Commit 02547cb
Run handle_request in caller context, not as child task
The previous approach ran handle_request inside a child task within the
request-scoped task group. This caused coverage.py on Python 3.11 to
lose track of execution when returning from the task group back to the
caller — the root cause of the false coverage gaps on test assertions.
The fix is simpler: run handle_request directly in the async with body
(like the original code on main), with only run_stateless_server as a
child task. This preserves the request-scoped task group for preventing
task accumulation while keeping the caller's execution context intact.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent a7907d0 commit 02547cb
File tree
2 files changed
+9
-20
lines changed- src/mcp/server
- tests/server
2 files changed
+9
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 189 | | |
201 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
202 | 195 | | |
203 | 196 | | |
204 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | | - | |
| 266 | + | |
269 | 267 | | |
270 | 268 | | |
271 | | - | |
272 | | - | |
273 | | - | |
| 269 | + | |
274 | 270 | | |
275 | 271 | | |
276 | 272 | | |
| |||
0 commit comments