Skip to content

Feature: Implement MCP cancellation mechanism - #24

Open
cioutn wants to merge 2 commits into
trpc-group:mainfrom
cioutn:fix-issue-18
Open

Feature: Implement MCP cancellation mechanism#24
cioutn wants to merge 2 commits into
trpc-group:mainfrom
cioutn:fix-issue-18

Conversation

@cioutn

@cioutn cioutn commented Jul 10, 2025

Copy link
Copy Markdown
  • Support client-initiated request cancellation notifications
  • Implement graceful interruption for long-running operations
  • Add automatic request cancellation on timeout
  • Create resource cleanup mechanism after cancellation
  • Handle pending requests on service shutdown

- Support client-initiated request cancellation notifications
- Implement graceful interruption for long-running operations
- Add automatic request cancellation on timeout
- Create resource cleanup mechanism after cancellation
- Handle pending requests on service shutdown
Comment thread handler.go Outdated
}

// Check if trying to cancel initialize request
if reqID, ok := requestId.(string); ok && reqID == "initialize" {

@bytethm bytethm Jul 28, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reqID == "initialize" 这条件应该判断不出是否是初始化请求?MCP 应该没规定初始化请求的 reqID 必须是 "initialize"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,谢谢老师指出错误,确实是这样。我更新了commit,在handleInitialize时对初始化请求进行标记,麻烦审阅,谢谢!

- Properly identify initialize requests by storing request ID in session data
- Replace incorrect string comparison with session-based tracking
- Add comprehensive test for initialize request cancellation protection
- Add test for automatic timeout cancellation functionality
- Ensure compliance with MCP specification: initialize requests MUST NOT be cancelled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants