Schwab MCP Server
A read-only MCP server that provides access to Charles Schwab account data and market information, including portfolio positions, real-time quotes, options chains, price history, and account balances through AI assistants.
README
Schwab MCP Server
A read-only Model Context Protocol (MCP) server for Charles Schwab API. Access your Schwab account data and market information through AI assistants like Claude, ChatGPT, and more.
Features
- Portfolio Analysis - View positions with cost basis, quantity, and market value
- Real-time Quotes - Get current prices for stocks and ETFs
- Options Data - Access options chains with Greeks
- Price History - Historical OHLCV data for technical analysis
- Account Info - View account balances and details
Security Note: This server is strictly READ-ONLY. No trading or account modification functionality is implemented.
Prerequisites
- Python 3.10 or higher
- A Charles Schwab Developer account with:
- App Key (Client ID)
- App Secret (Client Secret)
- A valid Refresh Token
- Callback URL configured
Installation
- Clone the repository:
git clone https://github.com/yourusername/schwab-mcp-server.git
cd schwab-mcp-server
- Create and activate a virtual environment:
python -m venv venv
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
- Install the package:
pip install -e .
Configuration
Environment Variables
Create a .env file in the project root:
SCHWAB_CALLBACK_URL=https://127.0.0.1:8182/callback
SCHWAB_TOKEN_PATH=~/.schwab-mcp/token.json
LOG_LEVEL=INFO
# Optional overrides if you don't keep them in the token file:
# SCHWAB_CLIENT_ID=your_app_key_here
# SCHWAB_CLIENT_SECRET=your_app_secret_here
Initial Token Setup
Create the token file at the path specified in SCHWAB_TOKEN_PATH (default: ~/.schwab-mcp/token.json):
{
"client_id": "your_app_key_here",
"client_secret": "your_app_secret_here",
"access_token": "",
"refresh_token": "YOUR_REFRESH_TOKEN_HERE",
"expires_at": 0,
"token_type": "Bearer"
}
Setting expires_at to 0 forces an automatic token refresh on first use.
The MCP server will load client_id and client_secret directly from this token file. Environment variables with the same names can override these values if needed.
Client Setup
Claude Desktop
Windows (Automated)
Run the PowerShell script to automatically configure Claude Desktop:
.\scripts\update_claude_schwab.ps1
The script will:
- Stop Claude Desktop (prompts for confirmation)
- Clear MCP-related cache files
- Update the config with correct paths to the venv Python and src directory
- Restart Claude Desktop
Options:
-RepoPath- Path to this repo (default: auto-detected)-SkipRestart- Update config without restarting Claude-ServerName- MCP server name in config (default:schwab)
Manual Configuration
macOS: Edit ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: Edit %APPDATA%\Claude\claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"schwab": {
"command": "python",
"args": ["-m", "schwab_mcp.server"],
"cwd": "/path/to/schwab-mcp-server",
"env": {
"SCHWAB_CALLBACK_URL": "https://127.0.0.1:8182/callback",
"SCHWAB_TOKEN_PATH": "/path/to/.schwab-mcp/token.json",
"PYTHONPATH": "/path/to/schwab-mcp-server/src",
"LOG_LEVEL": "INFO"
}
}
}
}
Restart Claude Desktop after saving the configuration.
ChatGPT Desktop
ChatGPT Desktop supports MCP servers through its settings. To configure:
- Open ChatGPT Desktop
- Go to Settings > Features > MCP Servers
- Click Add Server and enter:
- Name:
schwab - Command:
python - Arguments:
-m schwab_mcp.server - Working Directory:
/path/to/schwab-mcp-server
- Name:
- Add environment variables (client id/secret are read from the token file):
SCHWAB_CALLBACK_URL: https://127.0.0.1:8182/callbackSCHWAB_TOKEN_PATH: /path/to/.schwab-mcp/token.json
- Save and restart ChatGPT Desktop
File-based setup (auto-detected by ChatGPT Desktop):
- macOS: create
~/Library/Application Support/ChatGPT/.well-known/mcp.json - Windows: create
%APPDATA%\ChatGPT\.well-known\mcp.json
Copy chatgpt_desktop_config.example.json to that location and update the paths to match your environment (Python executable, repo path, and token path). Restart ChatGPT Desktop after saving.
Claude Code (CLI)
Add the MCP server to your Claude Code configuration. Create or edit ~/.claude/claude_code_config.json:
{
"mcpServers": {
"schwab": {
"command": "python",
"args": ["-m", "schwab_mcp.server"],
"cwd": "/path/to/schwab-mcp-server",
"env": {
"SCHWAB_CALLBACK_URL": "https://127.0.0.1:8182/callback",
"SCHWAB_TOKEN_PATH": "/path/to/.schwab-mcp/token.json"
}
}
}
}
Alternatively, you can add it to your project's .claude/settings.json for project-specific configuration:
{
"mcpServers": {
"schwab": {
"command": "python",
"args": ["-m", "schwab_mcp.server"],
"cwd": "/path/to/schwab-mcp-server",
"env": {
"SCHWAB_CALLBACK_URL": "https://127.0.0.1:8182/callback",
"SCHWAB_TOKEN_PATH": "/path/to/.schwab-mcp/token.json"
}
}
}
}
OpenAI Codex
For Codex CLI, configure the MCP server in your environment:
- Set up environment variables in your shell profile (
.bashrc,.zshrc, etc.):
export SCHWAB_CALLBACK_URL="https://127.0.0.1:8182/callback"
export SCHWAB_TOKEN_PATH="$HOME/.schwab-mcp/token.json"
# Optional overrides if you don't keep them in the token file:
# export SCHWAB_CLIENT_ID="your_client_id"
# export SCHWAB_CLIENT_SECRET="your_client_secret"
- Configure Codex to use the MCP server by adding to your Codex configuration:
{
"mcpServers": {
"schwab": {
"command": "python",
"args": ["-m", "schwab_mcp.server"],
"cwd": "/path/to/schwab-mcp-server"
}
}
}
Available Tools
| Tool | Description |
|---|---|
get_account |
Get account information including type and balances |
get_positions |
Get all positions with cost basis and market value |
get_quote |
Get real-time quote for a single symbol |
get_quotes |
Get real-time quotes for multiple symbols |
get_option_chain |
Get options chain with Greeks for a symbol |
get_price_history |
Get historical OHLCV price data |
Usage Examples
Once configured, you can ask your AI assistant questions like:
- "What are my current positions and their cost basis?"
- "Get me a quote for AAPL"
- "Show me the options chain for MSFT expiring in January"
- "What's the price history for NVDA over the last 6 months?"
- "What are my account balances?"
Testing
Using MCP Inspector
Test the server locally using the MCP Inspector:
npx @modelcontextprotocol/inspector python -m schwab_mcp.server
Manual Test
Verify authentication is working:
python -c "from schwab_mcp.auth import TokenManager; from schwab_mcp.config import settings; tm = TokenManager(settings.schwab_client_id, settings.schwab_client_secret, settings.schwab_token_path); tm.load_token(); print('Token loaded successfully')"
Troubleshooting
Token Refresh Fails
- Ensure your refresh token is valid and not expired (7-day expiration)
- Verify your client ID and secret are correct
- Check that your Schwab Developer app is approved and active
Server Won't Start
- Verify Python 3.10+ is installed:
python --version - Ensure all dependencies are installed:
pip install -e . - Check that the
.envfile exists and has correct values
No Data Returned
- Confirm your Schwab account has the appropriate permissions
- Check if markets are open (some data limited outside trading hours)
- Review logs for API error messages
Security
- Read-only access only - No trading or account modification capabilities
- Token storage - Tokens are stored locally with restricted file permissions (600)
- No credential logging - Sensitive data is never written to logs
- Environment variables - Credentials should be passed via environment, not hardcoded
References
License
MIT - Use at your own risk. Not affiliated with Charles Schwab.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。