Interactive Brokers MCP Server
The Interactive Brokers MCP Server provides an unofficial Model Context Protocol interface that enables AI assistants to integrate with Interactive Brokers for automated account management and trading operations.
Key Capabilities:
Authentication: Secure OAuth authentication via web browser or headless mode with credentials
Account Management: Retrieve detailed account information and balances (
get_account_info)Position Tracking: View current positions and profit/loss details (
get_positions)Market Data: Access real-time market data for specific symbols with optional exchange specification (
get_market_data)Order Management: Place market, limit, and stop orders with full control over account ID, symbol, action (BUY/SELL), quantity, and pricing (
place_order)Order Monitoring: Check status and execution details of orders using order ID (
get_order_status)
Designed for local use only with a focus on security, the server supports both paper and live trading environments for interactive and automated operations.
Provides runtime environment for the MCP server to execute trading operations and communicate with Interactive Brokers Gateway
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Interactive Brokers MCP Server show me my current portfolio positions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Interactive Brokers MCP 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.
🔒 Security Notice

Related MCP server: Interactive Brokers MCP Server
Features
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 Document for 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
Security Notice
IMPORTANT WARNINGS:
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.
Prerequisites
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
You only need:
Interactive Brokers account (paper or live trading)
Node.js 18+ (for running the MCP server)
Quick Start
Add this MCP server to your Cursor/Claude configuration:
{
"mcpServers": {
"interactive-brokers": {
"command": "npx",
"args": ["-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.
Headless Mode Configuration
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.
Flex Query Configuration (Optional)
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"
}
}
}
}How to Get Your Flex Token:
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 IB Flex Web Service Guide.
Creating Flex Queries:
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 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.
Flex Query Features:
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_querytool
Configuration Variables
Feature | Environment Variable | Command Line Argument |
Username |
|
|
Password |
|
|
Headless Mode |
|
|
Paper Trading |
|
|
Auth Timeout |
|
|
Auth Wait Seconds |
|
|
Auth Poll Seconds |
|
|
Force standalone bundled gateway |
| N/A |
Flex Token |
| N/A |
Read-only mode |
|
|
2FA Strategy |
| N/A |
TOTP Secret Key |
| N/A |
Login page selector overrides |
| N/A |
TOTP form selector overrides |
| N/A |
See the TOTP 2FA Strategy Document for details on the 2FA and selector-override variables.
Gateway Lifecycle
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.jsonrecords the MCP-managed Gateway pid, port, version, and log paths.gateway-session.lockprevents two MCP processes from starting duplicate managed Gateways at the same time.gateway.stdout.logandgateway.stderr.logreceive 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.
Available MCP Tools
Trading & Account Management
Tool | Description |
| Retrieve account information and balances |
| Get current positions and P&L |
| Real-time market data for symbols |
| Place market, limit, or stop orders (only if read-only mode is disabled) |
| Check order execution status |
| Get all live/open orders for monitoring |
Flex Queries (Requires IB_FLEX_TOKEN)
Tool | Description |
| Execute a Flex Query and retrieve statements (auto-saves for reuse) |
| List all previously used Flex Queries |
| Remove a saved Flex Query from memory |
Troubleshooting
Authentication Problems:
Use the web interface that opens automatically
Complete any required two-factor authentication
Try paper trading mode if live trading fails
Gateway Discovery Problems:
If another IB Gateway is already listening on a local port but should not be reused, set
IB_FORCE_STANDALONE_GATEWAY=trueExisting 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, andib-gateway/.runtime/gateway-session.jsonTo clear a stale managed startup lock, confirm no MCP process is currently starting Gateway, then remove
ib-gateway/.runtime/gateway-session.lock
Support
This Server: Open an issue in this repository.
License
MIT License - see LICENSE file for details.
Thanks to our contributors
A big thank you to everyone who has contributed to making this project better.
Available Tools
14 toolsactivate_alertA
Activate a previously created alert. Usage: { "accountId": "<id>", "alertId": "<alertId>" }.
Inputs: alertId (required), accountId (required).
authenticateA
Authenticate with Interactive Brokers. Usage: { "confirm": true }.
Inputs: confirm (required).
confirm_orderB
Manually confirm an order that requires confirmation. Usage: { "replyId": "742a95a7-55f6-4d67-861b-2fd3e2b61e3c", "messageIds": ["o10151", "o10153"] }.
Inputs: replyId (required), messageIds (required).
create_alertC
Create a new trading alert. Usage: { "accountId": "<id>", "alertRequest": { "alertName": "Price Alert", "conditions": [{ "conidex": "265598", "type": "price", "operator": ">", "triggerMethod": "last", "value": "150" }] } }.
Inputs: accountId (required), alertRequest (required).
delete_alertC
Delete an alert. Usage: { "accountId": "<id>", "alertId": "<alertId>" }.
Inputs: alertId (required), accountId (required).
get_account_infoB
Get account information and balances. Usage: { "confirm": true }.
Inputs: confirm (required).
get_alertsC
Get all trading alerts for an account. Usage: { "accountId": "<id>" }.
Inputs: accountId (required).
get_live_ordersA
Get all live/open orders for monitoring and validation. Usage: {} for all accounts or { "accountId": "<id>" } for a specific account. This is the recommended way to validate that market orders were executed successfully after placing them.
Inputs: accountId.
get_market_dataA
Get real-time market data. Usage: { "symbol": "AAPL" } or { "symbol": "AAPL", "exchange": "NASDAQ" }.
Inputs: symbol (required), exchange.
get_option_chainA
Get option expirations and strikes for an underlying symbol. Usage: { "symbol": "AAPL" } or { "symbol": "AAPL", "exchange": "SMART" }.
Inputs: symbol (required), exchange.
get_order_statusA
Get the status of a specific order. Usage: { "orderId": "12345" }.
Inputs: orderId (required).
get_positionsC
Get current positions. Usage: {} or { "accountId": "<id>" }.
Inputs: accountId (required).
place_orderA
Place a trading order. Examples:
Market buy:
{ "accountId":"abc","symbol":"AAPL","action":"BUY","orderType":"MKT","quantity":1 }Limit sell:
{ "accountId":"abc","symbol":"AAPL","action":"SELL","orderType":"LMT","quantity":1,"price":185.5 }Stop sell:
{ "accountId":"abc","symbol":"AAPL","action":"SELL","orderType":"STP","quantity":1,"stopPrice":180 }Option buy:
{ "accountId":"abc","symbol":"AAPL","secType":"OPT","expiry":"JAN27","strike":200,"right":"C","action":"BUY","orderType":"LMT","quantity":1,"price":4.5 }Option by conid:
{ "accountId":"abc","conid":123456789,"secType":"OPT","action":"BUY","orderType":"MKT","quantity":1 }Suppress confirmations:
{ "accountId":"abc","symbol":"AAPL","action":"BUY","orderType":"MKT","quantity":1,"suppressConfirmations":true }
Inputs: action (required), quantity (required), accountId (required), orderType (required), +11 more.
resolve_option_conidA
Resolve a specific option contract conid. Usage: { "symbol": "AAPL", "expiry": "JAN27", "strike": 200, "right": "C" } or add { "exchange": "SMART" }.
Inputs: right (required), expiry (required), strike (required), symbol (required), +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Most tools have distinct purposes (alerts vs orders vs account data), but get_live_orders and get_order_status could be confused since both relate to order monitoring. get_alerts vs create/activate/delete_alert are clear, and get_option_chain vs resolve_option_conid are related but distinct enough.
The naming follows a consistent verb_noun pattern (get_, create_, activate_, delete_, place_, confirm_). Minor deviation: 'authenticate' lacks a noun object, and 'resolve_option_conid' is slightly more verbose than the others, but overall the pattern is predictable.
14 tools is well-scoped for a trading platform server covering authentication, account info, market data, orders, and alerts. Each tool addresses a distinct workflow need without excessive overlap or bloat.
The server covers core trading workflows: authentication, account/position queries, market data, order placement/status/confirmation, and alert lifecycle (create, activate, delete, list). Missing order cancellation/modification and position closing are notable gaps, but the primary use cases are covered.
Maintenance
Related MCP Connectors
Connect brokerage accounts to AI assistants: holdings, orders, asset lookup, and approved trading.
Unified financial infrastructure connecting AI agents directly to trade live/demo brokerage accounts, Web3 non-custodial wallets, real-time market data across equities, ETFs, crypto, forex, options, DeFi swaps, and prediction markets, institutional research feeds, and algorithmic strategy backtesters.
AI agents backtest, paper trade and live trade via your broker. Free to connect; OAuth.
Agentic brokerage access to a US brokerage account: quotes, orders, positions, cash and documents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides AI models with secure access to Interactive Brokers trading data and functionality, enabling account management, market data retrieval, and trading operations through natural language interactions.18MIT
- FlicenseNot gradedqualityDmaintenanceConnects AI assistants to Interactive Brokers for intelligent portfolio management, options analysis, risk monitoring, and automated trading strategy suggestions. Enables real-time account tracking, Greeks calculations, option chain analysis, and playbook-based risk adjustments through natural language.5-
- AlicenseAqualityDmaintenanceEnables AI agents to trade on Interactive Brokers: check quotes, balance, positions, and execute buy/sell orders (including fractional shares by dollar amount) via the Client Portal API.2014MIT
- AlicenseBqualityDmaintenanceGives AI assistants real-time access to Interactive Brokers accounts via the Client Portal Web API, with 26 read-only tools for portfolio, market data, options, and scanner.328 npm2MIT