schwab-mcp
schwab-mcp
一个连接到 Charles Schwab 经纪 API 的 MCP 服务器,外加一个 Claude Code 插件,其技能可以在调用 MCP 工具时节省 LLM 的往返次数。
功能说明
MCP 服务器 — 通过 schwabdev 封装 Schwab API,并通过 Streamable HTTP 公开 18 个工具:
类别 | 工具 |
会话 |
|
市场数据 |
|
账户 |
|
订单 |
|
证券 |
|
Claude Code 插件 — 提供六种技能(schwab:account, schwab:orders, schwab:quotes, schwab:market, schwab:instruments, schwab:chart-orders),预先为 Claude 提供工具选择规则、参数格式和安全模式。这消除了 LLM 在决定调用哪个工具以及如何调用时所需的反复确认过程。
Related MCP server: KiteMCP
前置要求
Python 3.11+
一个拥有已批准应用的 Schwab Developer 账户(你需要应用密钥和密钥)
设置
# Clone and install
git clone <repo-url> && cd schwab-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Add credentials
cp .env.example ~/.schwab-mcp/.env
# Edit ~/.schwab-mcp/.env with your Schwab app key and secret
# Authenticate (opens browser for OAuth)
schwab-mcp auth
# Start the server
schwab-mcp serve服务器默认监听 http://127.0.0.1:8099/mcp。可通过环境变量 SCHWAB_MCP_HOST 和 SCHWAB_MCP_PORT 进行覆盖。
与 Claude Code 配合使用
安装插件目录,以便 Claude Code 获取 MCP 连接和技能:
claude plugin add ./plugin这将注册:
MCP 服务器连接(通过
plugin/.mcp.json)指导 Claude 如何使用每个工具类别的六种技能
一个在会话结束时清理临时文件的钩子
安装完成后,可以询问 Claude 如下问题:
“我的账户持仓有哪些?”
“获取 AAPL 的报价”
“下达限价单,以 400 美元买入 10 股 MSFT”
“显示今天 S&P 500 的涨幅榜”
“绘制我今天 SPX 的成交订单图表”
示例:下达限价单
You: Buy 100 shares of SPY with limit order at current median bid-ask spread.
This order should be canceled if it weren't filled before 3/30 12PM ET.
Claude: I need to get SPY's current bid-ask spread first, then build the order.
Let me fetch the quote.
[calls get_quotes for SPY]
Got the quote. Here's the current SPY pricing:
- Bid: $632.70
- Ask: $633.00
- Midpoint: $632.85
Regarding cancellation by 3/30 12PM ET — Schwab doesn't support
"cancel at a specific time." I'll use DAY duration (valid through
market close on 3/30). You'd need to manually cancel at noon if
unfilled.
[calls place_order with confirmed=False — dry run]
| Field | Value |
|------------|----------------------------|
| Action | BUY |
| Symbol | SPY |
| Quantity | 100 shares |
| Order Type | LIMIT |
| Price | $632.85 (bid-ask midpoint) |
| Duration | DAY |
| Session | NORMAL |
Shall I submit this order?
You: yes
Claude: [calls place_order with confirmed=True]
Order submitted successfully.该技能引导 Claude 执行以下操作:
获取报价以计算中间价
首先进行试运行 (
confirmed=False) 并显示摘要仅在获得用户明确批准后才提交 (
confirmed=True)
示例:绘制成交订单图表
You: Plot my last week's credit spread trades
Claude: [fetches filled orders for Mar 22-28]
39 credit spread orders on SPXW last week — 30 vertical spreads
and 9 iron condors across 5 trading days.
[fetches 15-minute SPX candles for the same range]
[runs chart_orders.py with candles + orders data]
Candles: 130, Orders: 62 (12 buy, 11 sell, 39 spread)
Interactive chart saved to plugin/skills/chart-orders/chart.html
该技能引导 Claude 执行以下操作:
获取指定日期范围内的成交订单并识别标的资产 (SPXW/SPX)
获取 15 分钟 K 线(适用于多日范围)
运行图表脚本,生成带有订单标记、日期分隔符和悬停提示的交互式 Plotly 图表
安全性
变更操作(place_order, cancel_order, replace_order)使用两步确认模式。第一次调用是试运行,显示将要发生的操作;你必须明确确认才能执行。
项目结构
src/schwab_mcp/
server.py # CLI entry point (serve / auth commands)
client.py # Schwab client init, OAuth tokens, state persistence
_mcp.py # FastMCP server instance
logging_config.py # Rotating log handler with credential redaction
tools/ # MCP tool implementations
session.py # Account listing and selection
market_data.py # Quotes, options, price history, movers
accounts.py # Account details, transactions, preferences
orders.py # Order CRUD with dry-run safety
instruments.py # Symbol/CUSIP lookup
plugin/
.mcp.json # MCP server connection config
.claude-plugin/plugin.json # Plugin metadata
hooks/hooks.json # Session cleanup hook
skills/ # Claude Code skill definitions状态和日志
所有运行时状态都存储在 ~/.schwab-mcp/ 中:
文件 | 用途 |
| API 凭据 |
| OAuth 令牌(由 schwabdev 自动刷新) |
| 活动账户选择 |
| 轮转日志(5 MB,3 个备份,凭据已脱敏) |
大型工具响应(期权链、长交易列表)会被写入 /tmp/schwab-mcp/,并在 Claude Code 会话结束时自动清理。
开发
# Run tests
pytest
# Run with debug logging
LOG_LEVEL=DEBUG schwab-mcp serveTool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Trading MCP server for AI agents, with live market data, account reads and controlled execution.
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Multi-tenant FastMCP server for Charles Schwab brokerage data, monetized via DPYC Tollbooth
Connect Claude, ChatGPT, Codex, Claude Code or another MCP client to your real multi-broker investment portfolio. Fortunest tracks stocks, ETFs and crypto across brokers and exchanges; its MCP server lets your agent read holdings, returns, allocation, risk, trades and tax lots, calculated by Fortunest rather than guessed by the model. Reads run on their own; every change waits for your approval in the Fortunest app, and no tool places an order or moves money. Sign-in is OAuth 2.1 and needs Fortunest Pro (14-day trial, no card). A free demo that needs no account is listed as Fortunest demo.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables AI assistants like Claude to securely interact with Charles Schwab accounts and market data through the official Schwab API.87MIT
- FlicenseNot gradedqualityDmaintenanceA command-based MCP server that enables programmatic stock trading on Zerodha through natural language interfaces like Claude, allowing users to buy and sell stocks via API calls.-
- FlicenseNot gradedqualityDmaintenanceMCP server exposing Tradier brokerage tools to Claude, enabling account balance checks, position management, order operations, and market data queries.-
- AlicenseAqualityFmaintenanceMCP server for Interactive Brokers API integration, enabling account management, trading, market data, and short selling analysis through Claude.835MIT