Title: fix: send notifications/cancelled on request timeout and cancellation by weiguangli-io · Pull Request #2518 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: send notifications/cancelled on request timeout and cancellation by weiguangli-io · Pull Request #2518 · modelcontextprotocol/python-sdk
X Title: fix: send notifications/cancelled on request timeout and cancellation by weiguangli-io · Pull Request #2518 · modelcontextprotocol/python-sdk
Description: Fixes #2507 Root Cause BaseSession.send_request() never emits a notifications/cancelled message when its in-flight await is interrupted: Timeout (anyio.fail_after): raises MCPError without notifying the server External cancellation (CancelledError): propagates without notifying the server The server never learns the request was abandoned, so server-side coroutines remain suspended holding resources (DB connections, cursors, locks) until the session ends. Fix Add a _send_cancelled_notification helper on BaseSession that does best-effort delivery (catches Exception to avoid masking the original error if the transport is already closed) In the TimeoutError handler, send the notification before raising MCPError Add an except anyio.get_cancelled_exc_class() handler with anyio.CancelScope(shield=True) to ensure the notification is sent even during cancellation teardown, then re-raise CancelledNotification is already part of both ClientNotification and ServerNotification unions, so this works for both client and server sessions.
Open Graph Description: Fixes #2507 Root Cause BaseSession.send_request() never emits a notifications/cancelled message when its in-flight await is interrupted: Timeout (anyio.fail_after): raises MCPError without notifyi...
X Description: Fixes #2507 Root Cause BaseSession.send_request() never emits a notifications/cancelled message when its in-flight await is interrupted: Timeout (anyio.fail_after): raises MCPError without notifyi...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2518
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:83da5aef-e2f2-0d6f-6c17-5c41d5fe2111 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D10A:2F9D41:9B9DBE:D015BA:6A5B4A86 |
| html-safe-nonce | f52772c3efcce8fa821be8c81ab83f659adb1d80d5c0e82ad2a5bc1b43fb3dea |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTBBOjJGOUQ0MTo5QjlEQkU6RDAxNUJBOjZBNUI0QTg2IiwidmlzaXRvcl9pZCI6Ijc1NjUxMDA1Mjg3NTE1NjEzNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f4709b5af3365edb368369eaa2ea282f74c84582acd2bb615bf27061b4c50ea3 |
| hovercard-subject-tag | pull_request:3600437709 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2518/files |
| twitter:image | https://avatars.githubusercontent.com/u/61958072?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/61958072?s=400&v=4 |
| og:image:alt | Fixes #2507 Root Cause BaseSession.send_request() never emits a notifications/cancelled message when its in-flight await is interrupted: Timeout (anyio.fail_after): raises MCPError without notifyi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width