loading…
Search for a command to run...
loading…
An MCP server providing stock market data and trading capabilities through multiple broker APIs including Robinhood and Schwab.
An MCP server providing stock market data and trading capabilities through multiple broker APIs including Robinhood and Schwab.
An MCP (Model Context Protocol) server providing access to stock market data and trading capabilities through multiple broker APIs.
🚀 Current Status: v0.6.5 - Multi-Broker Support (Robinhood + Schwab)
pip install open-stocks-mcp
For development:
git clone https://github.com/Open-Agent-Tools/open-stocks-mcp.git
cd open-stocks-mcp
uv sync # installs all deps including dev group
Create a .env file:
For Robinhood:
[email protected]
ROBINHOOD_PASSWORD=your_password
For Schwab (optional):
SCHWAB_API_KEY=your_api_key
SCHWAB_APP_SECRET=your_app_secret
SCHWAB_CALLBACK_URL=https://127.0.0.1:8182/
SCHWAB_TOKEN_PATH=~/.tokens/schwab_token.json
# Enable both brokers
ENABLED_BROKERS=robinhood,schwab
Note: Schwab requires a developer account and API approval (several days). See Schwab Setup Guide for full setup instructions.
HTTP Transport (Recommended)
open-stocks-mcp-server --transport http --port 3001
STDIO Transport
open-stocks-mcp-server --transport stdio
# Health check (HTTP transport)
curl http://localhost:3001/health
# Prometheus metrics (no auth required)
curl http://localhost:3001/metrics
# Interactive testing
uv run mcp dev src/open_stocks_mcp/server/app.py
The /metrics endpoint exposes:
open_stocks_mcp_tool_calls_total (counter by tool)open_stocks_mcp_tool_avg_calls_per_minute (gauge by tool; average over the rolling window)open_stocks_mcp_tool_latency_ms (gauge by tool and quantile: 0.50, 0.95, 0.99)Distributed tracing setup (OpenTelemetry, Jaeger, Tempo):
Each MCP tools/call invocation is bounded by a configurable deadline. Tools that exceed the
deadline return a structured JSON error instead of blocking the server indefinitely.
timeout.tool_execution_timeout_seconds (default: 30)OPEN_STOCKS_MCP_TOOL_EXECUTION_TIMEOUT_SECONDS (e.g., 60)When a tool times out its response body is:
{
"status": "error",
"error_type": "ToolExecutionTimeout",
"failure_class": "timeout",
"tool": "<tool_name>",
"timeout_seconds": 30,
"error": "Tool '...' exceeded the 30s execution limit"
}
The MCP result has isError: true; HTTP /mcp returns status 200 (not 500) so the
client can inspect the structured error. Broker-level request timeouts (Robinhood 16 s,
Schwab 30 s) remain in effect independently and count toward this deadline.
Broker call protection is enabled by default and reports state in MCP health_check,
MCP rate_limit_status, HTTP /health, and HTTP /status.
OPEN_STOCKS_MCP_CIRCUIT_BREAKER_ENABLED (default: true)OPEN_STOCKS_MCP_CIRCUIT_BREAKER_FAILURE_THRESHOLD (default: 5)OPEN_STOCKS_MCP_CIRCUIT_BREAKER_COOLDOWN_SECONDS (default: 60)State meanings:
closed: requests flow normally.open: broker calls fail fast until cooldown expires.half_open: one probe call is allowed; success resets to closed, failure returns to open.Production Docker Setup:
cd examples/open-stocks-mcp-docker
docker-compose up -d
Features:
Kubernetes / Orchestrated Deployment: See examples/kubernetes/README.md for Kustomize manifests covering HTTP transport, non-root security context, PVC-backed token/log persistence, and health probes.
Add to your MCP settings (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"open-stocks": {
"command": "open-stocks-mcp-server",
"args": ["--transport", "stdio"]
}
}
}
{
"mcpServers": {
"open-stocks": {
"command": "python",
"args": ["-m", "mcp_http_client", "http://localhost:3001/mcp"]
}
}
}
Reference docs and runnable examples:
Robinhood Tools:
Schwab Tools:
All Schwab tools use schwab_ prefix (e.g., schwab_get_portfolio, schwab_buy_stock_market).
Stock Orders (✅ Live Tested):
Options Orders (✅ Live Tested):
Order Management:
The server handles Robinhood's authentication requirements:
ROBINHOOD_MFA_CODE before login attempts to complete code-based verification (time-sensitive, typically 5-10 minutes).uv run pytest # All tests (works after uv sync)
uv run pytest -m "journey_account" # Fast account tests (~1.8s)
uv run pytest -m "journey_market_data" # Market data tests (~3.8s)
uv run pytest -m "not slow and not exception_test" # Recommended for development
uv run pytest -m rate_limited # Opt-in live API tests that may hit broker rate limits
RUN_RATE_LIMITED=1 uv run pytest # Include rate-limited tests in a full run
uv run pytest -m performance tests/performance -v # Mocked, CI-safe benchmarks
RUN_PERFORMANCE=1 uv run pytest # Include performance tests in a full run
# See CLAUDE.md for complete journey testing guide
ruff check . --fix # Lint and fix
ruff format . # Format code
mypy . # Type check
Open Stocks MCP can load configuration from open-stocks-mcp.yaml or config.yaml in the current working directory.
You can also set an explicit path with OPEN_STOCKS_CONFIG=/path/to/config.yaml or OPEN_STOCKS_CONFIG_FILE=/path/to/config.yaml (OPEN_STOCKS_MCP_CONFIG remains supported for backward compatibility).
Environment variables always win over YAML values, including:
MCP_SERVER_NAME, LOG_LEVELRATE_LIMIT_CALLS_PER_MINUTE, RATE_LIMIT_CALLS_PER_HOUR, RATE_LIMIT_BURST_SIZECACHE_TTL_MARKET_SECONDS, CACHE_TTL_ACCOUNT_SECONDS, CACHE_MAX_SIZEENABLE_CACHEOPEN_STOCKS_MCP_BATCH_SIZE, OPEN_STOCKS_MCP_QUEUE_MAX_WAITFeature flags support safe defaults plus per-environment overrides:
environment: production
feature_flags:
brokers.robinhood:
default: true
brokers.schwab:
default: false
environments:
production: true
Unknown feature flags resolve to disabled (false).
See config.yaml.example for the supported schema.
# Set environment variables
export GOOGLE_API_KEY="your-google-api-key"
export ROBINHOOD_USERNAME="[email protected]"
export ROBINHOOD_PASSWORD="password"
# Start Docker server
cd examples/open-stocks-mcp-docker && docker-compose up -d
# Run evaluation
MCP_HTTP_URL="http://localhost:3001/mcp" adk eval examples/google_adk_agent tests/evals/0_list_available_tools_test.json --config_file_path tests/evals/test_config.json
Completed in v0.7.0-dev:
Completed in v0.6.4:
open_option_positions_with_details() enriches positions with call/put typebuy_option_limit, sell_option_limit, and spread strategies now workingfind_options function working correctlyNext Priority (Schwab Testing):
Out of Scope:
Apache License 2.0 - see LICENSE file for details.
Important Security Notes:
.env filesFor security concerns, please see our security policy.
Disclaimer: This software is for educational and development purposes. Trading stocks and options involves substantial risk. Always verify trades and understand the risks before executing any financial transactions.
Run in your terminal:
claude mcp add open-stocks-mcp -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.