Skip to content

Fix silent pagination truncation in gh aw mcp inspect, dedupe connect logic - #51193

Merged
pelikhan merged 9 commits into
mainfrom
copilot/go-fan-review-go-sdk
Aug 8, 2026
Merged

Fix silent pagination truncation in gh aw mcp inspect, dedupe connect logic#51193
pelikhan merged 9 commits into
mainfrom
copilot/go-fan-review-go-sdk

Conversation

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The go-fan review of modelcontextprotocol/go-sdk v1.7.0 flagged a correctness bug in gh aw mcp inspect: ListTools/ListResources were called once with no cursor handling, so MCP servers that paginate their tool/resource lists would be silently truncated in the inspector output. It also flagged ~70 duplicated lines between connectStdioMCPServer and connectHTTPMCPServer.

Pagination fix

  • Switched tools/resources/prompts listing in pkg/cli/mcp_inspect_mcp.go to the SDK's iterator-based pagination helpers (session.Tools, session.Resources, session.Prompts), which follow cursors automatically instead of requiring hand-rolled cursor loops (previously only ListPrompts had one).

De-duplication

  • Extracted a shared queryServerCapabilities(ctx, config, session, verbose) *parser.MCPServerInfo helper, called by both connectStdioMCPServer and connectHTTPMCPServer after each establishes its transport-specific session.
  • Each listing operation runs in its own closure with a deferred context cancel, so timeouts can't leak if the loop body changes later.

Example

// Before: single-shot call, silently truncated on paginated servers
toolsResult, err := session.ListTools(ctx, &mcp.ListToolsParams{})
info.Tools = append(info.Tools, toolsResult.Tools...)

// After: iterator follows cursors automatically
for tool, err := range session.Tools(ctx, &mcp.ListToolsParams{}) {
    if err != nil { break }
    info.Tools = append(info.Tools, tool)
}

Also confirmed no test or fixture asserts on absence of readOnlyHint/idempotentHint fields, so the v1.7.0 wire-format change (bare bool instead of omitempty) requires no follow-up here. Added TestQueryServerCapabilities_Pagination, which spins up an in-memory MCP server/client with a small page size to verify all items are retrieved across multiple pages.


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.98 AIC · ⊞ 6.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 39.7 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.66 AIC · ⌖ 5.2 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.4 AIC · ⌖ 6.83 AIC · ⊞ 6.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.94 AIC · ⌖ 5.23 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 7, 2026 21:36
…helpers

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Review Go Module modelcontextprotocol/go-sdk Fix silent pagination truncation in gh aw mcp inspect, dedupe connect logic Aug 7, 2026
Copilot AI requested a review from pelikhan August 7, 2026 21:38
@pelikhan
pelikhan marked this pull request as ready for review August 7, 2026 21:56
Copilot AI balanced review requested due to automatic review settings August 7, 2026 21:56
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Matt Pocock Skills Reviewer. Review the logs for details.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Test Quality Sentinel. Review the logs for details.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Design Decision Gate 🏗️. Review the logs for details.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes MCP inspector pagination truncation and consolidates capability querying.

Changes:

  • Uses SDK pagination iterators for tools, resources, and prompts.
  • Shares capability-query logic across stdio and HTTP transports.
  • Adds an in-memory pagination regression test.
Show a summary per file
File Description
pkg/cli/mcp_inspect_mcp.go Adds paginated shared capability querying.
pkg/cli/mcp_inspect_mcp_test.go Verifies complete multi-page retrieval.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 100/100 — Excellent (with violation)

Analyzed 1 test(s): 1 design, 0 implementation, 1 violation.

⚠️ Hard violation detected: new test file pkg/cli/mcp_inspect_mcp_test.go is missing the mandatory (go/redacted):build tag on line 1. All *_test.go files in this package require (go/redacted):build !integration (or (go/redacted):build integration) as their very first line.

📊 Metrics (1 test)
Metric Value
Analyzed 1 (Go: 1, JS: 0)
✅ Design 1 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 1 (100%)
Duplicate clusters 0
Inflation No (73 test lines / 56 prod lines = 1.30×)
🚨 Violations 1 (missing build tag)
Test File Classification Issues
TestQueryServerCapabilities_Pagination pkg/cli/mcp_inspect_mcp_test.go:19 design_test / behavioral_contract / high_value Missing (go/redacted):build tag
⚠️ Flagged Tests (1)

