Commit d64d191
committed
Fix StreamableHTTP transport API for backwards compatibility and cleaner header handling
This commit addresses three issues identified in PR review:
1. **Restore RequestContext fields for backwards compatibility**
- Re-add `headers` and `sse_read_timeout` fields as optional with None defaults
- Mark them as deprecated in docstring since they're no longer used internally
- Prevents breaking changes for any code accessing these fields
2. **Add runtime deprecation warnings for StreamableHTTPTransport constructor**
- Use sentinel value pattern to detect when deprecated parameters are passed
- Issue DeprecationWarning at runtime when headers, timeout, sse_read_timeout, or auth are provided
- Complements existing @deprecated decorator for type checkers with actual runtime warnings
- Improve deprecation message clarity
3. **Simplify header handling by removing redundant client parameter**
- Remove `client` parameter from `_prepare_headers()` method
- Stop extracting and re-passing client.headers since httpx automatically merges them
- Only build MCP-specific headers (Accept, Content-Type, session headers)
- httpx merges these with client.headers automatically, with our headers taking precedence
- Reduces code complexity and eliminates unnecessary header extraction
The header handling change leverages httpx's built-in header merging behavior,
similar to how headers were handled before the refactoring but without the
redundant extraction-and-repass pattern.1 parent 862c22f commit d64d191
File tree
3 files changed
+92
-39
lines changed- src/mcp/client
- tests
- client
3 files changed
+92
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
84 | | - | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
93 | | - | |
94 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
95 | 102 | | |
96 | 103 | | |
97 | 104 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
112 | 118 | | |
113 | 119 | | |
114 | 120 | | |
| |||
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
122 | | - | |
123 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
124 | 147 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 148 | | |
132 | 149 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
142 | 162 | | |
143 | 163 | | |
144 | 164 | | |
| |||
242 | 262 | | |
243 | 263 | | |
244 | 264 | | |
245 | | - | |
| 265 | + | |
246 | 266 | | |
247 | 267 | | |
248 | 268 | | |
| |||
251 | 271 | | |
252 | 272 | | |
253 | 273 | | |
254 | | - | |
255 | 274 | | |
256 | 275 | | |
257 | 276 | | |
| |||
284 | 303 | | |
285 | 304 | | |
286 | 305 | | |
287 | | - | |
| 306 | + | |
288 | 307 | | |
289 | 308 | | |
290 | 309 | | |
| |||
300 | 319 | | |
301 | 320 | | |
302 | 321 | | |
303 | | - | |
304 | 322 | | |
305 | 323 | | |
306 | 324 | | |
| |||
318 | 336 | | |
319 | 337 | | |
320 | 338 | | |
321 | | - | |
| 339 | + | |
322 | 340 | | |
323 | 341 | | |
324 | 342 | | |
| |||
436 | 454 | | |
437 | 455 | | |
438 | 456 | | |
439 | | - | |
| 457 | + | |
440 | 458 | | |
441 | 459 | | |
442 | 460 | | |
| |||
450 | 468 | | |
451 | 469 | | |
452 | 470 | | |
453 | | - | |
454 | 471 | | |
455 | 472 | | |
456 | 473 | | |
| |||
538 | 555 | | |
539 | 556 | | |
540 | 557 | | |
541 | | - | |
542 | 558 | | |
543 | 559 | | |
544 | 560 | | |
545 | 561 | | |
546 | | - | |
547 | 562 | | |
548 | 563 | | |
549 | 564 | | |
| |||
570 | 585 | | |
571 | 586 | | |
572 | 587 | | |
573 | | - | |
| 588 | + | |
574 | 589 | | |
575 | 590 | | |
576 | 591 | | |
| |||
678 | 693 | | |
679 | 694 | | |
680 | 695 | | |
681 | | - | |
682 | 696 | | |
| 697 | + | |
683 | 698 | | |
684 | 699 | | |
685 | 700 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
2356 | 2361 | | |
2357 | 2362 | | |
2358 | 2363 | | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
0 commit comments