Overview
FinMCP supports exporting data directly to files during tool execution. This feature allows you to:- Save large datasets without hitting response size limits
- Persist data for offline analysis in spreadsheets or analytics tools
- Archive historical data snapshots
- Process data with external tools
Save Parameter
Every FinMCP tool accepts an optionalsave parameter defined in src/index.ts:
save object has two fields:
Export format:
"csv" or "json"- csv: Comma-separated values (for DataFrames, Series, and tabular data)
- json: Pretty-printed JSON (for all data types)
Custom filename for the export. Defaults to
{toolName}-{timestamp}.{extension}Must be a relative path within the server’s working directory for security.Export Formats
CSV Export
CSV export is implemented in thetoCsv function (src/index.ts:135):
CSV Value Escaping
TheescapeCsvValue function handles special characters:
Supported Data Types for CSV
- DataFrames: Exported with index column + data columns
- Series: Exported with index column + value column
- Arrays of objects: Exported with all unique keys as columns
Non-tabular data (plain objects, nested structures) cannot be exported as CSV. Use JSON format instead.
JSON Export
JSON export uses thestringifyJson function:
- DataFrames and Series (with
__type__metadata) - Objects (info dictionaries, news items)
- Arrays (news lists, search results)
- Nested structures
Save Implementation
ThesaveResult function (src/index.ts:162) handles file writing:
Security
The function validates that the resolved path stays within the server’s working directory to prevent path traversal attacks:Usage Examples
Export Historical Data to CSV
aapl-2024-daily.csv):
Export Company Info to JSON
msft-info.json):
Default Filename Pattern
Iffilename is omitted, FinMCP generates a timestamped filename:
{toolName}-{timestamp}.{extension}
Example: yf_download-1709251200000.csv
Combining Export with Response Formats
You can save data while still receiving a formatted response:Save + Markdown Preview
Save + JSON Response
Error Handling
Invalid CSV Data Type
CSV export requires tabular data. Try response_format=json or choose a table-producing tool.
Path Traversal Attempt
save.filename must stay within the server working directory.
Best Practices
Use CSV for time series and tabular data
Use CSV for time series and tabular data
CSV files are widely compatible with Excel, Google Sheets, pandas, and data analysis tools. Ideal for:
- Historical price data
- Financial statements
- Screener results
- Earnings calendars
Use JSON for structured metadata
Use JSON for structured metadata
JSON preserves nested structures and data types. Best for:
- Company info dictionaries
- News and research results
- Options chains
- Search results with mixed content
Provide descriptive filenames
Provide descriptive filenames
Use meaningful names that include:
- Ticker symbol(s)
- Date range or period
- Data type
aapl-2024-q1-financials.jsonCombine export with preview_limit
Combine export with preview_limit
For large datasets:
- Set
saveto persist full data - Set
response_format="markdown"for readability - Set
preview_limitto a reasonable number (10-50)
File Location
Exported files are saved relative to the MCP server’s working directory, typically:- Claude Desktop (macOS):
~/Library/Application Support/Claude/ - Claude Desktop (Windows):
%APPDATA%\Claude\ - Custom installations: The directory where the MCP server was started
saved_pathfield (JSON responses)- “Saved to ” note (Markdown responses)