You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Go SDK usage improvements from module review (#2967)
## Summary
Addresses the quick-win and best-practice findings from the Go Fan
module review of `modelcontextprotocol/go-sdk` (#2911).
## Changes
### 1. Extract pagination helper (`connection.go`)
Introduces a generic `paginateAll[T]()` helper that replaces three
identical cursor-loop pagination implementations in `listTools`,
`listResources`, and `listPrompts`. Eliminates ~45 lines of duplicated
boilerplate while preserving identical logging behavior.
### 2. Eliminate `resourceContents` intermediate type (`tool_result.go`)
The local `resourceContents` struct mirrored `sdk.ResourceContents`
field-for-field for JSON unmarshaling. Since the SDK type works directly
for this purpose, the local type is removed and `sdk.ResourceContents`
is used inline. The field-by-field copy in the resource content
conversion is also eliminated.
### 3. Explicit server options (`mcptest/server.go`)
Passes `&sdk.ServerOptions{}` instead of `nil` to `sdk.NewServer()` —
more defensive and documents intent, guarding against future SDK
changes.
### 4. Cache eviction for `filteredServerCache` (`routed.go`)
The routed-mode server cache previously grew unboundedly (one entry per
backend×session pair, never evicted). Now includes:
- TTL-based expiry matching the SDK `SessionTimeout` (30 minutes)
- Lazy eviction on each `getOrCreate()` call
- Extracted `routedSessionTimeout` variable shared between cache TTL and
SDK options
### 5. Transport ownership documentation (`http_transport.go`)
Adds lifecycle/ownership documentation to the `transportConnector` type,
clarifying that the SDK session owns the returned transport after
`Connect()`.
## Testing
- All Go unit and integration tests pass
- `make agent-finished` passes (format, build, lint, all tests)
Closes#2911
logConn.Printf("listResources: received page of %d resources (total so far: %d) from serverID=%s", len(result.Resources), len(allResources), c.serverID)
0 commit comments