Important
đź§Ş This project is experimental and could be subject to breaking changes.
Note
This is a maintained fork of the official Polygon.io MCP Server with extended features and documentation. For the official Polygon.io version, visit the upstream repository.
A Model Context Protocol (MCP) server that provides access to Polygon.io financial market data API through an LLM-friendly interface.
This server exposes all Polygon.io API endpoints as MCP tools, providing access to comprehensive financial market data including:
- Stock, options, forex, and crypto aggregates and bars
- Real-time and historical trades and quotes
- Market snapshots
- Ticker details and reference data
- Dividends and splits data
- Financial fundamentals
- Market status and holidays
The MCP server is organized into a modular architecture for scalability and maintainability:
src/mcp_polygon/
├── server.py # Main MCP server - orchestrates tool registration
├── api_wrapper.py # Centralized API error handling and response formatting
├── formatters.py # CSV output formatting utilities
├── validation.py # Shared validation functions (date validation, future date prevention)
└── tools/ # Tool implementations
├── rest/ # 81 REST API tools
│ ├── stocks.py # Stock market tools (47 tools)
│ ├── futures.py # Futures market tools (11 tools)
│ ├── crypto.py # Cryptocurrency tools (7 tools)
│ ├── forex.py # Forex market tools (6 tools)
│ ├── options.py # Options market tools (9 tools)
│ ├── indices.py # Market indices tools (5 tools)
│ └── economy.py # Economic indicators (3 tools)
└── websockets/ # 36 WebSocket streaming tools
├── connection_manager.py # Connection lifecycle and management
├── stream_formatter.py # JSON message formatting
├── stocks.py # Stock streaming (6 tools)
├── crypto.py # Crypto streaming (6 tools)
├── options.py # Options streaming (6 tools)
├── futures.py # Futures streaming (6 tools)
├── forex.py # Forex streaming (6 tools)
└── indices.py # Indices streaming (6 tools)
| Asset Class | REST Tools | WebSocket Tools | Total | Coverage | Status |
|---|---|---|---|---|---|
| Stocks | 42 | 6 | 48 | 100% | âś… Complete |
| Futures | 11 | 6 | 17 | 100% | âś… Complete |
| Crypto | 5 | 6 | 11 | 100% | âś… Complete |
| Forex | 6 | 6 | 12 | 100% | âś… Complete |
| Options | 8 | 6 | 14 | 100% | âś… Complete |
| Indices | 5 | 6 | 11 | 100% | âś… Complete |
| Economy | 3 | 0 | 3 | 100% | âś… Complete |
| Total | 80 | 36 | 116 | 99% | âś… Production Ready |
- âś… Phase 1 Complete (53 tools): Core market data, aggregates, trades, quotes, snapshots
- âś… Phase 2 Complete (27 tools): Enhanced options, technical indicators, indices, corporate actions
- âś… Phase 3 Complete (1 tool): Inflation expectations tool added, comprehensive endpoint coverage analysis revealing 99% API coverage through generic tool architecture (81 tools serving 92 of 93 REST endpoints)
- âś… Phase 4 Complete (Infrastructure): WebSocket connection manager, stream formatter, 71 tests (96% coverage)
- âś… Phase 5 Complete (36 tools): WebSocket streaming tools for 6 markets (stocks, crypto, options, futures, forex, indices) with automatic message buffering
The WebSocket implementation provides real-time market data streaming with built-in buffering:
- Message Buffering: Automatic buffering of last 100 messages per connection (~50KB memory per market)
- Stream Management: Start, stop, subscribe, unsubscribe, and monitor stream status for each market
- Message Statistics: Total received, current buffer fill, and sample message display for verification
- Auto-Reconnection: Exponential backoff reconnection (1s → 2s → 4s → 8s → max 30s)
- FIFO Buffer: Automatic message eviction when full, cleared on disconnect
- JSON Format: Real-time data preserves timestamps and nested structures (vs CSV for REST)
For detailed documentation, see CLAUDE.md - WebSocket Message Flow & Buffering section.
Comprehensive documentation is available:
- CLAUDE.md - Project instructions for Claude Code (development guide)
- SECURITY.md - Security policy and responsible disclosure
- CHANGELOG.md - Version history and release notes
- Implementation Roadmap - REST API implementation phases (99% coverage, 81 tools)
- WebSocket Implementation - Real-time streaming architecture (36 tools)
- Endpoint Patterns - Tool-to-endpoint mapping (1:1.14 coverage efficiency)
- Testing Guide - Test suite documentation (336 tests, 91% coverage)
- analysis/ - Phase 1-3 documentation archives
- Modular: Tools organized by asset class for easy navigation
- Scalable: Architecture supports 100+ tools without complexity
- Type-Safe: Comprehensive type hints throughout
- Read-Only: All tools marked with
readOnlyHint=Truefor safety - CSV Output: Token-efficient CSV format for LLM consumption
- Python 3.10+
- A Polygon.io API key
- Astral UV
- For existing installs, check that you have a version that supports the
uvxcommand.
- For existing installs, check that you have a version that supports the
First, install Claude Code
npm install -g @anthropic-ai/claude-codeUse the following command to add the Polygon MCP server to your local environment.
This assumes uvx is in your $PATH; if not, then you need to provide the full
path to uvx.
# Claude CLI - STDIO transport
claude mcp add polygon -e POLYGON_API_KEY=your_api_key_here -- uvx --from git+https://github.com/ChrisSc/mcp_polygon@v1.0.0 mcp_polygonTo connect Claude Code to a local Docker HTTP server:
-
Start the Docker server (see Docker HTTP Transport):
docker-compose up -d
-
Add the server to Claude Code:
# Claude CLI - HTTP transport claude mcp add polygon-docker http://localhost:8000/mcp --transport http -s user
The -s user flag installs it globally across all projects. Use -s project for project-only scope.
To start Claude Code, run claude in your terminal.
- If this is your first time using, follow the setup prompts to authenticate
You can also run claude mcp add-from-claude-desktop if the MCP server is installed already for Claude Desktop.
- Follow the Claude Desktop MCP installation instructions to complete the initial installation and find your configuration file.
- Use the following example as reference to add Polygon's MCP server.
Make sure you complete the various fields.
- Path find your path to
uvx, runwhich uvxin your terminal. - Replace
<your_api_key_here>with your actual Polygon.io API key. - Replace
<your_home_directory>with your home directory path, e.g.,/home/username(Mac/Linux) orC:\Users\username(Windows).
- Path find your path to
claude_desktop_config.json
{
"mcpServers": {
"polygon": {
"command": "<path_to_your_uvx_install>/uvx",
"args": [
"--from",
"git+https://github.com/ChrisSc/mcp_polygon@v1.0.0",
"mcp_polygon"
],
"env": {
"POLYGON_API_KEY": "<your_api_key_here>",
"HOME": "<your_home_directory>"
}
}
}
}To connect Claude Desktop to a local Docker HTTP server instead of using the stdio transport:
-
Start the Docker server (as shown in Docker HTTP Transport):
docker-compose up -d
-
Update your
claude_desktop_config.jsonwith the HTTP transport configuration:A ready-to-use configuration file is provided in
claude_desktop_config_http.json.
claude_desktop_config.json (HTTP Transport)
{
"mcpServers": {
"polygon-docker": {
"url": "http://localhost:8000/mcp",
"transport": "streamable-http"
}
}
}Configuration File Locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Important Notes:
- The
urlfield points to your local Docker server endpoint - The
transportfield must be set to"streamable-http" - No
command,args, orenvfields are needed for HTTP transport - The Docker server must be running before starting Claude Desktop
- API key is configured in Docker via
.envfile (not in Claude Desktop config)
Advantages of HTTP Transport:
- âś… Server runs independently of Claude Desktop
- âś… Can connect multiple MCP clients to the same server
- âś… Easier debugging with Docker logs
- âś… Better isolation and resource management
Disadvantages:
- ❌ Requires Docker to be running
- ❌ Extra step to start/stop the server
- ❌ Network overhead (minimal for localhost)
For stdio transport (default), see the Claude Desktop section above.
By default, STDIO transport is used.
To configure SSE or Streamable HTTP, set the MCP_TRANSPORT environment variable.
Example:
MCP_TRANSPORT=streamable-http \
POLYGON_API_KEY=<your_api_key_here> \
uv run entrypoint.pyTo run the server in Docker with HTTP transport (tested and verified âś…):
# Start the server
docker-compose up --build
# The server will be available at:
# http://localhost:8000/mcpEndpoint Details:
- URL:
http://localhost:8000/mcp - Transport:
streamable-http(Server-Sent Events) - Protocol: MCP v2024-11-05
- Tools: 81 tools across 7 asset classes
Testing the Endpoint:
The streamable-http transport requires specific headers:
# Test with proper headers
curl -X POST http://localhost:8000/mcp \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}'Configuration:
The default docker-compose.yml configuration:
- âś… Runs with
streamable-httptransport - âś… Binds to
0.0.0.0:8000inside container, exposed aslocalhost:8000on host (secure) - âś… Includes DNS rebinding protection (MCP spec compliant)
- âś… Container hardened with read-only filesystem and dropped capabilities
- âś… Cache directory support for uv package manager
Environment variables control the transport configuration:
MCP_TRANSPORT=streamable-http- Transport type (stdio, sse, or streamable-http)FASTMCP_HOST=0.0.0.0- Bind address inside container (required for Docker accessibility)FASTMCP_PORT=8000- Port number
See .env.example for all configuration options.
Connecting MCP Clients:
- Claude Code: See Claude Code - Option 2: HTTP Transport for the CLI command
- Claude Desktop: See Claude Desktop HTTP Configuration for JSON configuration
-
Localhost Binding (Default Configuration):
ports: - "127.0.0.1:8000:8000" # ✅ Safe - localhost only # NOT "0.0.0.0:8000:8000" # ❌ Dangerous - exposes to network
-
DNS Rebinding Protection (Enabled by Default): The server automatically enables Origin header validation per MCP specification. Configuration in
server.py:transport_security = TransportSecuritySettings( enable_dns_rebinding_protection=True, allowed_hosts=["localhost:8000", "127.0.0.1:8000"], allowed_origins=["http://localhost:8000"], )
-
API Key Protection:
- Never commit API keys to version control
- Use
.envfiles (included in.gitignore) - Consider Docker secrets for sensitive deployments
- Monitor API usage at polygon.io dashboard
-
Container Hardening (Enabled by Default):
- Read-only filesystem
- No new privileges
- Dropped Linux capabilities
- See
docker-compose.ymlfor full configuration
- Current Docker Setup: 8/10 (Production-ready for local development)
- Localhost binding: Prevents network exposure
- DNS rebinding protection: MCP spec compliant
- Container hardening: Defense-in-depth security
For detailed security information, see SECURITY.md.
Once integrated, you can prompt Claude to access Polygon.io data with efficient defaults:
Get the last year of daily prices for AAPL stock
Show me yesterday's trading volume for MSFT
What were the biggest stock market gainers today?
Get me the latest crypto market data for BTC-USD
The server uses optimized default limits to minimize API calls:
# Get 1 year of daily bars in a single API call (252 trading days)
get_aggs("AAPL", 1, "day", "2024-01-01", "2024-12-31", limit=252)
# Get 1 trading day of minute bars in a single call (390 minutes)
get_aggs("AAPL", 1, "minute", "2024-10-15", "2024-10-15", limit=390)
# Get full options chain for liquid underlying (500+ contracts)
list_options_contracts("AAPL", contract_type="call", expiration_date="2025-01-17", limit=500)Default limits are set based on typical use cases:
- Aggregates/tick data: 100 records
- Large catalogs: 250 records
- Technical indicators: 50 periods
- Economic data: 10 records
Adjust the limit parameter for specific workflows. See CLAUDE.md for detailed guidance.
This MCP server implements 81 production-ready tools across 7 asset classes:
- Aggregates:
get_aggs,list_aggs,get_grouped_daily_aggs,get_daily_open_close_agg,get_previous_close_agg - Trades & Quotes:
list_trades,get_last_trade,list_quotes,get_last_quote - Snapshots:
list_universal_snapshots,get_snapshot_all,get_snapshot_ticker,get_snapshot_direction - Reference Data:
list_tickers,get_ticker_details,list_ticker_news,get_ticker_types,get_ticker_changes,get_related_companies - Corporate Actions:
list_splits,list_dividends,list_conditions,get_exchanges,list_ticker_events - Financials:
list_stock_financials,list_ipos,list_short_interest,list_short_volume - Market Operations:
get_market_status,get_market_holidays - Analyst Data:
list_benzinga_analyst_insights,list_benzinga_analysts,list_benzinga_consensus_ratings,list_benzinga_earnings,list_benzinga_firms,list_benzinga_guidance,list_benzinga_news,list_benzinga_ratings - Technical Indicators:
get_sma,get_ema,get_macd,get_rsi
- Contracts:
list_options_contracts,get_options_contract,get_options_chain - Snapshots:
get_snapshot_option,list_snapshot_options_chain - Technical Indicators:
get_options_sma,get_options_ema,get_options_macd,get_options_rsi
- Aggregates:
list_futures_aggregates - Contracts:
list_futures_contracts,get_futures_contract_details - Products:
list_futures_products,get_futures_product_details - Market Data:
list_futures_quotes,list_futures_trades,get_futures_snapshot - Reference:
list_futures_schedules,list_futures_market_statuses,get_futures_snapshot_all
- Market Data:
get_last_crypto_trade - Snapshots: Use
get_snapshot_ticker('crypto', ticker)for crypto snapshots - Aggregates: Use
get_aggs(ticker='X:BTCUSD', ...)for crypto aggregates (generic tool) - Technical Indicators:
get_crypto_sma,get_crypto_ema,get_crypto_macd,get_crypto_rsi
- Quotes:
get_last_forex_quote,get_real_time_currency_conversion - Technical Indicators:
get_forex_sma,get_forex_ema,get_forex_macd,get_forex_rsi
- Snapshots:
get_indices_snapshot - Technical Indicators:
get_index_sma,get_index_ema,get_index_macd,get_index_rsi
- Indicators:
list_treasury_yields,list_inflation,list_inflation_expectations
For a complete list of available tools and their parameters, run the MCP Inspector or see the Endpoint Patterns documentation.
Each tool follows the Polygon.io SDK parameter structure while converting responses to CSV format for token-efficient LLM processing.
Check to ensure you have the Prerequisites installed.
# Sync dependencies
uv sync
# Run the server
POLYGON_API_KEY=your_api_key_here uv run mcp_polygonLocal Dev Config for claude_desktop_config.json
"mcpServers": {
"polygon": {
"command": "/your/path/.cargo/bin/uv",
"args": [
"run",
"--with",
"/your/path/mcp_polygon",
"mcp_polygon"
],
"env": {
"POLYGON_API_KEY": "your_api_key_here",
"HOME": "/Users/danny"
}
}
}For debugging and testing, we recommend using the MCP Inspector:
npx @modelcontextprotocol/inspector uv --directory /path/to/mcp_polygon run mcp_polygonThis will launch a browser interface where you can interact with your MCP server directly and see input/output for each tool.
This project uses just for common development tasks. To lint your code before submitting a PR:
just lintThis will run ruff format and ruff check --fix to automatically format your code and fix linting issues.
This MCP server interacts with Polygon.io's API to fetch market data. All data requests are subject to Polygon.io's privacy policy and terms of service.
- Polygon.io Privacy Policy: https://polygon.io/legal/privacy
- Data Handling: This server is a stateless proxy - no user data or API keys are stored, logged, or cached. All requests are forwarded directly to Polygon.io's API.
- API Key Storage: Your POLYGON_API_KEY is stored only in your local environment variables. It is never transmitted except to Polygon.io for authentication.
- Fork Relationship: This repository (ChrisSc/mcp_polygon) is a fork of polygon-io/mcp_polygon. For Polygon.io's data policies, see their privacy policy above.
This is a maintained fork of the official Polygon.io MCP Server.
Fork Maintainer: Chris Scragg (@ChrisSc) Fork Repository: https://github.com/ChrisSc/mcp_polygon Original Author: Polygon.io
This fork provides:
- Extended development and maintenance beyond the original scope
- Additional documentation and implementation guides (CLAUDE.md, docs/IMPLEMENTATION.md, docs/ENDPOINT_PATTERNS.md, docs/TESTING.md)
- Production-ready deployment (Phase 3 complete: 99% API coverage, 81 tools)
- Comprehensive development guides for contributors
For the upstream Polygon.io version, see: https://github.com/polygon-io/mcp_polygon
- For fork-specific issues: Open an issue at ChrisSc/mcp_polygon
- For Polygon.io API questions: Contact support@polygon.io or visit Polygon.io Documentation
This MCP server was originally created by Polygon.io and is maintained as a fork by Chris Scragg (@ChrisSc).
Original Repository: https://github.com/polygon-io/mcp_polygon Original Authors: Polygon.io team Fork Maintainer: Chris Scragg (@ChrisSc) Contact: clscragg@protonmail.com
This project is licensed under the MIT License - see the LICENSE file for details.
Original Copyright: Copyright (c) 2025 Polygon.io Derivative Work: This fork maintains the same MIT License
This is a fork of the original Polygon.io MCP Server. Contributions are welcome!
- Fork-specific improvements: Open an issue or PR at ChrisSc/mcp_polygon
- Upstream contributions: Consider submitting to polygon-io/mcp_polygon if the change benefits the original project
- Open an issue before starting work on major features
- Include tests for new functionality
- Follow the existing code style (run
just lint) - Update documentation to reflect your changes
For detailed contribution guidelines, see CONTRIBUTING.md.
Response Time: Best effort, typically within 1-2 weeks for issues/PRs.