Commit Graph

20 Commits

Author SHA1 Message Date
Teknium
a565e2d493 fix(mcp): widen the SSE fallback trigger and harden its guards (salvage #53764)
Relocated onto the decomposed module layout and hardened:

- Trigger covers the rejection CLASS, not just literal 400: SSE-only
  servers' load balancers answer the chunked Streamable HTTP initialize
  POST with 400/405/406/411, and the mcp>=2.0 SDK surfaces many such
  rejections as an opaque -32603 'Server returned an error response'
  (error class per #104363 by @RohithPariki). Timeouts and 5xx never
  trigger the fallback: they are not transport mismatches.
- Reconnect exclusion via _ever_connected instead of _ready: run()
  clears _ready before re-entering the transport, so the original guard
  also fired on reconnects after a proven session.
- Successful fallback latches _sse_fallback so reconnects go straight
  to SSE, and logs a warning suggesting the user pin transport: sse.
- Both transports failing raises a ConnectionError naming both errors
  and suggesting transport: sse / checking the URL.
- No fallback with strict_redirect_headers (SSE cannot enforce that
  boundary) or when transport is explicitly configured.
- Tests trimmed to 3 invariant contracts (proven red on base): fallback
  connects + latches; no fallback on reconnect/timeout/5xx; both-fail
  error is actionable.

The extracted SSE path reuses _sse_transport/_serve_transport from main,
preserving the bounded handshake timeout and reconnect-retry semantics.

Fixes #53676
2026-09-12 21:05:29 -07:00
Teknium
0d8a1575c5 refactor(mcp): keep the passive status RPC, drop the SDK contract and reason codes
mcp.servers.status now rides the shared _mcp_rpc decorator (profile scope, 4064,
5024 with the real message) instead of a hand-rolled try/finally with a blanket
except. Drop the _MCPConnectErrorText str subclass and reason taxonomy: the
existing status/error fields already carry the state, and a whitelist on the RPC
keeps error text out of the wire. The Desktop connections.health contribution
contract is held back until its consumer plugin is public. Tests trimmed to the
scope invariants (per-profile runtime visibility, scoped shutdown clears only its
own status, launch runtime never leaks into another profile).
2026-09-06 13:18:19 -07:00
Joey
a6699d60f4 feat(mcp): expose profile-scoped cached connection health 2026-09-06 13:18:19 -07:00
Teknium
f4d4831e70 simplify(compat): tools/mcp_tool facade — drop 13 re-export blocks (127 names) + shutil re-import; siblings read sibling-defined names directly (_core kept for facade state) 2026-09-03 13:28:47 -07:00
Teknium
e83816a4d1 review-fix(comments): restore lost #NNNN rationale comments across non-test source (mechanical sweep, condensed, code unchanged)
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.
2026-09-03 09:44:26 -07:00
Teknium
35b3888fc5 refactor(tools): MCP _dispatch absorbs _invoke_with_recovery; oauth 401 recovery flattened; small predicate folds 2026-09-03 01:37:03 -07:00
Teknium
bccfd1de26 refactor(tools): MCP handlers inline single-use render helpers, drop banners; registration foreign-owner log inlined; body blank squeeze 2026-09-03 01:31:18 -07:00
Teknium
58a993a54d refactor(tools): MCP group L docstring/comment compaction, >118-col fixes 2026-09-03 01:30:13 -07:00
Teknium
9458f4c27a refactor(tools): MCP group L docstring rewrap 2026-09-03 01:20:43 -07:00
Teknium
760ac0b609 refactor(tools): MCP handlers/errors/transport/config/health/registration/oauth-manager compaction — shared _dispatch, folded utility factory, auth-type cache tuple 2026-09-03 01:18:04 -07:00
Teknium
f7a4ccc081 refactor(tools): flatten identity-header/loop-stop control flow, inline SSE client factory 2026-09-03 00:01:18 -07:00
Teknium
672cd01c7c refactor(tools): fold legacy HTTP transport into streamable path, tighten MCP classifier/sampling bodies 2026-09-02 23:35:14 -07:00
Teknium
6a7d04e89d refactor(tools): collapse defensive layers and compact prose in MCP transport/loop/sampling/errors 2026-09-02 22:53:26 -07:00
Teknium
87c033a3e9 refactor(tools): hug lone closers in MCP errors/transport (AST-neutral) 2026-09-02 22:22:55 -07:00
Teknium
1ad360b3aa refactor(tools): compact MCP transport/loop/sampling/errors helpers, defensive collapse 2026-09-02 22:16:12 -07:00
Teknium
607a5b711e refactor(mcp): errors — one _jsonrpc_matches for both code/marker classifiers, one _exc_children walk for connect-error rendering, docstrings compacted by hand (455 -> 384; differential fuzz 20k cases identical) 2026-09-02 17:05:28 -07:00
Teknium
1623697cb7 refactor(mcp): compact session-expired marker table 2026-09-02 16:34:23 -07:00
Teknium
304118797b refactor(mcp): join short multi-line statements across the transport/handlers subset (AST-identical) 2026-09-02 16:29:53 -07:00
Teknium
1f7beadae7 refactor(mcp): dedupe error classification ladders, optional-type import helper, cause-chain walker 2026-09-02 15:41:56 -07:00
Teknium
c1f8af1e86 refactor(tools/mcp): split mcp_tool.py into transport/lifecycle/schema/handlers/... sibling modules; compact watchdog and schema cache 2026-09-02 14:44:15 -07:00