TestQueryServerCapabilities_Pagination (pkg/cli/mcp_inspect_mcp_test.go:1) — Missing mandatory build tag. The file starts with package cli on line 1 instead of the required (go/redacted):build !integration (or (go/redacted):build integration) tag. Every newly added *_test.go in this package has this tag. Fix: add (go/redacted):build !integration as line 1 followed by a blank line before package cli.

The test itself is high quality: it spins up a real in-memory MCP server/client pair with PageSize: 1 and 3 items per capability type, then calls queryServerCapabilities and asserts all 3 tools, resources, and prompts are retrieved. This directly verifies the pagination-completeness invariant fixed in this PR. No forbidden mocks; uses the SDK's own in-memory transport. The error/edge case is the core scenario.

Verdict

Failed. Build-tag violation on newly added test file. Fix: add (go/redacted):build !integration as the first line of pkg/cli/mcp_inspect_mcp_test.go. The underlying test logic is excellent (100/100).

References: PR #51193

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 41.5 AIC · ⊞ 7.7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Test Quality Sentinel: 100/100 (with violation). Missing (go/redacted):build build tag on newly added pkg/cli/mcp_inspect_mcp_test.go. All test files in this package require (go/redacted):build !integration (or (go/redacted):build integration) as line 1. Review flagged tests in the comment above.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — the pagination bug fix and deduplication are solid; flagging a few targeted gaps.

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Root cause properly addressed: switching to SDK iterators is the right fix, not cursor-loop patching
  • ✅ Shared queryServerCapabilities helper is a clean deep-module move — simpler interface, same behaviour
  • ✅ IIFE closures for each iterator section cleanly scope the per-operation context.WithTimeout and cancel
  • TestQueryServerCapabilities_Pagination with PageSize:1 is a strong regression guard for the core bug

Issues Found

  1. Partial results not surfaced to the user (mcp_inspect_mcp.go ~line 284) — iterator errors only print a warning when verbose is true; otherwise the caller receives a silently truncated list with no indication it is incomplete. This re-introduces a weaker form of the original truncation bug on transient errors.

  2. info.Roots unasserted in the test (mcp_inspect_mcp_test.go line 70) — extractRootsFromResources runs but is never checked, so a future breakage in that function would go undetected by this test.

  3. No error-path test case — the test only validates the happy path. A sub-test that simulates a mid-stream error would lock in the break-on-first-error behaviour.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 32.1 AIC · ⊞ 7.1K
Comment /matt to run again

if len(info.Resources) != itemCount {
t.Errorf("expected %d resources, got %d", itemCount, len(info.Resources))
}
if len(info.Prompts) != itemCount {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] info.Roots is not asserted — extractRootsFromResources runs but its output goes unverified, leaving a silent gap in regression coverage.

💡 Suggested addition
if len(info.Roots) == 0 {
    t.Errorf("expected roots to be inferred from resources, got none")
}

Adding even a basic non-empty check here would catch a future breakage in extractRootsFromResources.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the //go:build !integration tag and now assert info.Roots in pkg/cli/mcp_inspect_mcp_test.go in fb3eeac.


client := mcp.NewClient(&mcp.Implementation{Name: "test-client", Version: "1.0.0"}, nil)
serverTransport, clientTransport := mcp.NewInMemoryTransports()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The test does not cover error handling — there is no case where the server returns an error mid-iteration to verify that verbose-mode warnings fire and iteration stops cleanly.

💡 Why this matters

The new iterator loop uses break on first error; a test that injects an error would lock in that behaviour and prevent a silent regression if the error-handling path is changed.

Consider adding a second sub-test with a server that surfaces an error partway through listing, and assert that info.Tools contains only the items received before the error.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an error-path regression in fb3eeac that forces tools/list to fail on the second page and asserts the first-page tool is preserved while info.Error is populated.

