Schwab MCP Server
Enables AI assistants to securely interact with Charles Schwab accounts through OAuth authentication, providing access to account balances, real-time market quotes, options chains, transaction history, order management, and comprehensive market data.
README
Schwab MCP Server
A Model Context Protocol (MCP) server that enables AI assistants like Claude to securely interact with Charles Schwab accounts and market data through the official Schwab API.
What You Can Do
Ask Claude to:
- "Show me my Schwab account balances and positions"
- "Get real-time quotes for AAPL, GOOGL, and MSFT"
- "What are today's market movers in the $SPX?"
- "Show me the options chain for TSLA with Greeks"
- "Get my transactions from the last 30 days"
- "Search for ETFs related to technology"
- "Check if the markets are open"
Unofficial MCP Server
This is an unofficial, community-developed TypeScript MCP server for Charles Schwab. It has not been approved, endorsed, or certified by Charles Schwab. It is provided as-is, and its functionality may be incomplete or unstable. Use at your own risk, especially when dealing with financial data or transactions.
Overview
This MCP server acts as a bridge between AI assistants and the Schwab API, providing:
- Secure OAuth Authentication: Implements Schwab's OAuth 2.0 flow with PKCE for secure authentication
- Comprehensive Trading Tools: Access to accounts, orders, quotes, and transactions
- Market Data Tools: Real-time quotes, price history, market hours, movers, and options chains
- Account Privacy: Built-in account identifier scrubbing to protect sensitive information
- Local-Only: Runs entirely on your machine with local HTTPS server and file-based token storage
Features
Trading Tools
- Account Management
getAccounts: Retrieve all account information with positions and balancesgetAccountNumbers: Get list of account identifiers
- Order Management
getOrder: Get order by IDgetOrders: Fetch orders with filtering by status, time range, and symbolgetOrdersByAccountNumber: Get orders by account numbercancelOrder: Cancel an order (Experimental)placeOrder: Place an order (Experimental)replaceOrder: Replace an order (Experimental)
- Market Quotes
getQuotes: Get real-time quotes for multiple symbolsgetQuoteBySymbolId: Get detailed quote for a single symbol
- Transaction History
getTransactions: Retrieve transaction history across all accounts with date filtering
- User Preferences
getUserPreference: Retrieve user trading preferences and settings
Market Data Tools
- Instrument Search
searchInstruments: Search for securities by symbol with fundamental/reference data
- Price History
getPriceHistory: Get historical price data with customizable periods and frequencies
- Market Hours
getMarketHours: Check market operating hours by dategetMarketHoursByMarketId: Get specific market information
- Market Movers
getMovers: Find top market movers by index ($SPX, $COMPX, $DJI)
- Options Chains
getOptionChain: Retrieve full options chain data with GreeksgetOptionExpirationChain: Get option expiration dates
Prerequisites
- Schwab Developer Account: Register at Schwab Developer Portal
- Node.js: Version 20.x or higher (22.x recommended)
Getting Started
Quick Setup
git clone <repository-url>
cd schwab-mcp
npm install
# Configure your environment
cp .env.example .env
# Edit .env with your Schwab app credentials
# Start the MCP server (will prompt for OAuth on first run)
npm run start
Configuration
1. Create a Schwab App
- Log in to the Schwab Developer Portal
- Create a new app with:
- App Name: Your MCP server name (e.g., "My Schwab MCP")
- Callback URL:
https://localhost:3000/callback - App Type: Personal
- Note your App Key (Client ID) and generate an App Secret
2. Configure Environment Variables
Copy the .env.example file to .env and fill in your credentials:
cp .env.example .env
Edit .env:
# Schwab OAuth Configuration
SCHWAB_CLIENT_ID=your_schwab_app_key_here
SCHWAB_CLIENT_SECRET=your_schwab_app_secret_here
# OAuth Redirect URI (must match what you configured in Schwab Developer Portal)
SCHWAB_REDIRECT_URI=https://localhost:3000/callback
# Optional: Port for HTTPS server (default: 3000)
PORT=3000
# Optional: Log level (trace, debug, info, warn, error, fatal)
LOG_LEVEL=info
# Optional: Environment (development, staging, production)
ENVIRONMENT=production
3. First Run - OAuth Authentication
On the first run, the server will:
- Generate self-signed certificates in
.certs/directory (no OpenSSL required) - Start an HTTPS server on
https://localhost:3000 - Open your browser to the Schwab authorization page
- After you authorize, tokens will be saved to
.auth/directory - The MCP server will start and be ready to use
npm run start
Note: You may need to trust the self-signed certificate in your browser or system. The certificate is only used for localhost OAuth callback and is generated automatically using Node.js crypto libraries.
Usage
Claude Desktop Configuration
Add the server to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"schwab": {
"command": "npx",
"args": [
"tsx",
"/path/to/schwab-mcp/src/index.ts"
],
"env": {
"SCHWAB_CLIENT_ID": "your_app_key",
"SCHWAB_CLIENT_SECRET": "your_app_secret",
"SCHWAB_REDIRECT_URI": "https://localhost:3000/callback"
}
}
}
}
Or if you prefer to build first and run the compiled JavaScript:
{
"mcpServers": {
"schwab": {
"command": "node",
"args": [
"/path/to/schwab-mcp/dist/index.js"
],
"env": {
"SCHWAB_CLIENT_ID": "your_app_key",
"SCHWAB_CLIENT_SECRET": "your_app_secret",
"SCHWAB_REDIRECT_URI": "https://localhost:3000/callback"
}
}
}
}
Note: The first option using tsx is recommended as it doesn't require a build step.
Restart Claude Desktop. The server will connect via stdio transport.
Example Commands
Once connected, you can ask Claude to:
- "Show me my Schwab account balances"
- "Get a quote for AAPL"
- "What are today's market movers in the $SPX?"
- "Show me the options chain for TSLA"
- "Get my recent transactions from the last week"
Architecture
Technology Stack
- Runtime: Node.js with TypeScript
- Authentication: OAuth 2.0 with PKCE via
@sudowealth/schwab-api - API Client:
@sudowealth/schwab-apifor type-safe Schwab API access - MCP Framework:
@modelcontextprotocol/sdkwith stdio transport - State Management: File-based token storage in
.auth/directory - OAuth Server: Express with HTTPS for OAuth callback handling
Security Features
- OAuth 2.0 with PKCE: Secure authentication flow preventing authorization code interception
- Local Token Storage: Tokens stored locally in
.auth/directory (never sent to external servers) - HTTPS Localhost: Self-signed certificates for secure OAuth callback
- Automatic Token Refresh: Tokens refreshed 5 minutes before expiration
- Account Scrubbing: Sensitive account identifiers automatically replaced with display names
- Secret Redaction: Automatic masking of sensitive data in logs
Development
Available Scripts
npm run start # Start the MCP server
npm run dev # Start in development mode (same as start)
npm run build # Build TypeScript to JavaScript
npm run typecheck # Run TypeScript type checking
npm run lint # Run ESLint
npm run format # Format code with Prettier
npm run validate # Run typecheck and lint together
Project Structure
schwab-mcp/
├── .auth/ # OAuth tokens (git-ignored)
├── .certs/ # Self-signed certificates (git-ignored)
├── src/
│ ├── index.ts # Main MCP server entry point
│ ├── auth/ # OAuth authentication client
│ ├── server/ # OAuth HTTP server and certificate generation
│ ├── shared/ # Shared utilities (logging, token storage)
│ └── tools/ # MCP tool implementations
├── .env # Environment variables (git-ignored)
└── .env.example # Example environment variables
Debugging
The server includes comprehensive logging with configurable levels:
- Log Levels: trace, debug, info, warn, error, fatal
- Set via
LOG_LEVELenvironment variable in.env
Enable debug logging to see detailed OAuth flow and API interactions:
LOG_LEVEL=debug
Error Handling
The server implements robust error handling with specific error types:
- Authentication Errors (401): Prompt for re-authentication
- Client Errors (400): Invalid parameters, missing data
- Server Errors (500): API failures, configuration issues
- All errors include request IDs for Schwab API troubleshooting
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT
Troubleshooting
Common Issues
-
"Certificate error" in browser
- This is expected with self-signed certificates
- Accept the certificate warning during OAuth flow
- The certificate is only used for
https://localhost:3000/callback
-
"Cannot find module" errors
- Run
npm installto ensure all dependencies are installed - Make sure you're using Node.js 20.x or higher
- Run
-
Authentication failures
- Verify your redirect URI matches exactly:
https://localhost:3000/callback - Check that your Schwab app credentials are correct in
.env - Enable debug logging:
LOG_LEVEL=debugin.env
- Verify your redirect URI matches exactly:
-
"Port already in use" error
- Change the PORT in
.envto a different value - Make sure no other process is using port 3000
- Change the PORT in
Recent Updates
- Local-Only Architecture: Migrated from Cloudflare Workers to local Node.js server
- File-Based Token Storage: Tokens stored securely in local
.auth/directory - HTTPS OAuth Flow: Self-signed certificates for secure localhost OAuth callback
- Stdio Transport: Uses standard MCP SDK with stdio for Claude Desktop integration
Acknowledgments
- Uses Model Context Protocol
- Powered by @sudowealth/schwab-api
- Built with @modelcontextprotocol/sdk
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。