Skip to content
Back to search

schwab-mcp

Schwab MCP server that enables AI assistants like Claude to retrieve and interact with your Schwab accounts and Schwab market data.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/sudowealth--schwab-mcp/badge.svg)](/listings/sudowealth--schwab-mcp)

HTML

<a href="/listings/sudowealth--schwab-mcp"><img src="/api/listings/sudowealth--schwab-mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Quick Setup

git clone <repository-url>
cd schwab-mcp
npm install

# Authenticate with Cloudflare (first time only)
npx wrangler login

# Create KV namespace for OAuth token storage
npx wrangler kv:namespace create "OAUTH_KV"
# Note the ID from the output - you'll need it for configuration

# Set up your personal configuration
cp wrangler.example.jsonc wrangler.jsonc
# Edit wrangler.jsonc to:
# 1. Replace YOUR_KV_NAMESPACE_ID_HERE with the ID from above
# 2. Change the name to something unique (e.g., "schwab-mcp-yourname")

# Set your secrets
npx wrangler secret put SCHWAB_CLIENT_ID      # Your Schwab App Key
npx wrangler secret put SCHWAB_CLIENT_SECRET  # Your Schwab App Secret
npx wrangler secret put SCHWAB_REDIRECT_URI   # https://your-worker-name.workers.dev/callback
npx wrangler secret put COOKIE_ENCRYPTION_KEY # Generate with: openssl rand -hex 32

# Deploy
npm run deploy

Configuration Notes

- `wrangler.example.jsonc` - Template configuration (committed) - `wrangler.jsonc` - Your personal config (git-ignored, created from template) - `.dev.vars` - Local development secrets (git-ignored, optional)

Since `wrangler.jsonc` is git-ignored, you can safely develop and test with your personal configuration without exposing secrets.

Detailed Configuration

1. Create a Schwab App

1. Log in to the [Schwab Developer Portal](https://developer.schwab.com) 2. Create a new app with: - **App Name**: Your MCP server name - **Callback URL**: `https://schwab-mcp.<your-subdomain>.workers.dev/callback` - **App Type**: Personal or third-party based on your use case 3. Note your **App Key** (Client ID) and generate an **App Secret**

2. Set Environment Variables

The same secrets from Quick Setup need to be set (see above).

GitHub Actions Deployment

For automated deployments, add these GitHub repository secrets:

1. **`CLOUDFLARE_API_TOKEN`**: Your Cloudflare API token 2. **`OAUTH_KV_ID`**: Your KV namespace ID

The workflow handles validation and deployment when pushing to `main`. Cloudflare secrets must still be set via `wrangler secret`.

Testing with Inspector

Test your deployment using the MCP Inspector:

npx @modelcontextprotocol/inspector@latest

Enter `https://schwab-mcp.<your-subdomain>.workers.dev/sse` and connect. You'll be prompted to authenticate with Schwab.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 356 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Schwab MCP Server
  2. A Model Context Protocol (MCP) server that enables AI assistants like Claude to
  3. securely interact with Charles Schwab accounts and market data through the
  4. official Schwab API.
  5. ## What You Can Do
  6. Ask Claude to:
  7. - "Show me my Schwab account balances and positions"
  8. - "Get real-time quotes for AAPL, GOOGL, and MSFT"
  9. - "What are today's market movers in the $SPX?"
  10. - "Show me the options chain for TSLA with Greeks"
  11. - "Get my transactions from the last 30 days"
  12. - "Search for ETFs related to technology"
  13. - "Check if the markets are open"
  14. ## Unofficial MCP Server
  15. This is an unofficial, community-developed TypeScript MCP server for Charles
  16. Schwab. It has not been approved, endorsed, or certified by Charles Schwab. It
  17. is provided as-is, and its functionality may be incomplete or unstable. Use at
  18. your own risk, especially when dealing with financial data or transactions.
  19. ## Overview
  20. This MCP server acts as a bridge between AI assistants and the Schwab API,
  21. providing:
  22. - **Secure OAuth Authentication**: Implements Schwab's OAuth 2.0 flow with PKCE
  23. for secure authentication
  24. - **Comprehensive Trading Tools**: Access to accounts, orders, quotes, and
  25. transactions
  26. - **Market Data Tools**: Real-time quotes, price history, market hours, movers,
  27. and options chains
  28. - **Account Privacy**: Built-in account identifier scrubbing to protect
  29. sensitive information
  30. - **Enterprise-Ready**: Deployed on Cloudflare Workers with Durable Objects for
  31. state management
  32. ## Features
  33. ### Trading Tools
  34. - **Account Management**
  35. - `getAccounts`: Retrieve all account information with positions and balances
  36. - `getAccountNumbers`: Get list of account identifiers
  37. - **Order Management**
  38. - `getOrder`: Get order by ID
  39. - `getOrders`: Fetch orders with filtering by status, time range, and symbol
  40. - `getOrdersByAccountNumber`: Get orders by account number
  41. - `cancelOrder`: Cancel an order (Experimental)
  42. - `placeOrder`: Place an order (Experimental)
  43. - `replaceOrder`: Replace an order (Experimental)
  44. - **Market Quotes**
  45. - `getQuotes`: Get real-time quotes for multiple symbols
  46. - `getQuoteBySymbolId`: Get detailed quote for a single symbol
  47. - **Transaction History**
  48. - `getTransactions`: Retrieve transaction history across all accounts with
  49. date filtering
  50. - **User Preferences**
  51. - `getUserPreference`: Retrieve user trading preferences and settings
  52. ### Market Data Tools
  53. - **Instrument Search**
  54. - `searchInstruments`: Search for securities by symbol with
  55. fundamental/reference data
  56. - **Price History**
  57. - `getPriceHistory`: Get historical price data with customizable periods and
  58. frequencies
  59. - **Market Hours**
  60. - `getMarketHours`: Check market operating hours by date
  61. - `getMarketHoursByMarketId`: Get specific market information
  62. - **Market Movers**
  63. - `getMovers`: Find top market movers by index ($SPX, $COMPX, $DJI)
  64. - **Options Chains**
  65. - `getOptionChain`: Retrieve full options chain data with Greeks
  66. - `getOptionExpirationChain`: Get option expiration dates
  67. ## Prerequisites
  68. 1. **Schwab Developer Account**: Register at
  69. [Schwab Developer Portal](https://developer.schwab.com)
  70. 2. **Cloudflare Account**: For deployment (Workers paid plan required for
  71. Durable Objects)
  72. 3. **Node.js**: Version 22.x or higher
  73. 4. **Wrangler CLI**: Installed via npm (included in dev dependencies)
  74. ## Getting Started
  75. ### Quick Setup
  76. ```bash
  77. git clone <repository-url>
  78. cd schwab-mcp
  79. npm install
  80. # Authenticate with Cloudflare (first time only)
  81. npx wrangler login
  82. # Create KV namespace for OAuth token storage
  83. npx wrangler kv:namespace create "OAUTH_KV"
  84. # Note the ID from the output - you'll need it for configuration
  85. # Set up your personal configuration
  86. cp wrangler.example.jsonc wrangler.jsonc
  87. # Edit wrangler.jsonc to:
  88. # 1. Replace YOUR_KV_NAMESPACE_ID_HERE with the ID from above
  89. # 2. Change the name to something unique (e.g., "schwab-mcp-yourname")
  90. # Set your secrets
  91. npx wrangler secret put SCHWAB_CLIENT_ID # Your Schwab App Key
  92. npx wrangler secret put SCHWAB_CLIENT_SECRET # Your Schwab App Secret
  93. npx wrangler secret put SCHWAB_REDIRECT_URI # https://your-worker-name.workers.dev/callback
  94. npx wrangler secret put COOKIE_ENCRYPTION_KEY # Generate with: openssl rand -hex 32
  95. # Deploy
  96. npm run deploy
  97. ```
  98. ### Configuration Notes
  99. - `wrangler.example.jsonc` - Template configuration (committed)
  100. - `wrangler.jsonc` - Your personal config (git-ignored, created from template)
  101. - `.dev.vars` - Local development secrets (git-ignored, optional)
  102. Since `wrangler.jsonc` is git-ignored, you can safely develop and test with your
  103. personal configuration without exposing secrets.
  104. ### Detailed Configuration
  105. #### 1. Create a Schwab App
  106. 1. Log in to the [Schwab Developer Portal](https://developer.schwab.com)
  107. 2. Create a new app with:
  108. - **App Name**: Your MCP server name
  109. - **Callback URL**:
  110. `https://schwab-mcp.<your-subdomain>.workers.dev/callback`
  111. - **App Type**: Personal or third-party based on your use case
  112. 3. Note your **App Key** (Client ID) and generate an **App Secret**
  113. #### 2. Set Environment Variables
  114. The same secrets from Quick Setup need to be set (see above).
  115. ### GitHub Actions Deployment
  116. For automated deployments, add these GitHub repository secrets:
  117. 1. **`CLOUDFLARE_API_TOKEN`**: Your Cloudflare API token
  118. 2. **`OAUTH_KV_ID`**: Your KV namespace ID
  119. The workflow handles validation and deployment when pushing to `main`.
  120. Cloudflare secrets must still be set via `wrangler secret`.
  121. ### Testing with Inspector
  122. Test your deployment using the MCP Inspector:
  123. ```bash
  124. npx @modelcontextprotocol/inspector@latest
  125. ```
  126. Enter `https://schwab-mcp.<your-subdomain>.workers.dev/sse` and connect. You'll
  127. be prompted to authenticate with Schwab.
  128. ## Usage
  129. ### Claude Desktop Configuration
  130. ### 1. Use Claude Integrations
  131. 1. Go to the [Claude Desktop](https://www.anthropic.com/docs/claude-desktop)
  132. settings
  133. 2. Click on the "Integrations" tab
  134. 3. Click on the "Add Custom Integration" button
  135. 4. Enter the integration name "Schwab"
  136. 5. Enter the MCP Server URL:
  137. `https://schwab-mcp.<your-subdomain>.workers.dev/sse`
  138. 6. Click on the "Add" button
  139. 7. Click "Connect" and the Schwab Authentication flow will start.
  140. ### 2. Add the MCP Server to your Claude Desktop configuration
  141. Add the following to your Claude Desktop configuration file:
  142. ```json
  143. {
  144. "mcpServers": {
  145. "schwab": {
  146. "command": "npx",
  147. "args": [
  148. "mcp-remote",
  149. "https://schwab-mcp.<your-subdomain>.workers.dev/sse"
  150. ]
  151. }
  152. }
  153. }
  154. ```
  155. Restart Claude Desktop. When you first use a Schwab tool, a browser window will
  156. open for authentication.
  157. ### Example Commands
  158. Once connected, you can ask Claude to:
  159. - "Show me my Schwab account balances"
  160. - "Get a quote for AAPL"
  161. - "What are today's market movers in the $SPX?"
  162. - "Show me the options chain for TSLA"
  163. - "Get my recent transactions from the last week"
  164. ### Local Development
  165. For local development, create a `.dev.vars` file (automatically ignored by git):
  166. ```env
  167. SCHWAB_CLIENT_ID=your_development_app_key
  168. SCHWAB_CLIENT_SECRET=your_development_app_secret
  169. SCHWAB_REDIRECT_URI=http://localhost:8788/callback
  170. COOKIE_ENCRYPTION_KEY=your_random_key_here
  171. LOG_LEVEL=DEBUG # Optional: Enable debug logging
  172. ```
  173. Run locally:
  174. ```bash
  175. npm run dev
  176. # Server will be available at http://localhost:8788
  177. ```
  178. Connect to `http://localhost:8788/sse` using the MCP Inspector for testing.
  179. ## Architecture
  180. ### Technology Stack
  181. - **Runtime**: Cloudflare Workers with Durable Objects
  182. - **Authentication**: OAuth 2.0 with PKCE via
  183. `@cloudflare/workers-oauth-provider`
  184. - **API Client**: `@sudowealth/schwab-api` for type-safe Schwab API access
  185. - **MCP Framework**: `@modelcontextprotocol/sdk` with `workers-mcp` adapter
  186. - **State Management**: KV storage for tokens, Durable Objects for session state
  187. ### Security Features
  188. 1. **OAuth 2.0 with PKCE**: Secure authentication flow preventing authorization
  189. code interception
  190. 2. **Enhanced Token Management**:
  191. - Centralized KV token store with automatic migration
  192. - Automatic token refresh (5 minutes before expiration)
  193. - 31-day token persistence with TTL
  194. 3. **Account Scrubbing**: Sensitive account identifiers are automatically
  195. replaced with display names
  196. 4. **State Security**: HMAC-SHA256 signatures for state parameter integrity
  197. 5. **Cookie Encryption**: Client approval state encrypted with AES-256
  198. 6. **Secret Redaction**: Automatic masking of sensitive data in logs
  199. ## Development
  200. ### Available Scripts
  201. ```bash
  202. npm run dev # Start development server on port 8788
  203. npm run deploy # Deploy to Cloudflare Workers
  204. npm run typecheck # Run TypeScript type checking
  205. npm run lint # Run ESLint with automatic fixes
  206. npm run format # Format code with Prettier
  207. npm run validate # Run typecheck and lint together
  208. ```
  209. ### Debugging
  210. The server includes comprehensive logging with configurable levels:
  211. - **Development**: Terminal output with colored logs
  212. - **Production**: Cloudflare dashboard → Workers → Logs
  213. - **Log Levels**: DEBUG, INFO, WARN, ERROR (set via LOG_LEVEL env var)
  214. Enable debug logging to see detailed OAuth flow and API interactions:
  215. ```bash
  216. # For local development
  217. echo "LOG_LEVEL=DEBUG" >> .dev.vars
  218. # For production
  219. npx wrangler secret put LOG_LEVEL --secret="DEBUG"
  220. ```
  221. ### Error Handling
  222. The server implements robust error handling with specific error types:
  223. - **Authentication Errors (401)**: Prompt for re-authentication
  224. - **Client Errors (400)**: Invalid parameters, missing data
  225. - **Server Errors (500)**: API failures, configuration issues
  226. - **Network Errors (503)**: Automatic retry with backoff
  227. - All errors include request IDs for Schwab API troubleshooting
  228. ## Contributing
  229. 1. Fork the repository
  230. 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
  231. 3. Commit your changes (`git commit -m 'Add amazing feature'`)
  232. 4. Push to the branch (`git push origin feature/amazing-feature`)
  233. 5. Open a Pull Request
  234. ## License
  235. MIT
  236. ## Troubleshooting
  237. ### Common Issues
  238. 1. **"KV namespace not found" error**
  239. - Ensure you created the KV namespace and updated `wrangler.jsonc`
  240. - Run `npx wrangler kv:namespace list` to verify
  241. 2. **Authentication failures**
  242. - Verify your redirect URI matches exactly in Schwab app settings
  243. - Check that all secrets are set correctly with `npx wrangler secret list`
  244. - Enable debug logging to see detailed OAuth flow
  245. 3. **"Durable Objects not available" error**
  246. - Ensure you have a paid Cloudflare Workers plan
  247. - Durable Objects are not available on the free tier
  248. 4. **Token refresh issues**
  249. - The server automatically refreshes tokens 5 minutes before expiration
  250. - Tokens are migrated from clientId to schwabUserId keys automatically
  251. - Check KV namespace for stored tokens:
  252. `npx wrangler kv:key list --namespace-id=<your-id>`
  253. ## Recent Updates
  254. - **Enhanced Token Management**: Centralized KV token store prevents token
  255. divergence
  256. - **Improved Security**: HMAC-SHA256 state validation and automatic secret
  257. redaction
  258. - **Better Error Handling**: Structured error types with Schwab API error
  259. mapping
  260. - **Configurable Logging**: Debug mode for troubleshooting OAuth and API issues
  261. ## Acknowledgments
  262. - Built with [Cloudflare Workers](https://workers.cloudflare.com/)
  263. - Uses [Model Context Protocol](https://modelcontextprotocol.io/)
  264. - Powered by
  265. [@sudowealth/schwab-api](https://www.npmjs.com/package/@sudowealth/schwab-api)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.