Comment thread pkg/cli/mcp_inspect_mcp.go Outdated
if err != nil {
if verbose {
console.PrintWarningMessage(fmt.Sprintf("Failed to list resources: %v", err))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnosing-bugs] The iterator breaks on the first error, silently dropping any items a server may have already buffered after the failing page. This means a transient mid-stream error produces a partial (and potentially misleading) capability list with no indication in the returned *MCPServerInfo that it is incomplete.

💡 Options to consider
  1. Set info.Connected = false (or add an Error field to MCPServerInfo) when any iteration is cut short, so callers know the result is partial.
  2. Return the partial list but surface a structured warning in the output rendered by the caller, not just a console PrintWarningMessage that is suppressed when verbose is false.

The current code only warns when verbose is true, so a real-world silent truncation due to a transient network error would be invisible to the user.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fb3eeac now records iterator failures on info.Error, and displayServerCapabilities always emits a partial-results warning so the truncation is visible even when --verbose is off.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (129 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/51193-mcp-inspect-sdk-pagination-iterators.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff
  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-51193: Use SDK Iterator-Based Pagination for MCP Inspect Capability Listing

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 51193-mcp-inspect-sdk-pagination-iterators.md for PR #51193).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · sonnet46 · 52.8 AIC · ⊞ 8.8K ·
Comment /review to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, address the remaining review feedback, and run the pr-finisher skill before handing back to maintainers.

Review items to address (newest first):

  • Test Quality Sentinel report Missing mandatory (go/redacted):build !integration tag at the top of pkg/cli/mcp_inspect_mcp_test.go.
  • Matt Pocock Skills review Surface partial-results iterator errors to users, assert info.Roots in the pagination regression test, and consider an error-path regression test.
  • Design Decision Gate Review and complete the drafted ADR, then link it in the PR body.

Branch refresh was requested.

Run: https://github.com/github/gh-aw/actions/runs/31222749409

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.98 AIC · ⊞ 6.1K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please fix the missing (go/redacted):build !integration tag on pkg/cli/mcp_inspect_mcp_test.go, review the remaining changes-requested feedback, refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

Run: https://github.com/github/gh-aw/actions/runs/31225438989

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 39.7 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — the pagination bug fix and deduplication are solid; flagging a few targeted gaps....

Addressed in fb3eeac: partial iterator errors are surfaced to users, info.Roots is asserted, and there is now a partial-results regression test.

@copilot Quick triage nudge for this PR.

Please fix the missing (go/redacted):build !integration tag on pkg/cli/mcp_inspect_mcp_test.go, review the remaining changes-requested feedback, refresh t...

Addressed in fb3eeac. The missing build tag is fixed, the remaining review feedback is covered, and the branch is already up to date with origin/main.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, ensure the ADR at docs/adr/51193-mcp-inspect-sdk-pagination-iterators.md is linked in the PR body, and run the pr-finisher skill before handing back to maintainers.

Review items to address (newest first):

Run: https://github.com/github/gh-aw/actions/runs/31230238662

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.66 AIC · ⌖ 5.2 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Triage

Category: bug | Risk: high | Score: 50/100

Component Score
Impact 30/50
Urgency 15/30
Quality 5/20

Recommended action: defer

CHANGES_REQUESTED from automated reviewer and PR is currently in a blocked mergeable state. Needs author follow-up to address requested changes before it's review-ready again.

Generated by 🔧 PR Triage Agent · auto · 39.7 AIC · ⌖ 2.79 AIC · ⊞ 8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, ensure the remaining ADR and blocking review requirements are fully cleared, and run the pr-finisher skill before handing back to maintainers.

Open items (newest first):

  • blocking review from @github-actions: verify the remaining CHANGES_REQUESTED state is cleared or superseded before handoff
  • likely follow-up from earlier review context: ensure the drafted ADR is complete and linked in the PR body if still required

Branch refresh was requested.

Run: https://github.com/github/gh-aw/actions/runs/31233305116

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.4 AIC · ⌖ 6.83 AIC · ⊞ 6.1K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage nudge for this PR.

Please refresh the branch if GitHub can update it cleanly, ensure the ADR is linked in the PR body if still required, verify any remaining blocking review state is cleared or superseded, and run the pr-finisher skill before handing back to maintainers.

Open items (newest first):

  • blocking review from @github-actions: confirm the stale CHANGES_REQUESTED state is dismissed or otherwise no longer blocking after fb3eeac697
  • likely follow-up from earlier ADR gate: ensure docs/adr/51193-mcp-inspect-sdk-pagination-iterators.md is complete and linked in the PR body if the gate still requires it

Run: https://github.com/github/gh-aw/actions/runs/31235166066

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.94 AIC · ⌖ 5.23 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit 23fb691 into main Aug 8, 2026
4 of 5 checks passed
@pelikhan
pelikhan deleted the copilot/go-fan-review-go-sdk branch August 8, 2026 02:45
Copilot stopped work on behalf of gh-aw-bot due to an error August 8, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go-fan] Go Module Review: modelcontextprotocol/go-sdk

4 participants