Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Implement effective request cancellation on notifications/cancelled#26

Open
salignatmoandal wants to merge 1 commit intolightpanda-io:mainfrom
salignatmoandal:feat/notifications/cancelled
Open

Implement effective request cancellation on notifications/cancelled#26
salignatmoandal wants to merge 1 commit intolightpanda-io:mainfrom
salignatmoandal:feat/notifications/cancelled

Conversation

@salignatmoandal
Copy link

Hi everyone,
I came across a TODO in the codebase and went ahead and implemented it — hope that helps!###

Summary

This PR implements proper request cancellation in the MCP server. When a notifications/cancelled message is received, the server now effectively cancels the corresponding in-flight request using Go's context cancellation mechanism.

Details

  • Added a cancels map and mutex to MCPServer to track cancellable contexts by request ID.
  • When handling a ToolsCallRequest, a cancellable context is created and stored.
  • When a notifications/cancelled message is received, the server looks up and calls the corresponding cancel function, stopping the ongoing task.
  • The cancel function is cleaned up after the request completes or is cancelled.

Why

Previously, cancellation requests were only logged and had no effect. This change allows clients to actually interrupt long-running or unwanted operations, improving resource usage and responsiveness.


N/A

Let me know if you want a test scenario or further improvements!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant