Skip to content

refactor(mcp): eliminate listTools/listResources/listPrompts wrapper methods#7574

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-list-methods
Jun 15, 2026
Merged

refactor(mcp): eliminate listTools/listResources/listPrompts wrapper methods#7574
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-list-methods

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

connection_methods.go contained three structurally-identical ~12-line methods (listTools, listResources, listPrompts) that were thin wrappers around the already-generic listSDKItems package-level function. Each was only ever called from one place in the callSDKMethod switch.

Changes

  • Removed listTools, listResources, and listPrompts methods (~36 lines)
  • Inlined their listSDKItems calls directly into the corresponding callSDKMethod switch cases — no new abstraction needed since listSDKItems is already a package-level generic
  • Added a doc comment on callSDKMethod explaining why the three list cases remain structurally similar but cannot be collapsed further (Go has no method-level type parameters)

Before:

case "tools/list":
    return c.listTools()  // delegates entirely to listSDKItems

// ...12 lines of boilerplate per method × 3
func (c *Connection) listTools() (*Response, error) {
    return listSDKItems(c, "tools", ...)
}

After:

case "tools/list":
    return listSDKItems(c, "tools",
        func(cursor string) (*sdk.ListToolsResult, error) { ... },
        func(result *sdk.ListToolsResult) paginatedPage[*sdk.Tool] { ... },
        func(items []*sdk.Tool) *sdk.ListToolsResult { ... },
    )

GitHub Advanced Security started work on behalf of lpcox June 15, 2026 13:56 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 13:57
…KMethod

Remove the three structurally-identical wrapper methods (listTools,
listResources, listPrompts) and call listSDKItems directly from the
callSDKMethod switch cases. listSDKItems is already a package-level
generic function, so no new abstraction is needed.

A doc comment on callSDKMethod explains why the three list cases share
the same shape but cannot be collapsed further (Go has no method-level
type parameters).

Closes #7560
Copilot AI changed the title [WIP] Refactor duplicate list methods in connection_methods.go refactor(mcp): eliminate listTools/listResources/listPrompts wrapper methods Jun 15, 2026
Copilot finished work on behalf of lpcox June 15, 2026 14:01
Copilot AI requested a review from lpcox June 15, 2026 14:01
GitHub Advanced Security started work on behalf of lpcox June 15, 2026 14:02 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 14:04
@lpcox lpcox marked this pull request as ready for review June 15, 2026 14:34
Copilot AI review requested due to automatic review settings June 15, 2026 14:34

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

This PR refactors MCP SDK method dispatch by removing three redundant Connection wrapper methods (listTools, listResources, listPrompts) and inlining their listSDKItems usage directly into callSDKMethod, while documenting why the three list cases can’t be further unified in Go.

Changes:

  • Removed the thin Connection methods listTools, listResources, and listPrompts.
  • Inlined the corresponding listSDKItems calls into the callSDKMethod switch cases.
  • Added a clarifying doc comment on callSDKMethod describing why further abstraction isn’t feasible (given Go’s generics constraints).
Show a summary per file
File Description
internal/mcp/connection_methods.go Inlines listSDKItems calls into callSDKMethod and removes redundant list wrapper methods, with added rationale comment.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@lpcox

lpcox commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

GitHub Advanced Security started work on behalf of lpcox June 15, 2026 15:31 View session
Copilot finished work on behalf of lpcox June 15, 2026 15:32
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 15:33
@lpcox lpcox merged commit b25001a into main Jun 15, 2026
27 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-list-methods branch June 15, 2026 16:42
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.

3 participants