Interactive Brokers

Developer tools

Interactive Brokers MCP Server.

Your AI app calls the Interactive Brokers MCP server, which does the developer tools work and sends the result back to the chat.

About Interactive Brokers

Interactive Brokers is a community MCP server from code-rabi, filed in our directory under developer tools. Interactive Brokers MCP Server.

At a glance

Publisher
code-rabi (community)
Runs
See the README for setup
Written in
JavaScript
License
MIT
GitHub stars
227

How to set up Interactive Brokers

  1. Follow the install steps in the Interactive Brokers README; it is written in JavaScript, so have that toolchain ready.
  2. Check the Interactive Brokers README for keys or settings; the registry lists none that Interactive Brokers requires.
  3. Add Interactive Brokers to Claude Code, Claude Desktop, VS Code or Cursor with the config in the setup box on this page.
  4. Restart the app or reload its MCP servers, then ask it to list the Interactive Brokers tools to confirm the connection.
  5. Run one read-only task with Interactive Brokers first, and keep your app asking before each tool call until the results look right.

Interactive Brokers compared with similar servers

  • Opik by comet-ml has fewer GitHub stars than Interactive Brokers (227 against 227); both are community servers, and Opik runs as a remote server and Interactive Brokers runs on your own machine.
  • Embedded Debugger by Adancurusul has fewer GitHub stars than Interactive Brokers (227 against 227); both are community servers, and both run locally.
  • Termius by dk23lhl has fewer GitHub stars than Interactive Brokers (227 against 227); both are community servers, and both run locally.

Before you connect Interactive Brokers

  • Give Interactive Brokers its own API key or account with the smallest permissions the job needs, never an admin key.
  • Keep your AI app asking before each Interactive Brokers tool call until you trust what it does with them.
  • Treat text that Interactive Brokers fetches as data. Pages, files and messages can hold instructions written to steer an AI.
  • Read the open issues for Interactive Brokers on GitHub to see what breaks and how fast the maintainers reply.

Marketing use cases for Interactive Brokers

How marketing and sales teams put Interactive Brokers to work, by company size. Pick the size closest to yours and start Interactive Brokers on one use case.

Small business

  • A small business with a developer can use Interactive Brokers to ship site and tracking fixes faster, with the AI reading the code it changes.
  • Technical founders can ask Interactive Brokers to explain and fix a marketing site issue without context switching between tools.
  • Interactive Brokers runs on your own computer, which keeps data local; it needs a little setup, so a small team should plan an hour for it.

Mid-market

  • Growth engineers can use Interactive Brokers to build landing pages, tracking and integrations in fewer cycles, with reviews kept in the normal flow.
  • Marketing ops engineers can connect Interactive Brokers to keep scripts and automations documented and versioned as they change.
  • Start Interactive Brokers on one workflow with one owner, measure the time it saves, then roll it out to the wider team.

Enterprise

  • Enterprise engineering teams can roll out Interactive Brokers with repo scopes and audit logs, so agents work only where they are allowed.
  • Platform teams can standardize on Interactive Brokers so web and marketing engineering share one reviewed way of working with AI.
  • Interactive Brokers is a community server, so have security review the code and pin a version before Interactive Brokers touches company data.

Need help becoming an AI-forward company?

We connect MCP servers and AI agents to your CRM, content and data, with the guardrails your team needs.

Contact us

Interactive Brokers README

From code-rabi/interactive-brokers-mcp on GitHub, shared under its MIT license. Images are left out; the original has them.

README.md

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

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:
  1. Log in to Interactive Brokers Account Management
  2. Go to Settings → Account Settings
  3. Navigate to Reporting → Flex Web Service
  4. 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:
  1. Go to Reports → Flex Queries in Account Management
  2. Create or customize your query template
  3. 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_query tool

Configuration Variables

Feature Environment Variable Command Line Argument
Username IB_USERNAME --ib-username
Password IB_PASSWORD_AUTH --ib-password-auth
Headless Mode IB_HEADLESS_MODE --ib-headless-mode
Paper Trading IB_PAPER_TRADING --ib-paper-trading
Auth Timeout IB_AUTH_TIMEOUT --ib-auth-timeout
Auth Wait Seconds IB_AUTH_WAIT_SECONDS --ib-auth-wait-seconds
Auth Poll Seconds IB_AUTH_POLL_SECONDS --ib-auth-poll-seconds
Force standalone bundled gateway IB_FORCE_STANDALONE_GATEWAY N/A
Flex Token IB_FLEX_TOKEN N/A
Read-only mode IB_READ_ONLY_MODE --ib-read-only-mode
2FA Strategy IB_TWO_FA_STRATEGY N/A
TOTP Secret Key IB_TOTP_SECRET N/A
Login page selector overrides IB_SELECTOR_USERNAME, IB_SELECTOR_PASSWORD, IB_SELECTOR_LOGIN_SUBMIT N/A
TOTP form selector overrides IB_SELECTOR_TOTP_INPUT, IB_SELECTOR_TOTP_SUBMIT 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.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.

Available MCP Tools

Trading & Account Management
Tool Description
get_account_info Retrieve account information and balances
get_positions Get current positions and P&L
get_market_data Real-time market data for symbols
place_order Place market, limit, or stop orders (only if read-only mode is disabled)
get_order_status Check order execution status
get_live_orders Get all live/open orders for monitoring
Flex Queries (Requires IB_FLEX_TOKEN)
Tool Description
get_flex_query Execute a Flex Query and retrieve statements (auto-saves for reuse)
list_flex_queries List all previously used Flex Queries
forget_flex_query 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=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

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.

Questions about Interactive Brokers

What is the Interactive Brokers MCP server?

Interactive Brokers MCP Server. Interactive Brokers is maintained by code-rabi on GitHub at code-rabi/interactive-brokers-mcp, and works with AI apps that support the Model Context Protocol, such as Claude, Cursor and VS Code.

How do I install the Interactive Brokers MCP server?

Interactive Brokers doesn't publish a one-line install in the MCP registry, so follow the setup steps in its README on GitHub (code-rabi/interactive-brokers-mcp). Like most servers, Interactive Brokers ends with a command or URL you paste into your AI app's MCP config.

Does Interactive Brokers need an API key?

The registry lists no required keys for Interactive Brokers. Check the Interactive Brokers README for optional settings, and expect a remote server to ask you to sign in the first time you connect.

Is Interactive Brokers an official MCP server?

No. Interactive Brokers is a community server maintained by code-rabi. Community servers can be excellent; read the code and the open issues before you give Interactive Brokers access to company data.

What license is Interactive Brokers under?

Interactive Brokers is released under the MIT license, according to its GitHub repository. The license covers the code of Interactive Brokers; the service it connects to has its own terms.