ibkr-mcp
A read-only MCP server that connects to Interactive Brokers Gateway or TWS to expose account, contract, execution, and historical-data queries over stdio.
README
ibkr-mcp
ibkr-mcp is a read-only MCP server for Interactive Brokers IBKR Gateway or TWS. It connects to an already running socket API session and exposes account, contract, execution, and historical-data queries to MCP clients over stdio.
The server does not implement any order-entry operations. There are no tools for placing, modifying, or cancelling orders.
What It Exposes
| Tool | Purpose |
|---|---|
ibkr_status |
Confirm connectivity and return IBKR server time. |
ibkr_accounts |
List managed accounts visible to the current login. |
ibkr_account_summary |
Fetch account summary values such as cash, buying power, and margin. |
ibkr_positions |
List open positions across accessible accounts. |
ibkr_open_orders |
List currently open orders visible to the session. |
ibkr_executions |
Fetch execution reports with optional account, symbol, side, and time filters. |
ibkr_search_contracts |
Search contracts by ticker or company name. |
ibkr_contract_details |
Resolve a partial contract definition into concrete IBKR contract details. |
ibkr_historical_bars |
Fetch read-only historical bars for a contract. |
Safety Model
- Every registered MCP tool is read-only.
- The server never calls IBKR APIs for order placement, modification, or cancellation.
- A local process lock prevents duplicate
ibkr-mcpinstances from starting against the sameIBKR_HOST/IBKR_PORT/IBKR_CLIENT_IDcombination. - You should still enable IBKR's own
Read-Only APIsetting if you want Gateway- or TWS-level enforcement as a second guardrail.
Prerequisites
- Node.js and npm
- A running IBKR Gateway or TWS session
- Socket API access enabled in that IBKR session
In IBKR Gateway or TWS:
- Open the API settings page.
- Enable
ActiveX and Socket Clients. - Set the socket port to the value you want this server to use.
- Enable
Read-Only APIif you want IBKR to enforce read-only access too. - Allow
127.0.0.1or your MCP host in trusted IPs if your IBKR configuration requires it.
The server default is IBKR_PORT=4002, which matches the common IBKR Gateway paper-trading setup. If your session uses a different port, set IBKR_PORT explicitly.
Install
npm install
npm run build
Useful development commands:
npm run dev
npm run typecheck
Run
IBKR_HOST=127.0.0.1 \
IBKR_PORT=4002 \
IBKR_CLIENT_ID=19191 \
npm start
IBKR_CLIENT_ID must be unique for the API client session you want to open. Run exactly one ibkr-mcp process per IBKR_HOST / IBKR_PORT / IBKR_CLIENT_ID.
If your MCP client launches this server for you, do not also leave a separate npm start process running against the same target. The server will fail fast if another instance already holds the same lock.
Configuration
| Variable | Default | Description |
|---|---|---|
IBKR_HOST |
127.0.0.1 |
Hostname of the IBKR Gateway or TWS socket API endpoint. |
IBKR_PORT |
4002 |
Socket API port. |
IBKR_CLIENT_ID |
19191 |
API client ID used when connecting to IBKR. |
IBKR_TIMEOUT_MS |
10000 |
Request timeout for IBKR API calls. |
IBKR_ACCOUNT_GROUP |
All |
Default account group for ibkr_account_summary. |
IBKR_ACCOUNT_SUMMARY_TAGS |
conservative defaults | Optional comma-separated override for summary fields. |
Default account summary tags:
AccountType,NetLiquidation,TotalCashValue,SettledCash,BuyingPower,AvailableFunds,ExcessLiquidity,GrossPositionValue,InitMarginReq,MaintMarginReq,DayTradesRemaining
MCP Configuration Example
Point your MCP client at the built server entrypoint:
{
"mcpServers": {
"ibkr": {
"command": "node",
"args": ["/absolute/path/to/ibkr-mcp/dist/index.js"],
"env": {
"IBKR_HOST": "127.0.0.1",
"IBKR_PORT": "4002",
"IBKR_CLIENT_ID": "19191"
}
}
}
}
This project uses stdio transport. That means each MCP client normally starts its own server process. If you need multiple clients to share one IBKR session, move to a shared daemon or network transport rather than launching separate stdio instances.
Usage Notes
ibkr_executionsaccepts eithertimein raw IB format (YYYYMMDD HH:mm:ss) orsincein RFC3339 form, but not both.ibkr_search_contractsis useful for discovery;ibkr_contract_detailsis the better follow-up when you need a specific contract definition for downstream calls.- For stock and option lookups, the server infers
SMARTas the default exchange when appropriate. For cash pairs, it infersIDEALPRO. - Historical data, executions, and some contract lookups still depend on the permissions attached to the logged-in IBKR user.
Troubleshooting
- Connection failures usually mean the IBKR session is not running, the socket API is disabled, the port is wrong, or the client ID is already in use.
- Duplicate-process errors mean another
ibkr-mcpprocess is already running with the same host, port, and client ID combination. - Empty or incomplete market-data responses often point to IBKR permissions, exchange entitlements, or an underspecified contract.
- This server does not launch IBKR Gateway or TWS. It only connects to an existing API endpoint.
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.