Refactor MCP list methods via shared generic SDK pagination adapter#6997
Conversation
|
@copilot fix the failing lint ci check |
There was a problem hiding this comment.
Pull request overview
This PR refactors MCP cursor-based list operations to remove duplicated pagination glue across listTools, listResources, and listPrompts, while preserving response shapes and centralizing pagination/session validation in the existing listMCPItems flow.
Changes:
- Added a new generic adapter
listSDKItemsto bridge SDK list responses into the existinglistMCPItemspagination/marshalling pipeline. - Simplified
listTools,listResources, andlistPromptsto provide small typed adapters (list,toPage,buildResult) instead of repeating the full pagination closure pattern. - Added a unit test to verify
listSDKItemsshort-circuits on missing session before invoking the SDK list callback.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/pagination.go | Introduces listSDKItems as a thin generic adapter on top of listMCPItems. |
| internal/mcp/pagination_test.go | Adds coverage ensuring session precondition failure prevents invoking the provided SDK list function. |
| internal/mcp/connection_methods.go | Refactors listTools/listResources/listPrompts to use listSDKItems and remove duplicated pagination boilerplate. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
Fixed in the latest commit. The lint failure was |
listTools,listResources, andlistPromptshad the same cursor-pagination closure structure repeated with only SDK types changed. This PR removes that structural duplication while preserving existing list behavior and result shapes.Core refactor
listSDKItemsininternal/mcp/pagination.goto adapt SDK list responses intopaginatedPageand delegate tolistMCPItems.Connection method simplification
internal/mcp/connection_methods.go:listToolslistResourceslistPromptslist,toPage,buildResult) instead of duplicating the full closure pattern.Coverage update
TestListSDKItems_NilSessionininternal/mcp/pagination_test.goto verify session precondition failure short-circuits before invoking the SDK list callback.