E*TRADE MCP Server

E*TRADE MCP Server

Enables LLMs to retrieve real-time stock and options market data through the E\*TRADE API using natural language. It features secure OAuth 1.0 authentication, persistent token management, and comprehensive support for stock quotes, options chains, and Greeks.

Category
访问服务器

README

E*TRADE MCP Server

Model Context Protocol (MCP) server for E*TRADE API, enabling LLMs like Claude to retrieve stock and options market data.

Features

  • OAuth 1.0 Authentication - Secure, persistent token storage with automatic lifecycle management
  • Stock Quotes - Real-time and delayed stock quotes with optional earnings dates
  • Batch Quotes - Retrieve up to 25 stock quotes in a single request
  • Options Chains - Full options chain data with strikes, expirations, Greeks, and bid/ask
  • Options Quotes - Detailed quotes for specific option contracts
  • Automatic Retries - Built-in retry logic for handling API rate limits and token activation
  • MCP Integration - Seamless integration with Claude Desktop and other MCP clients

Prerequisites

Installation

1. Install uv (if not already installed)

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

2. Clone and Setup Project

cd etrade-mcp

# Create virtual environment
uv venv

# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

# Install dependencies
uv pip install -e .

3. Configure Environment

Create a .env file in the project root:

# Copy example file
cp .env.example .env

# Edit .env with your credentials

.env file:

ETRADE_CONSUMER_KEY=your_consumer_key_here
ETRADE_CONSUMER_SECRET=your_consumer_secret_here
ETRADE_ENVIRONMENT=sandbox  # Use 'production' for live trading

Important:

  • Start with sandbox environment for testing
  • Switch to production only after thorough testing
  • Production requires live E*TRADE brokerage account

OAuth Setup

OAuth authentication is handled automatically through the MCP server. When you first use the server with Claude, you'll be prompted to authorize:

  1. Claude will call the setup_oauth tool (no verification code needed initially)
  2. Your browser will open to the E*TRADE authorization page
  3. After authorizing, E*TRADE will display a 5-character verification code
  4. Provide the code to Claude, who will call setup_oauth again with the code
  5. Tokens are saved encrypted locally and automatically renewed

Alternatively, you can run the standalone OAuth setup:

python -m server.auth.setup

Running Tests

# Install dev dependencies
uv pip install -e ".[dev]"

# Run all tests
pytest

# Run with coverage
pytest --cov=server tests/

# Run specific test file
pytest tests/test_token_store.py -v

Claude Desktop Configuration

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "etrade": {
      "command": "python",
      "args": [
        "-m",
        "server.main"
      ],
      "cwd": "/absolute/path/to/etrade-mcp",
      "env": {
        "ETRADE_CONSUMER_KEY": "your_consumer_key",
        "ETRADE_CONSUMER_SECRET": "your_consumer_secret",
        "ETRADE_ENVIRONMENT": "sandbox"
      }
    }
  }
}

Replace /absolute/path/to/etrade-mcp with your actual project path and add your credentials.

Usage with Claude

Once configured, Claude can access E*TRADE data through natural language:

Stock Quotes:

  • "What's the current price of Apple stock?"
  • "Get quotes for AAPL, MSFT, and GOOGL with earnings dates"
  • "Show me the price and volume for TSLA"

Options Data:

  • "Show me the option chain for Tesla expiring in January 2025"
  • "What are the Greeks for AAPL calls at $180 strike?"
  • "Get the bid/ask spread for SPY weekly options near $450"
  • "Show me put options for NVDA expiring next month"

Available Tools

Authentication

setup_oauth - OAuth 1.0 authentication flow

  • Step 1: Call without verification_code to get authorization URL
  • Step 2: Call with verification_code (5 characters from E*TRADE) to complete auth
  • Tokens are automatically stored and managed

Stock Quotes

get_stock_quote - Get quote for a single stock

  • Input: symbol (e.g., "AAPL"), optional include_earnings (default: false)
  • Returns: Price, volume, bid/ask, change, and optionally next earnings date

get_batch_quotes - Get quotes for multiple stocks

  • Input: symbols (array, up to 25), optional include_earnings (default: false)
  • Returns: Quotes for all requested symbols

Options Data

