Interactive Brokers MCP Server for Claude Desktop/Code
Project description
IBKR MCP Server
A professional Model Context Protocol (MCP) server for Interactive Brokers API integration, designed for use with Claude Desktop and Claude Code.
Features
- ✅ Multi-Account Support - Switch between multiple IBKR accounts
- ✅ Short Selling Analysis - Shortable shares, borrow rates, margin requirements
- ✅ Real-time Market Data - Live quotes, historical data, options chains
- ✅ Portfolio Management - Positions, P&L, account summaries
- ✅ Trading Operations - Place, modify, cancel orders (with safety checks)
- ✅ Auto-Reconnection - Handles TWS/Gateway restarts gracefully
- ✅ Production Ready - Proper error handling, logging, and monitoring
Quick Start
Prerequisites
- Python 3.10 or higher
- Interactive Brokers account with TWS or IB Gateway
- Claude Desktop or Claude Code
Installation
-
Clone the repository:
git clone https://github.com/yourusername/ibkr-mcp-server.git cd ibkr-mcp-server
-
Run the setup script:
# macOS/Linux chmod +x scripts/setup.sh ./scripts/setup.sh # Windows scripts\setup.bat
-
Configure your settings:
cp .env.example .env # Edit .env with your IBKR settings
-
Start TWS/IB Gateway and enable API connections
-
Test the server:
python -m ibkr_mcp_server.main --test
Claude Integration
Claude Desktop:
Add to your claude_desktop_config.json:
{
"mcpServers": {
"ibkr": {
"command": "python",
"args": ["-m", "ibkr_mcp_server.main"],
"cwd": "/path/to/ibkr-mcp-server"
}
}
}
Claude Code:
claude mcp add ibkr 'python -m ibkr_mcp_server.main' --cwd /path/to/ibkr-mcp-server
Usage Examples
Basic Operations
# Get portfolio across all accounts
"Show me my current portfolio"
# Switch accounts
"Switch to account DU7654321"
# Market data
"Get real-time quotes for AAPL, TSLA, MSFT"
Short Selling Analysis
# Complete short selling analysis
"Analyze short selling for GME, AMC, BBBY - show availability, borrow costs, and margin requirements"
# Check specific account
"Check shortable shares for TSLA in my paper trading account"
Trading Operations
# Place orders (paper trading recommended)
"Place a limit order to buy 100 shares of AAPL at $150"
# Check margin requirements
"What are the margin requirements for shorting 200 shares of TSLA?"
Available Tools
| Tool | Description |
|---|---|
get_portfolio |
Current portfolio positions and P&L |
get_account_summary |
Account balances and key metrics |
switch_account |
Switch between IBKR accounts |
check_shortable_shares |
Short selling availability |
get_margin_requirements |
Margin requirements for securities |
get_borrow_rates |
Stock borrow rates (short selling costs) |
short_selling_analysis |
Complete short selling analysis |
get_market_data |
Real-time market quotes |
get_historical_data |
Historical price data |
place_order |
Place trading orders (with safety checks) |
get_connection_status |
Check IBKR connection status |
Configuration
Environment Variables
# IBKR Connection
IBKR_HOST=127.0.0.1
IBKR_PORT=7497 # 7497=TWS Paper, 7496=TWS Live, 4001=Gateway
IBKR_CLIENT_ID=1
IBKR_IS_PAPER=true
# Logging
LOG_LEVEL=INFO
# Safety
ENABLE_LIVE_TRADING=false # Set to true for live trading
MAX_ORDER_SIZE=1000 # Maximum order size
TWS/Gateway Setup
- Start TWS or IB Gateway
- Go to Configuration → API → Settings
- Enable "ActiveX and Socket Clients"
- Set socket port (7497 for paper, 7496 for live)
- Add 127.0.0.1 to "Trusted IPs"
- Check "Download open orders on connection"
Development
Setup Development Environment
pip install -e ".[dev]"
pre-commit install
Running Tests
pytest tests/ -v
Code Quality
black ibkr_mcp_server/
isort ibkr_mcp_server/
mypy ibkr_mcp_server/
Deployment
Auto-start on Boot (macOS)
python scripts/install_service.py --platform macos
Auto-start on Boot (Linux)
python scripts/install_service.py --platform linux
Docker Deployment
docker build -t ibkr-mcp-server .
docker run -d --name ibkr-mcp -p 8080:8080 ibkr-mcp-server
Documentation
Safety & Disclaimers
⚠️ Important Safety Notes:
- Always test with paper trading first
- Verify all data in TWS before making trading decisions
- This software is for educational purposes
- Use at your own risk
- No warranty provided
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iflow_mcp_arjundivecha_ibkr_mcp_server-1.0.1.tar.gz.
File metadata
- Download URL: iflow_mcp_arjundivecha_ibkr_mcp_server-1.0.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e35941a38678949c564658a6fbb25aeeb0d885e0de029fdcdaa802d99dfa34f
|
|
| MD5 |
a1943ddf1a9448d84bb91a17f159e3f9
|
|
| BLAKE2b-256 |
790f41844710b1cb93073f96d77d612ef8f80221df99757483798cac6563e3aa
|
File details
Details for the file iflow_mcp_arjundivecha_ibkr_mcp_server-1.0.1-py3-none-any.whl.
File metadata
- Download URL: iflow_mcp_arjundivecha_ibkr_mcp_server-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9308fdc17c10d6a0fdde9425a7e7b4677b82410398bad338a115fc3c1b735e15
|
|
| MD5 |
744f62428dded5e7040ebdff6315e8a8
|
|
| BLAKE2b-256 |
0f5ece5eb5594a24784959e425d4b3cca2789463059a5fdf6531686e74c9aa6f
|