Commit 3778e00
Recognize JSON-RPC errors in AutoDetect HTTP transport (no SSE fallback)
AutoDetectingClientSessionTransport's job is to pick between StreamableHttp
(post-SEP-2243) and legacy SSE based on the server's response to the first
POST. The detection logic only checked the HTTP status code, so a draft server
returning `400 Bad Request` with a JSON-RPC error body (e.g. `-32004`
UnsupportedProtocolVersion or `-32600` from a legacy server that didn't
understand the draft `_meta` envelope) was being treated as ""this isn't
StreamableHttp"" — and the transport silently fell back to SSE, breaking
fallback negotiation against any HTTP/1.1 peer that follows the spec.
Detect a JSON-RPC error envelope in the 400 body, adopt StreamableHttp, then
re-throw the structured exception so McpClientImpl can dispatch on the error
code (retry with advertised version, surface capability gap, or fall back to
`initialize`). Use a deferred throw guarded by `catch when (ActiveTransport
is null)` to preserve transport ownership across the deferred error path.
Cross-SDK validation: against vanilla Go SDK `origin/main` HTTP everything
server, default `--http-mode autodetect` now successfully adopts
StreamableHttp, recognizes `-32004` with `data.supported`, retries with
`2025-11-25`, and lists 10 tools. Against Python `main`'s
`simple-streamablehttp-stateless`, the same flow recognizes the `-32600`
returned from the draft probe, adopts StreamableHttp, and falls back to
`initialize` with `2025-06-18` to complete the handshake.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 276bde4 commit 3778e00
2 files changed
Lines changed: 366 additions & 4 deletions
File tree
- src/ModelContextProtocol.Core/Client
- tests/ModelContextProtocol.AspNetCore.Tests
Lines changed: 61 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
76 | 92 | | |
77 | 93 | | |
78 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
79 | 98 | | |
80 | 99 | | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
84 | 103 | | |
85 | | - | |
| 104 | + | |
86 | 105 | | |
87 | | - | |
88 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
89 | 109 | | |
90 | 110 | | |
91 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
92 | 149 | | |
93 | 150 | | |
94 | 151 | | |
| |||
0 commit comments