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
This commit is contained in:
Rasyidan Akbar F. 2026-11-04 19:26:10 +07:00
commit 9b46161566
10 changed files with 145 additions and 18 deletions

View file

@ -33,6 +33,21 @@ Tools that fetch live data return:
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:
```json
{
"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: