schwab-mcp
schwab-mcp
Charles Schwab証券APIに接続するMCPサーバーと、MCPツール呼び出し時のLLMのやり取りを削減するスキルを備えたClaude Codeプラグインです。
機能概要
MCPサーバー — schwabdev を介して Schwab API をラップし、Streamable HTTP経由で18個のツールを公開します:
カテゴリ | ツール |
セッション |
|
市場データ |
|
口座 |
|
注文 |
|
銘柄 |
|
Claude Codeプラグイン — 6つのスキル(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にガイドする6つのスキル
一時ファイルをクリーンアップするセッション終了フック
インストール後、Claudeに以下のように質問できます:
"What are my account positions?"(現在の保有銘柄を教えて)
"Get me a quote for AAPL"(AAPLの株価を教えて)
"Place a limit order to buy 10 shares of MSFT at $400"(MSFTを400ドルで10株買う指値注文を出して)
"Show me today's top movers on the S&P 500"(今日のS&P 500の騰落率上位銘柄を見せて)
"Chart my filled orders for SPX today"(今日の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分足のローソク足を取得する(複数日の範囲に適したもの)
チャートスクリプトを実行し、注文マーカー、日次区切り、ホバーツールチップを備えたインタラクティブなPlotlyチャートを生成する
安全性
状態を変更する操作(place_order, cancel_order, replace_order)には、2段階の確認パターンを使用します。最初の呼び出しはドライランであり、何が起こるかを表示します。実行するには明示的に確認する必要があります。
プロジェクト構造
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により自動更新) |
| アクティブな口座選択 |
| ローテーションログ(5MB、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…
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
Build and backtest investing strategies from your AI assistant. Remote MCP with OAuth sign-in.
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