Claude TWS Connect MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
git clone https://github.com/danielkristofik/mcp_claude_ibkr.git
cd mcp_claude_ibkr
./install.sh
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add claude-tws-connect -- node "<FULL_PATH_TO_MCP_CLAUDE_IBKR>/dist/index.js"

Replace <FULL_PATH_TO_MCP_CLAUDE_IBKR>/dist/index.js with the actual folder you prepared in step 1.

README.md

Connect Claude to Interactive Brokers TWS for portfolio management and trading

claude-tws-connect

MCP (Model Context Protocol) server that connects Claude to Interactive Brokers TWS via ib_insync. Use natural language to check your portfolio, pull market data, and place orders — all from Claude Desktop, Claude Code, or any MCP-compatible client.

Quick Start

macOS:

git clone https://github.com/danielkristofik/mcp_claude_ibkr.git
cd mcp_claude_ibkr
./install.sh

Linux (Ubuntu/Debian):

git clone https://github.com/danielkristofik/mcp_claude_ibkr.git
cd mcp_claude_ibkr
./install-linux.sh

The installer will:

  1. Find or install Python 3.10+
  2. Create a virtual environment and install dependencies
  3. Let you choose Paper or Live trading port
  4. Configure Claude Desktop automatically
  5. Configure Claude Code (CLI) if installed

Features

Tool Description Read-only
ib_account_summary Account overview — liquidation value, cash, margin, buying power Yes
ib_positions Portfolio positions with market value and P&L Yes
ib_pnl Daily P&L — realized and unrealized Yes
ib_fundamental_data Fundamentals — P/E, EPS, market cap, dividends, 52-week range Yes
ib_margin_impact Margin impact estimate for a hypothetical order (what-if) Yes
ib_market_data Real-time snapshot (bid/ask/last/volume) + Greeks for options Yes
ib_historical_data Historical OHLCV bars Yes
ib_scanner Market scanner (top gainers, losers, most active, etc.) Yes
ib_contract_details Contract details Yes
ib_option_chains Option expirations and strikes Yes
ib_open_orders Active orders Yes
ib_executions Today's executions / fills Yes
ib_prepare_order Prepare an order for review (step 1/2) Yes
ib_submit_order Submit a confirmed order (step 2/2) No
ib_cancel_order Cancel an active order No

Order Safety

Orders use a two-step confirmation flow:

  1. ib_prepare_order — validates the contract, builds the order, and returns a confirmation token
  2. Claude shows the order details to you and waits for explicit approval
  3. ib_submit_order — submits the order only after confirmation (token expires in 5 minutes)

Manual Installation

Prerequisites

  • Python 3.10+
  • TWS or IB Gateway running and logged in
  • TWS API enabled (Edit → Global Configuration → API → Settings)

Setup

git clone https://github.com/danielkristofik/mcp_claude_ibkr.git
cd mcp_claude_ibkr

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Claude Desktop Configuration

Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) and add the IBKR server:

{
  "mcpServers": {
    "ibkr": {
      "command": "/FULL/PATH/TO/claude-tws-connect/venv/bin/python",
      "args": ["/FULL/PATH/TO/claude-tws-connect/ibkr_mcp.py"]
    }
  }
}

Important: Use the full absolute path to the Python binary inside the venv.

See `claude_desktop_config_example.json` for a complete example.

Claude Code (CLI) Setup

If you use Claude Code, the MCP server can be configured with a single command:

claude mcp add --transport stdio --scope user ibkr -- /FULL/PATH/TO/claude-tws-connect/venv/bin/python /FULL/PATH/TO/claude-tws-connect/ibkr_mcp.py

Alternatively, this repository includes a .mcp.json file that makes the MCP server available automatically when you open the project directory in Claude Code — no manual configuration needed.

Verify

Restart Claude Desktop. The ib_* tools should appear in the tools list. Try:

"Show me my account summary"
"What positions do I have?"
"Get historical data for AAPL for the last month"

Configuration

Edit config.json or the variables at the top of ibkr_mcp.py:

TWS_HOST = "127.0.0.1"   # TWS host
TWS_PORT = 7496           # 7496 = live, 7497 = paper trading
CLIENT_ID = 10            # Unique client ID (avoid conflicts with other TWS connections)

TWS Setup

In TWS: Edit → Global Configuration → API → Settings:

  • Enable ActiveX and Socket Clients
  • Socket port: 7496 (live) or 7497 (paper)
  • Uncheck "Read-Only API" if you want to place orders
  • Add 127.0.0.1 to Trusted IPs

Remote IB Gateway

To connect to a remote IB Gateway, use an SSH tunnel:

ssh -L 4002:127.0.0.1:4002 user@remote-server

Then change TWS_PORT t

Tools (8)

ib_account_summaryProvides an account overview including liquidation value, cash, margin, and buying power.
ib_positionsRetrieves portfolio positions with market value and P&L.
ib_pnlRetrieves daily realized and unrealized P&L.
ib_fundamental_dataProvides fundamentals like P/E, EPS, market cap, dividends, and 52-week range.
ib_market_dataProvides a real-time snapshot of bid/ask/last/volume and Greeks for options.
ib_prepare_orderValidates the contract and builds an order, returning a confirmation token.
ib_submit_orderSubmits a confirmed order using a token.
ib_cancel_orderCancels an active order.

Environment Variables

TWS_HOSTThe host address for TWS/Gateway connection
TWS_PORTThe port for TWS/Gateway (7496 for live, 7497 for paper)
CLIENT_IDUnique client ID for TWS connection

Configuration

claude_desktop_config.json
{"mcpServers": {"ibkr": {"command": "/FULL/PATH/TO/claude-tws-connect/venv/bin/python", "args": ["/FULL/PATH/TO/claude-tws-connect/ibkr_mcp.py"]}}}

Try it

Show me my account summary and current buying power.
What are my current positions and their daily P&L?
Get the fundamental data and current market price for AAPL.
Prepare a buy order for 10 shares of TSLA at market price.
Show me the option chain for SPY expiring next month.

Frequently Asked Questions

What are the key features of Claude TWS Connect?

Real-time portfolio monitoring including P&L and margin impact. Market data retrieval for stocks and options including Greeks. Secure two-step order confirmation process for trading. Market scanner for identifying top gainers and losers. Historical OHLCV data access for technical analysis.

What can I use Claude TWS Connect for?

Quickly checking portfolio performance and margin status during trading hours. Performing fundamental analysis on stocks using natural language queries. Executing trades with a safety-first confirmation flow directly from Claude. Retrieving historical market data for research without leaving the chat interface.

How do I install Claude TWS Connect?

Install Claude TWS Connect by running: git clone https://github.com/danielkristofik/mcp_claude_ibkr.git && cd mcp_claude_ibkr && ./install.sh

What MCP clients work with Claude TWS Connect?

Claude TWS Connect works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Claude TWS Connect docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare