Sponsored by Deepsite.site

EZIB-MCP: Interactive Brokers Trading for AI Agents

Created By
kelvingao7 months ago
MCP server built on ezib_async that exposes Interactive Brokers' trading and market data functionality.
Content

EZIB-MCP: Interactive Brokers Trading for AI Agents

A Model Context Protocol (MCP) server implementation that enables AI agents to interact with Interactive Brokers' trading platform, providing access to market data, account information, and trading functionality.

Overview

This project provides an MCP server built on ezib_async that allows AI agents to connect to Interactive Brokers, retrieve account information, manage portfolios, and execute trades. It serves as both a practical tool for algorithmic trading and a reference implementation for building MCP servers.

The implementation follows the best practices laid out for building MCP servers, allowing seamless integration with any MCP-compatible client.

Features

The server provides several powerful tools for trading and market data:

  1. Account Information: Access account balances, positions, and portfolio data
  2. Market Data: Retrieve real-time and historical market data
  3. Order Management: Place, modify, and cancel orders
  4. Position Management: Monitor and manage trading positions

Prerequisites

  • Python 3.11+
  • Interactive Brokers TWS or IB Gateway running
  • Docker if running the MCP server as a container (recommended)

Installation

Using pip

  1. Clone this repository:

    git clone https://github.com/kelvingao/ezib-mcp.git
    cd ezib-mcp
    
  2. Install dependencies:

    pip install -e .
    
  3. Create a .env file based on .env.example:

    cp .env.example .env
    
  4. Configure your environment variables in the .env file (see Configuration section)

  1. Build the Docker image:

    docker build -t mcp/ezib --build-arg PORT=8050 .
    
  2. Create a .env file based on .env.example and configure your environment variables

Configuration

The following environment variables can be configured in your .env file:

VariableDescriptionDefaultExample
IB_HOSTInteractive Brokers host127.0.0.1127.0.0.1
IB_PORTInteractive Brokers port40014001
IB_CLIENTIDClient ID for IB connection01
TRANSPORTTransport protocol (sse or stdio)-sse
HOSTHost to bind to when using SSE transport-0.0.0.0
PORTPort to listen on when using SSE transport-8050

Running the Server

Using pip

SSE Transport

# Set TRANSPORT=sse in .env then:
python src/server.py

The MCP server will run as an API endpoint that you can connect to with the configuration shown below.

Stdio Transport

With stdio, the MCP client itself can spin up the MCP server, so nothing to run at this point.

Using Docker

SSE Transport

docker run --env-file .env -p 8050:8050 mcp/ezib

The MCP server will run as an API endpoint within the container that you can connect to with the configuration shown below.

Stdio Transport

With stdio, the MCP client itself can spin up the MCP server container, so nothing to run at this point.

Integration with MCP Clients

SSE Configuration

Once you have the server running with SSE transport, you can connect to it using this configuration:

{
  "mcpServers": {
    "ezib": {
      "transport": "sse",
      "url": "http://localhost:8050/sse"
    }
  }
}

Note for Windsurf users: Use serverUrl instead of url in your configuration:

{
  "mcpServers": {
    "ezib": {
      "transport": "sse",
      "serverUrl": "http://localhost:8050/sse"
    }
  }
}

Note for n8n users: Use host.docker.internal instead of localhost since n8n has to reach outside of its own container to the host machine:

So the full URL in the MCP node would be: http://host.docker.internal:8050/sse

Make sure to update the port if you are using a value other than the default 8050.

Python with Stdio Configuration

Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:

{
  "mcpServers": {
    "ezib": {
      "command": "your/path/to/ezib-mcp/.venv/bin/python",
      "args": ["your/path/to/ezib-mcp/src/main.py"],
      "env": {
        "TRANSPORT": "stdio"
      }
    }
  }
}

Docker with Stdio Configuration

{
  "mcpServers": {
    "ezib": {
      "command": "docker",
      "args": ["run", "--rm", "-i", 
               "-e", "TRANSPORT", 
               "mcp/ezib"],
      "env": {
        "TRANSPORT": "stdio"
      }
    }
  }
}

Usage Examples

Here are some examples of how to use the EZIB MCP server with an AI agent:

Getting Account Information

Retrieve my current account balance and positions.

Placing an Order

Place a market order to buy 100 shares of AAPL.

Retrieving Market Data

Get the current price and trading volume for TSLA.

Managing Positions

Show me all my open positions and their current P&L.

License

MIT License

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Playwright McpPlaywright MCP server
Serper MCP ServerA Serper MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
DeepChatYour AI Partner on Desktop
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Tavily Mcp
Amap Maps高德地图官方 MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
WindsurfThe new purpose-built IDE to harness magic
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"