Skip to content

refactor(mcp): extract shared root extraction helper and disable SSE in HTTP inspector#16922

Merged
pelikhan merged 2 commits intomainfrom
copilot/refactor-root-extraction-mcp
Feb 19, 2026
Merged

refactor(mcp): extract shared root extraction helper and disable SSE in HTTP inspector#16922
pelikhan merged 2 commits intomainfrom
copilot/refactor-root-extraction-mcp

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

connectStdioMCPServer and connectHTTPMCPServer contained identical ~20-line root URI extraction logic, and the HTTP transport was unnecessarily maintaining a persistent SSE connection despite only needing request-response communication.

Changes

  • Extracted extractRootsFromResources() — deduplicates the root URI inference loop (split on ://, dedup by scheme) shared by both connect functions
  • DisableStandaloneSSE: true on StreamableClientTransport in connectHTTPMCPServer() — the inspector only queries capabilities; no server-initiated messages are needed, so the persistent GET/SSE stream is wasteful
// Before: identical ~20-line loop duplicated in both connect functions
// After:
info.Roots = extractRootsFromResources(info.Resources)

// HTTP transport now skips the standalone SSE stream
transport := &mcp.StreamableClientTransport{
    Endpoint:             config.URL,
    DisableStandaloneSSE: true,
}

Note: the issue referred to the field as DisableListening — the actual exported field in go-sdk v1.3.0 is DisableStandaloneSSE, which carries the same semantics.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Refactor duplicate root extraction and add DisableListening to MCP inspector HTTP transport</issue_title>
<issue_description>## Objective

Apply two related improvements to the MCP inspector HTTP client in pkg/cli/mcp_inspect_mcp.go:

  1. Refactor duplicate root extraction logic into a shared helper function
  2. Set DisableListening: true on the StreamableClientTransport used in the HTTP inspector

Context

Discussion #16774 identified:

  • Duplicate code: connectStdioMCPServer() and connectHTTPMCPServer() contain identical ~20-line root URI extraction logic. Extracting it to a shared extractRootsFromResources() helper follows DRY principles.
  • Resource optimization: The inspector client only queries capabilities and never needs to receive server-initiated messages. Setting DisableListening: true on StreamableClientTransport reduces resource usage.

Steps

  1. Open pkg/cli/mcp_inspect_mcp.go
  2. Extract the duplicate root extraction logic from both connectStdioMCPServer() and connectHTTPMCPServer() into a new private function extractRootsFromResources(resources []*mcp.Resource) []*mcp.Root
  3. Replace both inline implementations with calls to the new helper
  4. In connectHTTPMCPServer(), add DisableListening: true to the StreamableClientTransport initialization
  5. Run make fmt && make build && make test-unit

Files to Modify

  • pkg/cli/mcp_inspect_mcp.go

Acceptance Criteria

  • extractRootsFromResources() helper function exists and is used by both connect functions
  • StreamableClientTransport in connectHTTPMCPServer() has DisableListening: true
  • No behavior change — the root extraction logic produces identical results
  • make build and make test-unit pass

Generated by Plan Command for issue #discussion #16774

  • expires on Feb 21, 2026, 9:47 PM UTC

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ndaloneSSE to HTTP transport

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicate root extraction and set DisableListening in HTTP transport refactor(mcp): extract shared root extraction helper and disable SSE in HTTP inspector Feb 19, 2026
Copilot AI requested a review from pelikhan February 19, 2026 22:03
@pelikhan pelikhan marked this pull request as ready for review February 19, 2026 22:04
Copilot AI review requested due to automatic review settings February 19, 2026 22:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the MCP inspector client to reduce duplicated root-inference code and avoid maintaining an unnecessary SSE stream for HTTP-based inspection.

Changes:

  • Extracted shared root URI inference into extractRootsFromResources() and used it from both stdio and HTTP connect paths.
  • Disabled standalone SSE (DisableStandaloneSSE: true) for the HTTP MCP inspector transport to reduce resource usage.
  • Reformatted portions of docs/public/editor/autocomplete-data.json by inlining many enum arrays.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/cli/mcp_inspect_mcp.go Deduplicates root extraction logic and disables standalone SSE for HTTP transport.
docs/public/editor/autocomplete-data.json Formatting-only changes to enum array layout (inlined).
Comments suppressed due to low confidence (1)

pkg/cli/mcp_inspect_mcp.go:318

  • The new extractRootsFromResources helper has non-trivial behavior (scheme parsing + de-duping). Since this repo already has unit tests for the MCP inspect CLI, it would be good to add a focused unit test for this helper to lock in ordering and de-duplication behavior and ensure it stays in sync with expectations.
// extractRootsFromResources infers root URIs from a list of resources by extracting
// the scheme portion (e.g. "file://") of each resource URI.
func extractRootsFromResources(resources []*mcp.Resource) []*mcp.Root {
	var roots []*mcp.Root
	for _, resource := range resources {
		if strings.Contains(resource.URI, "://") {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +315 to 340
func extractRootsFromResources(resources []*mcp.Resource) []*mcp.Root {
var roots []*mcp.Root
for _, resource := range resources {
if strings.Contains(resource.URI, "://") {
parts := strings.SplitN(resource.URI, "://", 2)
if len(parts) == 2 {
rootURI := parts[0] + "://"
// Check if we already have this root
found := false
for _, root := range info.Roots {
for _, root := range roots {
if root.URI == rootURI {
found = true
break
}
}
if !found {
info.Roots = append(info.Roots, &mcp.Root{
roots = append(roots, &mcp.Root{
URI: rootURI,
Name: parts[0],
})
}
}
}
}

return info, nil
return roots
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

extractRootsFromResources returns a nil slice when no roots are inferred (because roots is never initialized). Previously info.Roots stayed as a non-nil empty slice, so this subtly changes behavior (e.g., JSON marshaling could emit null instead of []). Consider initializing roots to an empty slice (or returning []*mcp.Root{} when none found) to preserve prior semantics.

This issue also appears on line 313 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines 219 to 246
@@ -238,192 +236,116 @@
"reaction": {
"type": "string|integer",
"desc": "AI reaction to add/remove on triggering item (one of: +1, -1, laugh, confused, heart, hooray, rocket, eyes, none).",
"enum": [
"+1",
"-1",
"laugh",
"confused",
"heart",
"hooray",
"rocket",
"eyes",
"none"
],
"enum": ["+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", "eyes", "none"],
"leaf": true
},
"status-comment": {
"type": "boolean",
"desc": "Whether to post status comments (started/completed) on the triggering item.",
"enum": [
true,
false
],
"enum": [true, false],
"leaf": true
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

This file has a large set of formatting-only changes (inlining many enum arrays) that aren't mentioned in the PR description and appear unrelated to the MCP inspector refactor. Consider reverting this change or explaining why it's needed here (or moving it to a dedicated formatting PR) to keep the diff focused.

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 4152d32 into main Feb 19, 2026
129 checks passed
@pelikhan pelikhan deleted the copilot/refactor-root-extraction-mcp branch February 19, 2026 22:09
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.

[plan] Refactor duplicate root extraction and add DisableListening to MCP inspector HTTP transport

3 participants