Commit ea50838
committed
fix: improve streamable HTTP session reinitialization (#459)
Implements the MCP spec guidelines for streamable HTTP (re)initialization:
- Server MAY terminate session and MUST respond with HTTP 404 for terminated session IDs
- Client MUST start new session when receiving HTTP 404 for requests with session ID
Changes:
- Replace generic McpError with McpTransportException for transport-layer errors
- Only throw McpTransportSessionNotFoundException when session ID is present in request
(per spec: 404 with session ID means session terminated, without means general error)
- Enhance error messages with more context (status codes, response events)
- Use RuntimeException for non-transport specific SSE endpoint failures
- Ensure consistent error handling across HTTP client transports
- Improve error handling with standard Java exceptions.
Replace generic McpError with appropriate standard exceptions:
- Use IllegalArgumentException for invalid input parameters
- Use IllegalStateException for state-related issues
- Use RuntimeException wrapper for initialization failures
- Use McpError.builder() with proper error codes for protocol errors
Fixes #459
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>1 parent ed2c35e commit ea50838
File tree
25 files changed
+955
-90
lines changed- mcp-spring
- mcp-spring-webflux/src
- main/java/io/modelcontextprotocol/client/transport
- test/java/io/modelcontextprotocol
- client/transport
- mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server
- mcp-test/src/main/java/io/modelcontextprotocol/client
- mcp/src
- main/java/io/modelcontextprotocol
- client
- transport
- spec
- test/java/io/modelcontextprotocol
- client
- transport
- server
25 files changed
+955
-90
lines changedLines changed: 22 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| |||
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
224 | | - | |
225 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
226 | 234 | | |
227 | 235 | | |
228 | 236 | | |
| |||
318 | 326 | | |
319 | 327 | | |
320 | 328 | | |
321 | | - | |
| 329 | + | |
322 | 330 | | |
323 | 331 | | |
324 | | - | |
| 332 | + | |
325 | 333 | | |
326 | 334 | | |
327 | 335 | | |
| |||
362 | 370 | | |
363 | 371 | | |
364 | 372 | | |
365 | | - | |
| 373 | + | |
366 | 374 | | |
367 | 375 | | |
368 | | - | |
| 376 | + | |
369 | 377 | | |
370 | 378 | | |
371 | 379 | | |
| |||
374 | 382 | | |
375 | 383 | | |
376 | 384 | | |
377 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
378 | 390 | | |
379 | 391 | | |
380 | 392 | | |
| |||
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
406 | | - | |
| 418 | + | |
407 | 419 | | |
408 | 420 | | |
409 | 421 | | |
| |||
421 | 433 | | |
422 | 434 | | |
423 | 435 | | |
424 | | - | |
425 | | - | |
| 436 | + | |
426 | 437 | | |
427 | 438 | | |
428 | 439 | | |
| |||
449 | 460 | | |
450 | 461 | | |
451 | 462 | | |
452 | | - | |
| 463 | + | |
453 | 464 | | |
454 | 465 | | |
455 | 466 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
197 | 196 | | |
198 | 197 | | |
199 | 198 | | |
200 | | - | |
201 | | - | |
202 | 199 | | |
203 | 200 | | |
204 | 201 | | |
| |||
215 | 212 | | |
216 | 213 | | |
217 | 214 | | |
218 | | - | |
| 215 | + | |
219 | 216 | | |
220 | 217 | | |
221 | 218 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
0 commit comments