-
Notifications
You must be signed in to change notification settings - Fork 296
Description
Objective
In pkg/cli/mcp_inspect_mcp.go, call cancel() immediately after each sequential MCP operation (ListTools, ListResources, ListPrompts) instead of deferring, to release context resources promptly.
Context
From discussion #18080 (go-sdk module review): The connectStdioMCPServer and connectHTTPMCPServer functions create three WithTimeout sub-contexts sequentially and cancel them via defer. Since only one operation runs at a time, cancelling immediately after each operation is complete (rather than at function return) releases timer resources sooner.
File to Modify
pkg/cli/mcp_inspect_mcp.go — connectStdioMCPServer and connectHTTPMCPServer functions
Change Required
// Before — deferred cancel held until function return
listToolsCtx, cancel := context.WithTimeout(ctx, MCPOperationTimeout)
defer cancel()
toolsResult, err := session.ListTools(listToolsCtx, ...)
// After — cancel immediately after operation completes
listToolsCtx, cancel := context.WithTimeout(ctx, MCPOperationTimeout)
toolsResult, err := session.ListTools(listToolsCtx, ...)
cancel()Apply the same pattern to the ListResources and ListPrompts context pairs.
Acceptance Criteria
- All three sequential sub-context
cancel()calls are invoked immediately after use (not deferred) in bothconnectStdioMCPServerandconnectHTTPMCPServer -
make test-unitpasses -
make agent-finishpasses
Generated by Plan Command for issue #discussion #18080
- expires on Feb 27, 2026, 12:38 PM UTC