Skip to main content
Glama
Interactive Brokers (IBKR) MCP Server

Interactive Brokers (IBKR) MCP Server

Interactive Brokers (IBKR) MCP Server

A lightweight, zero-framework-dependency Model Context Protocol (MCP) server in Python that connects AI agents to Interactive Brokers. Implements MCP JSON-RPC 2.0 over stdio natively.

Auto-Detection Across IBKR Apps

Automatically probes and connects to whichever local IBKR interface is running:

  1. TWS (Paper Trading) — Port 7497

  2. IB Gateway (Paper Trading) — Port 4002

  3. TWS (Live Trading) — Port 7496

  4. IB Gateway (Live Trading) — Port 4001

  5. Client Portal Web API Gateway — Port 5000 (https://127.0.0.1:5000/v1/api)

Tip: If you use IBKR Desktop as your main screen, run IB Gateway or Client Portal Web API Gateway alongside it so the local API is available.

Related MCP server: IBKR TWS MCP Server

Setup

  1. Install dependencies:

    pip install -r requirements.txt
  2. In TWS or IB Gateway, open File → Global Configuration → API → Settings:

    • Check Enable ActiveX and Socket Clients

    • Uncheck Read-Only API (only if you want to stage or place orders)

    • Verify the Socket port (7497 TWS Paper / 7496 TWS Live / 4002 Gateway Paper / 4001 Gateway Live)

    • Ensure 127.0.0.1 is allowed under Trusted IPs / "Allow connections from localhost only"

  3. Add the server to your MCP client config:

    {
      "mcpServers": {
        "ibkr": {
          "command": "python3",
          "args": ["/path/to/ibkr-mcp/server.py"]
        }
      }
    }

Available MCP Tools

Tool

Description

ibkr_status

Scans local ports (7497, 4002, 7496, 4001, 5000) and reports which IBKR app is running

ibkr_account_summary

Net Liquidation, Cash, Buying Power, Available Funds, Margin, and Realized/Unrealized P&L

ibkr_positions

Current portfolio holdings, average cost, market price, market value, and P&L

ibkr_market_quote

Live or delayed bid/ask/last/high/low/volume quote for stocks, ETFs, forex, options, or futures

ibkr_historical_bars

Historical OHLCV candlestick bars (1 D, 1 M, 1 Y at 1 min, 5 mins, 1 hour, 1 day, etc.)

ibkr_search_contract

Search contracts by ticker or company name (conId, exchange, available derivative types)

ibkr_option_chain

Fetch option expirations and strikes for an underlying ticker

ibkr_open_orders

List all currently open or working orders

ibkr_place_order

Stage (transmit=False by default) or transmit (transmit=True) LMT, MKT, or STP orders

ibkr_cancel_order

Cancel an open order by orderId

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      Enables AI assistants to interact with Interactive Brokers trading accounts to retrieve market data, check positions, and place trades. Includes pre-configured IB Gateway and handles OAuth authentication automatically.
      14
      317 npm
      227
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables LLM clients to interact with Interactive Brokers Trader Workstation for automated trading workflows. Supports market data retrieval, portfolio management, and order execution through the TWS API.
      5
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with Interactive Brokers via the TWS API or IB Gateway to manage accounts, retrieve market data, and execute trades. It supports features like real-time market data, historical data queries, and order management for stocks and options.
      4
      -
    • A
      license
      B
      quality
      C
      maintenance
      Provides tools for interacting with Interactive Brokers Gateway to access market data, account summaries, and portfolio positions. It enables users to perform contract lookups, retrieve historical OHLCV bars, and view real-time quotes through natural language interfaces.
      6
      49 PyPI
      3
      PolyForm Noncommercial 1.0.0