Skip to content

[plan] Release MCP inspector sub-contexts promptly after each operation #18337

Description

@github-actions

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.goconnectStdioMCPServer 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 both connectStdioMCPServer and connectHTTPMCPServer
  • make test-unit passes
  • make agent-finish passes

Generated by Plan Command for issue #discussion #18080

  • expires on Feb 27, 2026, 12:38 PM UTC

Activity

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions