Release MCP inspector sub-contexts promptly after each operation#18343
Release MCP inspector sub-contexts promptly after each operation#18343
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR ensures MCP inspector operation timeout sub-contexts are cancelled immediately after each sequential operation, releasing timer resources promptly instead of holding them until the function returns.
Changes:
- Replace
defer cancel()with an immediatecancel()afterListToolsin both stdio and HTTP connection flows. - Replace
defer cancel()with an immediatecancel()afterListResourcesin both stdio and HTTP connection flows. - Reformat a smoke-test JSON file used for PR push validation.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/cli/mcp_inspect_mcp.go |
Cancels per-operation WithTimeout contexts immediately after ListTools/ListResources complete to release timers sooner. |
.github/smoke-test-22395402042.json |
Formatting-only change to the smoke-test JSON file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // List tools | ||
| listToolsCtx, cancel := context.WithTimeout(ctx, MCPOperationTimeout) | ||
| defer cancel() | ||
|
|
||
| toolsResult, err := session.ListTools(listToolsCtx, &mcp.ListToolsParams{}) | ||
| cancel() |
There was a problem hiding this comment.
The PR description/acceptance criteria mention also applying this to ListPrompts, but this repo/file does not contain any ListPrompts call (only ListTools/ListResources). Please update the PR description (or the referenced acceptance criteria) to match the actual operations being changed, to avoid confusion for future readers.
|
Smoke test summary
|
connectStdioMCPServerandconnectHTTPMCPServercreatedWithTimeoutsub-contexts for each sequential MCP operation (ListTools,ListResources) but cancelled them viadefer, holding timer resources until function return rather than releasing them immediately after each operation completed.Changes
connectStdioMCPServerandconnectHTTPMCPServer: replaceddefer cancel()with an immediatecancel()after each sequential MCP operationThe
connectCtxused forclient.Connect()retainsdefer cancel()since it isn't sequential and doesn't benefit from early release.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.