mm-ibkr-mcp

mm-ibkr-mcp

MCP server for Interactive Brokers that enables account monitoring, order preview, trade execution, and basket trading with human-in-the-loop approval via Telegram and SQLite-backed audit.

Category
访问服务器

README

mm-ibkr-mcp

⚠️ LIVE CAPITAL AT RISK — USE AT YOUR OWN RISK

This project connects to Interactive Brokers and can place real, irreversible trades with real money. It is a proof-of-concept research implementation for agent-driven trading workflows. It is not financial advice, not a licensed trading system, and not production-ready.

Agent systems can and do make errors: misnamed parameters, hallucinated calculations, incorrect order quantities, and wrong order sides have all been observed in testing. The human-in-the-loop Telegram approval gate exists precisely because automated execution without oversight is dangerous.

You are solely responsible for any losses incurred through use of this software. If you do not understand the risks, do not use this project.

mm-ibkr-mcp is the canonical Interactive Brokers MCP repo for agent-driven account monitoring and trade execution.

It assumes the user already has IB Gateway or TWS running locally. This repo does not manage the broker process. Its job is to connect, inspect account state, preview orders, place trades, persist execution state, and gate submissions through Telegram when required.

The older mm-ibkr-gateway repo remains public for now and will later narrow into gateway deployment and maintenance tooling. This repo is the canonical monitoring and trading MCP surface.

Scope

Included:

  • account health, balances, P&L, positions, open orders
  • market data, contract resolution, options chain and snapshot tools
  • single-order preview and placement
  • durable basket execution through persisted trade intents
  • SQLite-backed audit, approvals, trade intents, execution state, and position snapshots
  • Telegram approval flow for single orders and baskets
  • compare-and-swap admin control over control.json

Not included as part of the canonical workflow:

  • starting or stopping IB Gateway
  • web UI or REST admin as a first-class interface
  • schedulers, signal ingestion, or separate OMS daemons

Safety model

Two layers control execution:

  1. control.json
    • orders_enabled
    • dry_run
    • block_reason
  2. MCP_ORDER_APPROVAL_MODE
    • telegram: order submission requires Telegram approval
    • yolo: no approval gate

Safe defaults are:

  • orders_enabled=false
  • dry_run=true
  • MCP_ORDER_APPROVAL_MODE=telegram

Configuration

On first start, uv run ibkr-mcp creates safe defaults for:

  • data/ibkr-mcp/config.json
  • data/ibkr-mcp/control.json

Edit config.json to match your local IB Gateway or TWS connection:

{
  "ibkr_host": "127.0.0.1",
  "ibkr_port": 4002,
  "ibkr_client_id": 1,
  "default_account_id": null
}

.env is optional. Copy .env.example to .env only if you want Telegram approval or explicit yolo mode:

MCP_ORDER_APPROVAL_MODE=telegram

If using Telegram approval mode, also set:

TELEGRAM_BOT_TOKEN=...
TELEGRAM_CHAT_ID=...

For monitoring only, you can leave .env empty and use the default approval posture.

Advanced-only environment overrides:

MM_IBKR_DATA_DIR=/path/to/data
MM_IBKR_CONFIG_PATH=/path/to/config.json
MM_IBKR_CONTROL_DIR=/path/to/control-dir
MCP_TRANSPORT=streamable-http
MCP_HOST=127.0.0.1
MCP_PORT=8001
MCP_AUTH_TOKEN=change-me
MCP_ENABLE_ADMIN_TOOLS=true
APPROVED_UNUSED_EXPIRY_SECONDS=600   # auto-expiry for approved-but-unused approvals (default 600 s)

Running

Install dependencies:

uv sync --group dev

Start the MCP server over stdio:

uv run ibkr-mcp

The default transport is local stdio, which is the lowest-friction MCP setup for Claude Code/Desktop style clients.

Run over HTTP only for advanced self-hosted setups:

export MCP_TRANSPORT=streamable-http
export MCP_HOST=127.0.0.1
export MCP_PORT=8001
export MCP_AUTH_TOKEN=change-me
uv run ibkr-mcp

Remote Execution Host

If IB Gateway runs on another machine, the recommended agent setup is to run mm-ibkr-mcp on that execution host and launch it over SSH stdio from the client machine.

Why this is preferred:

  • control.json, approvals, and audit state stay on the execution host
  • the MCP process connects to the gateway through that host's own 127.0.0.1:4001 / 127.0.0.1:4002
  • OpenCode or Claude does not need a separate local socket tunnel for the execution workflow

Use local SSH port forwarding only for other applications that require local gateway sockets on the client machine, such as a tracker or sync job that connects directly through ib_insync.

Canonical tools

Core monitoring and execution:

  • health
  • get_trading_status
  • get_schedule_status
  • get_account_summary
  • get_positions
  • get_pnl
  • list_open_orders
  • get_order_status
  • preview_order
  • place_order
  • cancel_order

Basket execution:

  • preview_order_basket
  • create_trade_intent
  • request_trade_intent_approval
  • submit_trade_intent
  • get_trade_intent
  • list_trade_intents
  • reconcile_trade_intent
  • cancel_trade_intent

Approval and safety:

  • request_trade_approval (Blocks until approved/denied/timeout)
  • request_trade_intent_approval (Blocks until approved/denied/timeout)
  • request_environment_change (Blocks until approved/denied/timeout)
  • execute_environment_change
  • check_approval_status
  • emergency_stop

Expected workflow

Single order:

  1. get_trading_status
  2. resolve_contract
  3. preview_order
  4. assess_order_impact
  5. validate_against_profile
  6. If MCP_ORDER_APPROVAL_MODE=telegram, request approval
  7. place_order

Basket:

  1. preview_order_basket
  2. create_trade_intent
  3. If MCP_ORDER_APPROVAL_MODE=telegram, request approval
  4. submit_trade_intent
  5. reconcile_trade_intent

Persistence

The MCP server uses one SQLite database for:

  • audit_log
  • order_history
  • approvals
  • trade_intent
  • intent_order
  • execution_state
  • position_snapshot

This gives the agent one durable source of truth for approvals, order submission, reconciliation, and audit.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选