IBKR MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@IBKR MCP ServerShow me my current portfolio positions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
IBKR MCP Server
An Interactive Brokers (IBKR) MCP server implementation based on FastMCP 2.0 and MCP StreamableHTTP, providing account management, trading operations, and market data query functionality.
Features
π Connection Management: Stable connection with IBKR TWS/Gateway
π Account Information: Query account summary, positions, and balances
πΉ Trading Operations: Place orders, cancel orders, query order status
π Market Data: Real-time and historical market data retrieval
π‘οΈ Type Safety: Data validation using Pydantic
β‘ Async Architecture: High-performance asynchronous I/O operations
π Rich Logging: Structured logging
π§ Flexible Configuration: Support for environment variables and configuration files
Related MCP server: claude-tws-connect
Installation
Install from Source
git clone https://github.com/yourusername/ibkr-mcp-server.git
cd ibkr-mcp-server
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install the package
pip install -e .Development Setup
# Install development dependencies
pip install -e ".[dev]"
# Setup pre-commit hooks
pre-commit installQuick Start
1. Configure Environment
Create a .env file in the project root:
# MCP Server Settings
MCP__HOST=0.0.0.0
MCP__PORT=8080
# IBKR Connection Settings
IBKR__HOST=127.0.0.1
IBKR__PORT=4002
IBKR__CLIENT_ID=1
IBKR__READONLY=false
# Logging Settings
LOGGING__LEVEL=INFO2. Test Connection
# Test IBKR connection
python -m ibkr_mcp_server.cli test --host 127.0.0.1 --port 40023. Start Server
# Start server
python -m ibkr_mcp_server.cli serve
# Or with custom parameters
python -m ibkr_mcp_server.cli serve --host 0.0.0.0 --port 8080Configuration
Environment Variables
Variable | Default | Description |
|
| MCP server listen address |
|
| MCP server port |
|
| IBKR TWS/Gateway address |
|
| IBKR TWS/Gateway port |
|
| IBKR client ID |
|
| Read-only mode |
|
| Logging level |
IBKR Port Configuration
Platform | Demo Port | Live Port |
TWS | 4002 | 7496 |
Gateway | 4002 | 4001 |
MCP Tools
The server provides 9 MCP tools:
Account Management
get_account_summary: Get account summary informationget_positions: Get position information
Trading Operations
place_order: Place an ordercancel_order: Cancel an orderget_open_orders: Get open orders
Market Data
get_market_data: Get real-time market dataget_historical_data: Get historical data
Connection Management
connection_status: Check connection statusreconnect: Reconnect to IBKR
Usage Examples
Place Order
{
"tool": "place_order",
"arguments": {
"contract": {
"symbol": "AAPL",
"sec_type": "STK",
"exchange": "SMART",
"currency": "USD"
},
"order": {
"action": "BUY",
"total_quantity": 100,
"order_type": "LMT",
"lmt_price": 150.0
}
}
}Get Positions
{
"tool": "get_positions",
"arguments": {}
}Get Historical Data
{
"tool": "get_historical_data",
"arguments": {
"contract": {
"symbol": "AAPL",
"sec_type": "STK",
"exchange": "SMART",
"currency": "USD"
},
"duration": "1 D",
"bar_size": "1 min"
}
}Architecture
βββββββββββββββββββββββ
β MCP Client β
β (Claude Desktop, β
β Custom Client) β
βββββββββββ¬ββββββββββββ
β HTTP/WebSocket
βββββββββββ΄ββββββββββββ
β FastMCP Server β
β (MCP Protocol Layer)β
βββββββββββββββββββββββ€
β IBKR MCP Server β
β (Business Logic) β
βββββββββββββββββββββββ€
β IBKR Client β
β (API Wrapper) β
βββββββββββ¬ββββββββββββ
β TWS API
βββββββββββ΄ββββββββββββ
β TWS/Gateway β
β (IBKR Platform) β
βββββββββββββββββββββββDevelopment
Project Structure
src/ibkr_mcp_server/
βββ __init__.py # Package initialization
βββ server.py # MCP server implementation
βββ client.py # IBKR client wrapper
βββ models.py # Data models
βββ config.py # Configuration management
βββ exceptions.py # Exception definitions
βββ cli.py # Command line interfaceCode Standards
Use
blackfor code formattingUse
isortfor import sortingUse
flake8for code lintingUse
mypyfor type checking
Testing
# Run tests
pytest
# Generate coverage report
pytest --cov=src --cov-report=htmlDeployment
Docker Deployment
# Build image
docker build -t ibkr-mcp-server .
# Run container
docker run -p 8080:8080 --env-file .env ibkr-mcp-serverDocker Compose
# Start services
docker-compose up -d
# View logs
docker-compose logs -fIntegration with Claude Desktop
Add to your Claude Desktop MCP configuration:
{
"mcpServers": {
"ibkr": {
"command": "python",
"args": ["-m", "ibkr_mcp_server.cli", "serve"],
"env": {
"IBKR__HOST": "127.0.0.1",
"IBKR__PORT": "4002",
"IBKR__CLIENT_ID": "1"
}
}
}
}Important Notes
TWS/Gateway: Ensure IBKR TWS or Gateway is running with API connection enabled
Port Configuration: Make sure TWS/Gateway API port matches your configuration
Permissions: Ensure your account has appropriate trading permissions
Risk Management: Please implement proper risk controls in production environments
Market Data: Some market data may require subscriptions
Troubleshooting
Common Issues
Connection Failed: Check if TWS/Gateway is running and API is enabled
Client ID Conflict: Use different client IDs for multiple connections
Port Issues: Verify the correct port for your TWS/Gateway setup
Market Data Errors: Ensure you have proper market data subscriptions
Logging
Enable debug logging for troubleshooting:
LOGGING__LEVEL=DEBUG python -m ibkr_mcp_server.cli serveLicense
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues, please file an Issue.
δΈζζζ‘£: README_zh_CN.md
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/GaoChX/ibkr-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server