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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.