ibkr-mcp
Click on "Deploy 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 show me my account summary"
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
A read-only-by-default MCP server for Interactive Brokers — account, positions, PnL, market data, and full trade history from a local TWS / IB Gateway session.
What it is
ibkr-mcp exposes your Interactive Brokers account to any Model Context Protocol client (Claude Code, Claude Desktop, and others) through a locally running Trader Workstation or IB Gateway, using the ib_async library.
No credentials pass through this server. You log in to TWS or IB Gateway as usual, and ibkr-mcp attaches to its API socket on 127.0.0.1. By default it is read-only: no order tools exist, and the only outbound network call it can make is the optional Flex history fetch, pinned to interactivebrokers.com.
Related MCP server: IBKR MCP Server
Tools
Read-only (always available):
list_accounts,get_account_summary,get_positions,get_portfolio,get_pnlget_quote,get_historical_data,lookup_contract,search_contractsget_open_orders,get_executionsreview_positions— flags open positions past a loss threshold for a deliberate "thesis changed or just the price?" reviewget_trade_history,get_cash_transactions,get_history_coverage(see Historical activity)
Trading (only registered when IBKR_ENABLE_TRADING=true):
preview_order— a what-if that returns margin and commission impact and places nothingplace_order— market or limit orders, with quantity, notional, and rate capscancel_order— cancels an open order (by default only orders this server placed)
Requirements
uv for dependency management.
TWS or IB Gateway, running and logged in, with the API enabled: Configure > Settings > API > "Enable ActiveX and Socket Clients". Keep "Read-Only API" checked unless you deliberately enable trading.
Ports: TWS live
7496, TWS paper7497, Gateway live4001, Gateway paper4002.
Install
git clone https://github.com/jgalea/ibkr-mcp.git
cd ibkr-mcp
uv sync --lockedRegister with Claude Code (run from the cloned directory):
claude mcp add ibkr --env IBKR_PORT=4001 -- uv --directory "$(pwd)" run ibkr-mcpOr with Claude Desktop, in claude_desktop_config.json:
{
"mcpServers": {
"ibkr": {
"command": "uv",
"args": ["--directory", "/path/to/ibkr-mcp", "run", "ibkr-mcp"],
"env": { "IBKR_PORT": "4001" }
}
}
}Configuration
Variable | Default | Notes |
|
| TWS / Gateway host |
|
| Match your TWS / Gateway mode |
|
| Unique per API client (must be ≥ 1) |
|
| Connect and request timeout, seconds |
|
| 1 live, 2 frozen, 3 delayed, 4 delayed-frozen |
| unset |
|
|
| Hard cap on units per order (ceiling 1,000,000) |
|
| Cap on order notional (ceiling 10,000,000). Exact for limit orders; for market orders it is checked against a pre-submit snapshot price, so a fast-moving fill can exceed it |
|
| Aggregate order rate limit across concurrent calls |
| unset |
|
Security model
Trading is gated in three independent layers:
No order tools are registered unless
IBKR_ENABLE_TRADING=true, so a client cannot call what does not exist.In read-only mode every account-mutating call in the underlying library is stubbed out inside the process, so no code path can transmit an order.
TWS / Gateway's own "Read-Only API" setting rejects order requests at the gateway. Keep it checked unless you enable trading. (The library's
readonlyconnect flag only skips fetching order state; it is not enforcement on its own.)
Other properties:
Transport is stdio and pinned; it cannot be promoted to a network listener by an environment variable or a stray
.env.The IB API protocol is cleartext TCP. Keep
IBKR_HOSTon localhost; tunnel over SSH if you must reach a remote gateway.Do not run with
INFO/DEBUGlogging: the HTTP client logs request URLs atINFO, and Flex request URLs carry your token.Tool output (account IDs, balances, positions) flows into whatever model your MCP host uses. Be deliberate about which host you connect.
When trading is enabled, test against a paper account (port 7497 / 4002) first, and keep TWS's precautionary order settings on.
Historical activity
The Gateway socket only exposes current-day executions. get_trade_history and get_cash_transactions pull full account history (trades, dividends, interest, deposits, fees) from IBKR's Flex Web Service over HTTPS, and cache it in a local SQLite archive (~/.ibkr-mcp/archive.db, owner-only) so rows never age out of the rolling Flex window.
One-time setup in Client Portal:
Performance & Reports > Flex Queries > new Activity Flex Query. Include the Trades and Cash Transactions sections, period "Last 365 Calendar Days", format XML. Note the numeric Query ID.
On the same page, under Flex Web Service Configuration, enable it and generate a token.
Store the token outside your config, for example in the macOS Keychain, then point the server at it:
Variable | Notes |
| Numeric ID of your Activity Flex Query (or |
| A command whose stdout is the token, e.g. |
| The token itself (fallback; prefer |
Backfilling history older than 365 days
A Flex query reaches at most the trailing 365 days. To seed the archive with older history, export Activity Statements (Client Portal > Performance & Reports > Statements > Activity Statement, Custom Date Range, up to 365 days per file, Download CSV) and import them:
uv run python -m ibkr_mcp.importer /path/to/activity_statement.csvImports are deduplicated, so re-running is safe. get_history_coverage reports the archived span.
Development
uv run pytest
uv run ruff check src testsDisclaimer
Not affiliated with or endorsed by Interactive Brokers. Provided as-is under the MIT license, with no warranty. You are responsible for any orders placed through it and for keeping the trading gates configured as you intend. Nothing here is investment advice.
License
Available Tools
15 toolsget_account_summaryB
Account summary: net liquidation, cash, buying power, margin, etc.
Inputs: account. Returns: result
get_cash_transactionsC
Historical cash activity (dividends, interest, deposits/withdrawals, fees) from the configured Flex query. Needs IBKR_FLEX_QUERY_ID + token; see README.
Inputs: days, max_rows, type_filter. Returns: result
get_executionsA
Executions (fills) from the current session/day.
Inputs: no named parameters. Returns: result
get_historical_dataC
Historical OHLCV bars.
Inputs: symbol (required), bar_size, currency, duration, +4 more. Returns: result
get_history_coverageA
Date span and row counts of locally archived account history.
Inputs: no named parameters. Returns: result
get_open_ordersA
Open (working) orders across accounts.
Inputs: no named parameters. Returns: result
get_pnlB
Today's realized/unrealized/daily PnL for an account.
Inputs: account. Returns: result
get_portfolioB
Portfolio with market value, unrealized and realized PnL per position.
Inputs: account. Returns: result
get_positionsB
Current positions with quantity and average cost.
Inputs: account. Returns: result
get_quoteC
Market data snapshot (delayed by default; see IBKR_MARKET_DATA_TYPE).
Inputs: symbol (required), currency, exchange, sec_type. Returns: result
get_trade_historyA
Historical executed trades from the configured Flex query (up to its period, plus everything previously archived locally). Needs IBKR_FLEX_QUERY_ID + token; see README.
Inputs: days, symbol, max_rows. Returns: result
list_accountsB
List account IDs managed by the current TWS/Gateway login.
Inputs: no named parameters. Returns: result
lookup_contractC
Resolve a symbol to a fully qualified IB contract (conId, exchange, etc.).
Inputs: symbol (required), currency, exchange, sec_type. Returns: result
review_positionsA
Review open positions for loss discipline. Flags positions that have fallen past a loss threshold so a deliberate decision gets made — "has the thesis changed, or just the price?" — instead of defaulting to holding. Surfaces the book so the well-documented tendency to hold losers and sell winners (the disposition effect) gets a conscious check. Informational, not advice.
Inputs: account, loss_threshold_pct. Returns: result
search_contractsC
Search instruments by symbol or company name.
Inputs: pattern (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Each tool targets a specific IBKR functionality (account summary, transactions, executions, PnL, positions, etc.) with no overlapping purposes. Clear distinction between similar concepts like portfolio vs. positions or trade history vs. executions.
All tool names follow a verb_noun pattern using snake_case. Verbs vary (get, list, lookup, review, search) but each is appropriate for its action, and the overall convention is uniform and predictable.
15 tools cover a broad range of IBKR account and trading operations without being excessive. Each tool serves a distinct purpose and the number is well-scoped for the domain.
The tool set provides excellent read capabilities but lacks any tool for placing, modifying, or canceling orders, which is a critical gap for a trading platform. Agents can analyze but cannot execute trades, making the surface incomplete for full lifecycle management.
Maintenance
Related MCP Connectors
Trading MCP server for AI agents, with live market data, account reads and controlled execution.
MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents
JW3.ai remote MCP server for market reads and confirm-gated trading execution.
Hosted MCP server for MT4 and MT5: read accounts, prices and candles, and place or close orders.
Related MCP Servers
- FlicenseCqualityDmaintenanceAn MCP server that provides an interface for the Interactive Brokers API via the ib_async library. It enables users to manage accounts, access real-time and historical market data, and execute or monitor trades through TWS or IB Gateway.331-
- AlicenseNot gradedqualityDmaintenanceAn MCP server for Interactive Brokers, enabling account management, trading operations, and market data queries.8MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for Interactive Brokers that exposes portfolio data, market quotes, trading, and analysis to any MCP-compatible AI client, with support for EU investors and safety-gated trading.1MIT
- AlicenseAqualityDmaintenanceRead-only MCP server for Interactive Brokers that exposes market data, positions, and account info as MCP tools.8MIT