ibkr-risk-mcp

Model Context Protocol server · Interactive Brokers

Where the P&L curve
bottoms out.

Reads IB's model greeks, its implied volatility surface and its what-if margin out of TWS, then reprices the whole portfolio across underlying shocks. It answers one kind of question: how bad does it get, at what shock, and what moves if you add a hedge.

It does not duplicate the official IBKR connector. Positions, balances, orders, trades and prices come from there. This fills the gap that one leaves.

Add to Claude Desktop Other clients reading latest release…
P&L vs. underlying shock · sticky strike test fixture · 121 points
−146,151 trough, at −18.0% 0.00 at 0% −30% −20% −10% 0 +10% +20% +30%
An options portfolio repriced across underlying shocks, produced by the repricing layer in this repository from its own test fixture — not drawn by hand. The curve is exactly zero at zero shock by construction, and the minimum sits inside the range rather than at its edge, which is the case the server exists to find.

Install

One block, wherever your client keeps it

The snippets carry the current release, so there is no tag to look up. TWS or IB Gateway must be running on the same machine with the API enabled — the server talks to its local socket and never reaches IBKR over the internet.

Claude Desktop · Claude Code · Cursor · Windsurf · Gemini CLI
Codex CLI · ~/.codex/config.toml
ClientWhere the config goes
Claude Desktop%APPDATA%\Claude\claude_desktop_config.json, or ~/Library/Application Support/Claude/
Claude Codeclaude mcp add
Cursor~/.cursor/mcp.json, or .cursor/mcp.json per project
VS Code.vscode/mcp.json, keyed under servers with "type": "stdio"
Windsurf~/.codeium/windsurf/mcp_config.json

Ports are 7496 TWS live, 7497 TWS paper, 4001 and 4002 for IB Gateway. If the configured one is wrong, check_connection scans all four and says which is answering. On a login managing more than one account, set IBKR_ACCOUNT: without it every tool that reads positions refuses, rather than adding two accounts together.


Surface

Seven tools

Each carries the protocol's annotations, so a client can group them by permission. Six only read. The seventh is the one that touches IB's order path, and it stays inert unless you switch it on.

ToolWhat it returns
stress_portfolioThe P&L curve across underlying shocks, its trough, a per-position breakdown, and a reconciliation against NetLiquidation
stress_whatifThree curves and three troughs: the portfolio, the portfolio plus hypothetical legs, and the difference
get_position_greeksIB's model greeks for every option position, with both expiry dates and the forward its model used
get_vol_surfaceIB's implied volatility grid for an underlying, by expiry and strike, with days to settlement
get_margin_summaryMargin and liquidity, split into the securities and commodities segments
check_connectionWhich of the ways TWS can be unreachable is happening, and what to do about it
whatif_order gatedIB's own margin impact for a structure, per leg and cumulatively, with the SPAN offset between them

Behaviour

What it gets right that is easy to get wrong

Each of these produces a confidently wrong number if you skip it. All were found against live TWS.

Settlement dates, not last trading days

AM-settled contracts can report the day before settlement, so two options expiring the same morning appear on two dates. IB's realExpirationDate settles it where available; both dates are always returned.

The underlying comes from IB

It is not implied by the expiry. On 18 December 2026 the ES quarterly is written on ESZ6 while the EW3 weekly expiring the same day is on ESH7. underConId is read, never inferred.

Positions are requalified first

Contracts from IB's portfolio arrive with no exchange, and a market data request on one returns nothing at all — no ticks, no error. Left alone, an entire option book reports no greeks.

Nothing is quietly dropped

A contract IB would not price is listed with the reason, and the curve says how much of the book it is missing. Volatilities implied locally are labelled as such and never passed off as IB's.

Everything reconciles

At zero shock the portfolio is rebuilt from its positions — cash, securities at market, futures at their mark — and checked against NetLiquidation. Over 1% out, it returns reconciled: false with the residual.

An edge is not a trough

If the curve is still falling at the end of the range, that minimum is the edge of the window and is labelled as one. Short-option books are concave, so their worst point sits at the boundary unless something is long gamma below it.


Limits

What it will not tell you

Risk Navigator's own volatility shock model is not published by any API. This rebuilds the curve from IB's inputs with a documented model; expect the shape to agree and the last few percent not to.