Unofficial local MCP server for Interactive Brokers market data, account positions, and trading workflows. Use paper trading and review permissions before connecting live accounts.
Details
Author
seriallazer
GitHub stars
63
Downloads
595
Categories
Finance, Community, Other, API
Jump to
- Fetches portfolio details from Interactive Brokers.
- Exposes REST API endpoints via FastAPI.
- Provides auto-generated API documentation.
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
Clone the repository, create a Python virtual environment, install dependencies from requirements.txt, set up a .env file with IBKR API credentials, then run with uvicorn app.main:app --reload. The API documentation is available at http://localhost:8000/docs.
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
**DISCLAIMER**: This is an**unofficial**, community-developed MCP server and is**NOT**affiliated with or endorsed by Interactive Brokers. This software is in**Alpha state**and may not work perfectly.
A Model Context Protocol (MCP) server that provides integration with Interactive Brokers' trading platform. This server allows AI assistants to interact with your IB account to retrieve market data, check positions, and place trades.
- **Interactive Brokers API Integration**: Full trading capabilities including account management, position tracking, real-time market data, and order management (market, limit, and stop orders)
- **Flex Query Support**: Execute Flex Queries to retrieve account statements, trade confirmations, and historical data. Queries are automatically remembered for easy reuse
- **Flexible Authentication**: Choose between browser-based OAuth authentication or headless mode with credentials for automated environments, including fully automated TOTP 2FA override. See[TOTP 2FA Strategy Documentfor detailed configuration and important risk warnings.
- **Simple Setup**: Run directly with`npx`- no Docker or additional installations required. Includes pre-configured IB Gateway and Java runtime for all platforms
- **Financial Risk**: Trading involves substantial risk of loss. Always test with paper trading first.
- **Security**: This software handles sensitive financial data. Only run locally, never on public servers.
- **No Warranty**: This unofficial software comes with no warranties. Use at your own risk.
- **Not Financial Advice**: This tool is for automation only, not financial advice.
**No additional installations required for mainstream platforms.**This package includes:
- Pre-configured IB Gateway for all platforms (Linux, macOS, Windows)
- Java Runtime Environment (JRE) for macOS, Windows, and standard Linux builds
- Automatic first-run musl JRE download for Alpine-based containers (e.g.`node:lts-alpine`, supergateway)
- All necessary dependencies
- Interactive Brokers account (paper or live trading)
- Node.js 18+ (for running the MCP server)
Add this MCP server to your Cursor/Claude configuration:
```
`{ "mcpServers": { "interactive-brokers": { "command": "npx", "args": ](https://github.com/code-rabi/interactive-brokers-mcp/blob/HEAD/docs/2FA-TOTP-STRATEGY.md)["-y", "interactive-brokers-mcp"] } } }`
```
When you first use the server, a web browser window will automatically open for the Interactive Brokers OAuth authentication flow. Log in with your IB credentials to authorize the connection.
For automated environments or when you prefer not to use a browser for authentication, you can enable headless mode by configuring it in your MCP server configuration:
```
`{ "mcpServers": { "interactive-brokers": { "command": "npx", "args": ["-y", "interactive-brokers-mcp"], "env": { "IB_HEADLESS_MODE": "true", "IB_USERNAME": "your_ib_username", "IB_PASSWORD_AUTH": "your_ib_password" } } } }`
```
In headless mode, the server will automatically authenticate using your credentials without opening a browser window. This is useful for:
- Automated trading systems
- Server environments without a display
- CI/CD pipelines
- Situations where browser interaction is not desired
**Important**: Even in headless mode, Interactive Brokers may still require two-factor authentication (2FA). When 2FA is triggered, the headless authentication will wait up to 60 seconds for you to complete the 2FA process through your configured method (mobile app, SMS, etc.) before returning an`AUTHENTICATION_PENDING`response. Wait for approval to complete, then check account info again.
To enable paper trading, add`"IB_PAPER_TRADING": "true"`to your environment variables:
```
`{ "mcpServers": { "interactive-brokers": { "command": "npx", "args": ["-y", "interactive-brokers-mcp"], "env": { "IB_HEADLESS_MODE": "true", "IB_USERNAME": "your_ib_username", "IB_PASSWORD_AUTH": "your_ib_password", "IB_PAPER_TRADING": "true" } } } }`
```
**Security Note**: Store credentials securely and never commit them to version control. Consider using environment variable files or secure credential management systems.
To use Flex Queries for retrieving account statements and historical data, you need to configure your Flex Web Service Token:
```
`{ "mcpServers": { "interactive-brokers": { "command": "npx", "args": ["-y", "interactive-brokers-mcp"], "env": { "IB_FLEX_TOKEN": "your_flex_token_here" } } } }`
```
- Log in to[Interactive Brokers Account Management
- Go to**Settings**→**Account Settings**
- Navigate to**Reporting**→**Flex Web Service**
- Generate or retrieve your Flex Web Service Token
For detailed instructions on enabling Flex Web Service, see the](https://www.interactivebrokers.com/portal)[IB Flex Web Service Guide.
- Go to**Reports**→**Flex Queries**in Account Management
- Create or customize your query template
- Click the info icon next to your query to find its Query ID
For a complete guide on creating and customizing Flex Queries, see the](https://www.ibkrguides.com/orgportal/performanceandstatements/flex-web-service.htm)[IB Flex Queries Guide.
**Note**: When you execute a Flex Query for the first time, the MCP server automatically saves it with its name from the API. Future executions can reference the query by either its ID or its saved name.
- **Automatic Memory**: When you execute a Flex Query, it's automatically saved for future use
- **Easy Reuse**: Previously used queries are remembered - no need to copy query IDs repeatedly
- **Friendly Names**: Optionally provide a friendly name when first executing a query
- **Forget Queries**: Remove queries you no longer need with the`forget_flex_query`tool
See the](https://www.ibkrguides.com/orgportal/performanceandstatements/flex.htm)[TOTP 2FA Strategy Documentfor details on the 2FA and selector-override variables.
On startup, the MCP first probes reachable local Gateway endpoints on the configured port and common Client Portal Gateway ports. If a healthy existing Gateway is found, the MCP attaches to it and does not start another bundled Gateway.
When no suitable existing Gateway is reachable, the MCP starts the bundled Java Gateway as a durable detached process. Runtime coordination files are stored under`ib-gateway/.runtime/`:
- `gateway-session.json`records the MCP-managed Gateway pid, port, version, and log paths.
- `gateway-session.lock`prevents two MCP processes from starting duplicate managed Gateways at the same time.
- `gateway.stdout.log`and`gateway.stderr.log`receive the Gateway process output.
Normal MCP shutdown detaches from the Gateway and leaves it running so later MCP runs can reuse it. If`IB_FORCE_STANDALONE_GATEWAY=true`is set, the MCP skips unrelated external Gateway discovery, but it still reuses or coordinates through the durable MCP-managed session metadata and lock files.
To reset the managed Gateway session, stop the Gateway process recorded in`ib-gateway/.runtime/gateway-session.json`, then remove`ib-gateway/.runtime/gateway-session.json`and any stale`ib-gateway/.runtime/gateway-session.lock`. The MCP automatically removes stale metadata when the recorded pid no longer exists.
- Use the web interface that opens automatically
- Complete any required two-factor authentication
- Try paper trading mode if live trading fails
- If another IB Gateway is already listening on a local port but should not be reused, set`IB_FORCE_STANDALONE_GATEWAY=true`
- Existing gateways are only reused when the MCP process can reach them over HTTPS; otherwise the bundled standalone gateway is started on an available port
- For MCP-managed Gateway startup issues, inspect`ib-gateway/.runtime/gateway.stdout.log`,`ib-gateway/.runtime/gateway.stderr.log`, and`ib-gateway/.runtime/gateway-session.json`
- To clear a stale managed startup lock, confirm no MCP process is currently starting Gateway, then remove`ib-gateway/.runtime/gateway-session.lock`
- **This Server**: Open an issue in this repository.
MIT License - see LICENSE file for details.
A big thank you to everyone who has contributed to making this project better.
Read and write access to Airtable databases.
A Model Context Protocol (MCP) server that enables AI assistants to integrate with Prometheus Alertmanager
A comprehensive MCP server for tooling interactions(40+) and resource accessibility(60+) plus many useful prompts to interact with Algorand Blockchain.
An MCP server that provides control over Android devices through ADB. Offers device screenshot capture, UI layout analysis, package management, and ADB command execution capabilities.
AniList MCP server for accessing AniList API data
AnkiConnect MCP server for interacting with Anki via AnkiConnect.
Chat with any other OpenAI SDK Compatible Chat Completions API, like Perplexity, Groq, xAI and more
APISIX Model Context Protocol (MCP) server is used to bridge large language models (LLMs) with the APISIX Admin API, supporting querying and managing all resources in Apache APISIX.](https://github.com/code-rabi/interactive-brokers-mcp/blob/HEAD/docs/2FA-TOTP-STRATEGY.md)
No reviews yet — be the first
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
Social sign-in isn’t configured yet. You can still create an account with email below, or ask an admin to add Google/GitHub/Discord OAuth credentials.
Sequential Thinking is an MCP server that provides a tool for dynamic and reflective problem-solving through a structured, step-by-step thinking process. It is…
Filesystem is a Node.js server that implements the Model Context Protocol (MCP) for filesystem operations. It enables AI assistants to read, write, and manage…
A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
A collection of reference implementations for the Model Context Protocol (MCP), demonstrating secure and controlled access to tools and data sources for Large…