get_option_chains - Get options chain data

  • Input: symbol, optional filters:
    • expiry_year, expiry_month, expiry_day - Filter by expiration date
    • chain_type - "CALL", "PUT", or "CALLPUT" (default)
    • strike_price_near - Get strikes near a specific price
    • no_of_strikes - Limit number of strikes returned
    • include_weekly - Include weekly options (default: false)
    • skip_adjusted - Skip adjusted options (default: true)
    • option_category - "STANDARD" (default), "ALL", or "MINI"
    • price_type - "ATNM" (at-the-money, default) or "ALL"
  • Returns: Available strikes, expirations, bid/ask, Greeks, open interest, volume

get_option_quote - Get specific option quotes

  • Input: option_symbols (array of OSI format symbols, up to 25)
  • Returns: Detailed option quote data including Greeks and theoretical values

Project Structure

etrade-mcp/
├── server/
│   ├── auth/
│   │   ├── oauth_manager.py    # OAuth session & token lifecycle
│   │   ├── token_store.py      # Encrypted token storage
│   │   └── setup.py            # Standalone OAuth setup
│   ├── tools/
│   │   ├── oauth_tools.py      # MCP OAuth tool
│   │   ├── stock_quotes.py     # Stock quote tools
│   │   └── options_quotes.py   # Options chain & quote tools
│   ├── utils/
│   │   └── retry.py            # Automatic retry logic
│   ├── config.py               # Configuration management
│   └── main.py                 # MCP server entry point
├── tests/
│   ├── test_token_store.py     # Token storage tests
│   └── test_auth.py            # OAuth manager tests
├── .env.example                # Example environment config
├── pyproject.toml              # Project metadata & dependencies
└── README.md

Development Status

✅ v0.1.0 - All Core Features Complete

Foundation

  • [x] Project setup with modern tooling (uv, pyproject.toml)
  • [x] Environment-based configuration management
  • [x] Encrypted token storage with lifecycle management
  • [x] OAuth 1.0 authentication flow
  • [x] Unit tests for auth components

Stock Market Data

  • [x] Single stock quote tool with earnings support
  • [x] Batch quotes (up to 25 symbols)
  • [x] Real-time and delayed quote handling

Options Data

  • [x] Options chains with comprehensive filtering
  • [x] Options quotes by OSI symbol
  • [x] Greeks, theoretical values, and open interest
  • [x] Support for standard, weekly, and mini options

MCP Integration

  • [x] Two-step OAuth flow via MCP tools
  • [x] Automatic retry logic for API rate limits
  • [x] Token activation delay handling
  • [x] Full integration with Claude Desktop

Quality & Reliability

  • [x] Comprehensive error handling
  • [x] Debug logging to file and stderr
  • [x] Automatic token renewal
  • [x] Production-ready for E*TRADE live accounts

Security Notes

  • Never commit .env file - Contains sensitive credentials
  • Tokens are encrypted - Stored in .etrade_tokens.enc
  • Use sandbox first - Test thoroughly before production
  • Environment variable for key - Set ETRADE_TOKEN_KEY in production

Troubleshooting

OAuth Setup Fails

  • Verify consumer key and secret are correct
  • Check you're using the right environment (sandbox/production)
  • Ensure your E*TRADE account has API access

"No tokens found" Error

  • Run python -m server.auth.setup to authenticate
  • Check .etrade_tokens.enc file exists
  • Verify ETRADE_TOKEN_KEY is consistent

Import Errors

  • Ensure virtual environment is activated
  • Run uv pip install -e . to install dependencies

Recent Improvements

Token Lifecycle Management (Latest)

  • Automatic token renewal on expiration
  • Graceful handling of token activation delays
  • Persistent session state across restarts

Enhanced Options Support

  • Full E*TRADE API spec compliance
  • Support for weekly and mini options
  • Flexible filtering by expiration and strike price
  • Complete Greeks and theoretical pricing data

Reliability Enhancements

  • Automatic retry logic for API rate limits
  • Exponential backoff for token activation
  • Comprehensive error handling and logging
  • Production-tested with live E*TRADE accounts

Resources

License

MIT

Contributing

Contributions welcome! Please:

  1. Follow test-driven development
  2. Add tests for new features
  3. Update documentation
  4. Test with sandbox environment first

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选