IB_MCP

MCP.Pizza Chef: rcontesti

Interactive Brokers is a trading platform with a capable but unfriendly interface. This exposes its market data to an assistant, so you can ask for a current price or pull historical figures without navigating the terminal. It reads data rather than placing trades. It runs as two small services connected to the trading software you already run, and is documented for Claude Desktop.

Data
Web/Research

Use This MCP server To

Check the current price of something Pull historical prices for a period Compare how two things moved Get a plain summary of recent movement Look up market data without the terminal

README

IB_MCP

Overview

This project provides an Interactive Brokers (IB) API interface using the Model Context Protocol (MCP). It allows you to access real-time and historical market data from IB through a FastAPI-based service, designed to be used with MCP clients like Claude Desktop.

Architecture

The project consists of two main components:

  • ib_client_service: A FastAPI application that connects to the IB API (TWS or IB Gateway) using the ib_async library. It exposes REST endpoints for retrieving market data. This service runs in a Docker container.
  • mcp_server: A FastMCP server that acts as an MCP interface to the ib_client_service. It exposes tools that can be called by MCP clients, which in turn call the REST endpoints of the ib_client_service. This service also runs in a Docker container.

Setup

  1. Create .env file: Create a file named .env in the project root directory (/Users/rubencontesti/Code/IB_MCP/) and populate it with your IB API connection details. You can create this file by copying the content of .env.example and replacing the placeholder values with your actual IB connection information. The following variables are required:

    IB_HOST=127.0.0.1
    IB_PORT=7497  # Or your TWS/Gateway API port
    IB_CLIENT_ID=1 # Must be unique
    
  2. Install Docker and Docker Compose: Make sure you have Docker and Docker Compose installed on your system.

  3. Build and Run: In your terminal, navigate to the project root directory (/Users/rubencontesti/Code/IB_MCP/) and run:

    docker-compose up --build

    This command will build the Docker images for both services and start the containers.

Testing

Once the services are running and connected to IB (check the logs for connection success), you can test the following endpoints:

Health Check

curl http://localhost:5001/health

Tick Data

# Stock Tick Data (Snapshot, Delayed) - Replace conId with a valid Bond conId
curl "http://localhost:5001/data/ticks/STK?conId=265598&exchange=SMART&currency=USD&marketDataType=3"

# Bond Tick Data (Snapshot, Delayed) - Replace conId with a valid Bond conId
curl "http://localhost:5001/data/ticks/BOND?conId=443719449&exchange=SMART&currency=USD&marketDataType=3"

Historical Data

# Stock Historical Data
curl "http://localhost:5001/data/historical/STK?conId=265598&exchange=SMART&currency=USD&durationStr=1%20M&barSizeSetting=1%20day&whatToShow=TRADES"

# Bond Historical Data - Replace conId with a valid Bond conId
curl "http://localhost:5001/data/historical/BOND?conId=443719449&exchange=SMART&currency=USD&durationStr=1%20M&barSizeSetting=1%20day&whatToShow=MIDPOINT"

Future Work

  • Implement MCP tools in the mcp_server to expose the ib_client_service endpoints.
  • Add endpoints for order placement and management.
  • Add endpoints for position retrieval.
  • Implement streaming tick data via Server-Sent Events (SSE).

Resources:

MCP

Interactive Brokers

IB_MCP FAQ

Can I use this to check prices without opening the trading terminal?
Yes — you ask and the current or historical figures come back in the chat.
Can it place trades?
No, it is built around reading market data rather than executing orders.
Do I need an account?
You need your own Interactive Brokers setup running, since it connects to that rather than a separate service.
Which apps does it work with?
It is documented for Claude Desktop.
Can I get historical data as well as live prices?
Yes — both real-time and historical figures are available.