IB Portfolio Tracker MCP Server
Connects Claude AI to Interactive Brokers accounts to enable real-time portfolio tracking, position management, and historical market data retrieval. It also integrates financial news and sentiment analysis from multiple sources, including Finnhub and IB native feeds.
README
IB Portfolio Tracker - MCP Server
An MCP (Model Context Protocol) server that connects Claude AI to your Interactive Brokers account for real-time portfolio tracking, financial news, and sentiment analysis.
What Can You Do?
Once set up, you can ask Claude things like:
- "What's my portfolio value?"
- "Show my positions with P&L"
- "Give me a full news analysis for NVDA" (combines IB + Finnhub + sentiment)
- "What's the sentiment around Tesla?"
- "Show historical data for SPY"
- "What news providers are available from IB?"
All responses come directly from your Interactive Brokers account, IB news feeds (Reuters, Dow Jones, etc.), and optionally Finnhub API.
Quick Start
Prerequisites
- macOS, Linux, or Windows
- Python 3.10+ installed
- Interactive Brokers account
- Claude Desktop or Claude Code (VS Code)
Step 1: Download IB Gateway
IB Gateway is a lightweight app that allows API access to your IBKR account.
- Download from: https://www.interactivebrokers.com/en/trading/ibgateway-stable.php
- Install and log in with your IBKR credentials
- Configure API settings:
- Go to Configure → Settings → API → Settings
- Set Socket port to
4001 - Check Read-Only API (recommended for safety)
- Keep IB Gateway running whenever you want to use the portfolio features
Note: IBKR Desktop app does NOT support API connections. You need IB Gateway or TWS.
Step 2: Get a Finnhub API Key (Optional)
Finnhub provides additional news and social sentiment data. This is optional - IB native news works without it.
- Sign up at: https://finnhub.io/register
- Copy your API key from the dashboard
- Free tier: 60 requests/minute (plenty for personal use)
Step 3: Install the MCP Server
# Clone or download this repository
git clone https://github.com/vinbg/ib-mcp-server.git
cd ib-mcp-server
# Run the setup script
# Mac/Linux:
chmod +x setup.sh
./setup.sh
# Windows:
setup.bat
The setup script will:
- Create a Python virtual environment
- Install all dependencies
- Guide you through configuration
- Test your connections
Step 4: Configure Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"ib-portfolio": {
"command": "/FULL/PATH/TO/ib-mcp-server/.venv/bin/python",
"args": ["-m", "ib_mcp.server"],
"cwd": "/FULL/PATH/TO/ib-mcp-server"
}
}
}
Replace /FULL/PATH/TO/ with your actual path!
Then restart Claude Desktop (Cmd+Q, then reopen).
Optional: Add LunarCrush for Crypto Sentiment
LunarCrush provides social sentiment data for cryptocurrencies. To add it alongside this server:
- Get an API key at: https://lunarcrush.com/developers
- Add to your Claude Desktop config:
{
"mcpServers": {
"ib-portfolio": {
"command": "/FULL/PATH/TO/ib-mcp-server/.venv/bin/python",
"args": ["-m", "ib_mcp.server"],
"cwd": "/FULL/PATH/TO/ib-mcp-server"
},
"LunarCrush": {
"type": "http",
"url": "https://lunarcrush.ai/mcp",
"headers": {
"Authorization": "Bearer YOUR_LUNARCRUSH_API_KEY"
}
}
}
}
Now you can ask Claude about crypto social sentiment alongside your IBKR portfolio!
Available Tools (22 total)
Comprehensive News (RECOMMENDED)
| Tool | Description |
|---|---|
get_comprehensive_news |
All-in-one news analysis - combines IB news, Finnhub news, social sentiment, insider sentiment, and AI-analyzed scores |
Portfolio Tools (requires IB Gateway)
| Tool | Description |
|---|---|
get_account_summary |
Net liquidation value, buying power, cash, margin |
get_positions |
All positions with quantities, cost basis, P&L |
get_portfolio_pnl |
Daily, unrealized, and realized P&L breakdown |
get_position_details |
Detailed info for a specific symbol |
get_open_orders |
List pending orders |
get_executions |
Recent trade fills |
Market Data Tools (requires IB Gateway)
| Tool | Description |
|---|---|
get_quote |
Real-time/delayed quotes (bid, ask, last, volume) |
get_historical_data |
OHLCV historical bars |
get_contract_details |
Symbol info, trading hours |
search_symbols |
Find contracts by name |
IB Native News Tools (requires IB Gateway)
| Tool | Description |
|---|---|
get_ib_news_providers |
List available news sources (Reuters, Dow Jones, etc.) |
get_ib_news |
Get historical news from IB for a symbol |
get_ib_news_article |
Get full article text by article ID |
Finnhub News & Sentiment Tools (requires Finnhub API)
| Tool | Description |
|---|---|
search_news |
Search by symbol or keyword |
get_company_news |
Company-specific headlines |
get_market_news |
General market news |
get_social_sentiment |
Reddit/Twitter sentiment metrics |
get_insider_sentiment |
Insider trading signals |
Sentiment Analysis Tools
| Tool | Description |
|---|---|
analyze_news_sentiment |
AI sentiment analysis on news |
analyze_text_sentiment |
Analyze any custom text |
Utility Tools
| Tool | Description |
|---|---|
check_connection_status |
Check IB and API connections |
Configuration
All settings are in the .env file:
# Interactive Brokers Connection
IB_HOST=127.0.0.1
IB_PORT=4001 # 4001=Gateway Paper, 4002=Gateway Live
# News API
FINNHUB_API_KEY=your_finnhub_key_here
# Sentiment Model
SENTIMENT_MODEL=vader # "vader" (fast) or "finbert" (accurate, 500MB model)
# Logging
LOG_LEVEL=INFO
Port Reference
| Port | Application | Mode |
|---|---|---|
| 4001 | IB Gateway | Paper Trading |
| 4002 | IB Gateway | Live Trading |
| 7497 | TWS | Paper Trading |
| 7496 | TWS | Live Trading |
Security
This server is READ-ONLY by default:
- No order placement capabilities
- No account modification
- API keys stored locally in
.env(never committed to git) - Works with IB's "Read-Only API" setting
Your credentials never leave your machine. The MCP server runs locally and communicates only with:
- IB Gateway on localhost
- Finnhub API (for news)
Troubleshooting
"Cannot connect to IB Gateway"
- Is IB Gateway running? Check your dock/taskbar
- Correct port? Verify port in IB Gateway matches your
.env - API enabled? In IB Gateway: Configure → Settings → API → Settings
- Firewall? Ensure localhost connections aren't blocked
"Invalid API key" (Finnhub)
- Check your key at https://finnhub.io/dashboard
- Verify it's correctly copied to
.env - Free tier limit: 60 requests/minute
"Tool not found" in Claude
- Restart Claude Desktop completely (Cmd+Q)
- Check the config file path is correct
- Verify Python path:
which python3in terminal
Test the connection manually
cd ib-mcp-server
source .venv/bin/activate
python -c "
from ib_async import IB
import asyncio
async def test():
ib = IB()
await ib.connectAsync('127.0.0.1', 4001, clientId=99)
print('Connected!')
print('Accounts:', ib.managedAccounts())
ib.disconnect()
asyncio.run(test())
"
Project Structure
ib-mcp-server/
├── setup.sh # Mac/Linux setup script
├── setup.bat # Windows setup script
├── pyproject.toml # Python dependencies
├── .env.example # Configuration template
├── .env # Your configuration (gitignored)
├── README.md # This file
├── claude.md # Claude Code documentation
└── src/ib_mcp/
├── server.py # MCP server entry point
├── config.py # Configuration management
└── clients/
├── ib_client.py # Interactive Brokers API
├── news_client.py # Finnhub API
└── sentiment.py # Sentiment analysis
License
MIT License - feel free to use, modify, and share.
Disclaimer
This software is for informational purposes only. It does not constitute financial advice. Always verify information independently before making investment decisions. The authors are not responsible for any financial losses incurred through the use of this software.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。