ibkr-mcp

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.

Category
访问服务器

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-mcp instances from starting against the same IBKR_HOST / IBKR_PORT / IBKR_CLIENT_ID combination.
  • You should still enable IBKR's own Read-Only API setting 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:

  1. Open the API settings page.
  2. Enable ActiveX and Socket Clients.
  3. Set the socket port to the value you want this server to use.
  4. Enable Read-Only API if you want IBKR to enforce read-only access too.
  5. Allow 127.0.0.1 or 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_executions accepts either time in raw IB format (YYYYMMDD HH:mm:ss) or since in RFC3339 form, but not both.
  • ibkr_search_contracts is useful for discovery; ibkr_contract_details is the better follow-up when you need a specific contract definition for downstream calls.
  • For stock and option lookups, the server infers SMART as the default exchange when appropriate. For cash pairs, it infers IDEALPRO.
  • 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-mcp process 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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选