idx-cli/web/src/content/docs/mcp/index.md
0xrsydn 9b46161566 fix(mcp): hand a call's warnings to the agent
idx-core reports what it works around (history falling back to yahoo when
Stockbit refuses the session, a stale cache served after a failed fetch, a
movements query cut short) as warnings on stderr. An agent never reads
idx-mcp's stderr, so it saw `source: "yahoo"` or `stale: true` with no reason.

- Each tool call collects its warnings with runtime::on_warning and returns
  them as `warnings` on the answer or the error, when there are any.
- The stale-cache warning names the failure behind it.
- The mock's session API 403 is the real session API's block message; the
  public page's block names IDX_PROVIDER=msn as well as `--provider msn`.

Goldens: error-intraday-blocked (json, table) carry the reworded block hint.

Claude-Session: https://claude.ai/code/session_01RqPPVeVDrnLoP7NUZmLRxY
2026-11-04 19:26:10 +07:00

2.6 KiB

title description
MCP server idx-mcp serves idx's stock and ownership data to AI agents over MCP.

idx-mcp is a Model Context Protocol server over stdio. It gives an agent the same data as the idx CLI, as 21 tools (plus an opt-in ownership_sync): quotes, today's session by the minute, the order book, corporate actions and insider movements (with a Stockbit login), price history, screening, company data, analysis, comparison, broker summaries, bandarmology, foreign flow, and the KSEI ownership queries.

It shares idx's config, cache and ownership database, so idx ownership sync in a terminal also feeds the server.

Set it up in your agent →

Results

Tools that fetch live data return:

{
  "data": { "...": "the same shape as idx -o json" },
  "source": "msn",
  "fetched_at": "2026-10-15T03:20:11Z",
  "stale": false
}

source is the provider (msn, yahoo, ipot, idx or stockbit). Results are cached on disk; stale is true when an expired cache entry was served because a fresh fetch failed. Ownership tools return their data directly, from the local database.

What idx prints as a warning in a terminal comes back in warnings, on an answer or an error, when there was any. For example, history that fell back to Yahoo because Stockbit refused your session says so, and a stale answer names the failure behind it:

{
  "data": [{ "date": "2026-11-03", "close": 9875, "...": "..." }],
  "source": "yahoo",
  "fetched_at": "2026-11-04T03:20:11Z",
  "stale": false,
  "warnings": ["Stockbit rejected the session; run `idx stockbit login` again; history falls back to yahoo meanwhile"]
}

Errors come back as a tool result with isError set and the CLI's error body, so the agent can decide whether to retry:

{"error": true, "code": "PROVIDERUNAVAILABLE", "message": "..."}

Limits

Input Limit
tickers per call (get_quotes, compare_stocks) 20, duplicates removed
get_intraday tail 400 minutes (default: the whole session)
get_orderbook depth 50 levels per side (default 10)
screen_stocks limit 200
search_investors limit 100
get_ownership_changes limit 300 per page (default 200); page with offset
concurrent tool calls 4

Ownership data

Ownership tools need a populated database. Either run idx ownership sync once, or start the server with --allow-sync, which adds an ownership_sync tool so the agent can download the snapshot itself (several MB).