πΉ Go Fan Report: modelcontextprotocol/go-sdk
Module Overview
github.com/modelcontextprotocol/go-sdk is the official Go SDK for MCP β the foundational protocol the entire gateway is built around. It provides client/server primitives, typed request/response types, session management, transport implementations (stdio, streamable HTTP, SSE), and testing helpers.
This is the most strategically critical direct dependency: every MCP interaction flows through it.
Current Usage in gh-aw
- Files: ~40 files (production + test)
- Import alias:
sdk "github.com/modelcontextprotocol/go-sdk/mcp"
| API |
Usage |
sdk.NewClient / sdk.ClientSession |
Backend MCP connections (stdio + HTTP) |
sdk.CommandTransport |
stdio backend launch |
sdk.StreamableClientTransport |
Streamable HTTP (2025-03-26 spec) |
sdk.SSEClientTransport |
SSE transport (2024-11-05 spec, deprecated path) |
sdk.NewInMemoryTransports |
In-process testing |
sdk.NewServer + sdk.NewStreamableHTTPHandler |
Gateway frontend MCP server |
sdk.ErrSessionMissing |
Typed sentinel for session-not-found (v1.5.0+) |
sdk.ClientOptions.KeepAlive |
Periodic pings to keep HTTP backend sessions alive |
| All content types |
TextContent, ImageContent, AudioContent, EmbeddedResource |
Key Patterns
- Triple transport fallback: streamable HTTP β SSE β plain JSON-RPC (custom)
- Schema bypass:
server.AddTool() (method) bypasses sdk.AddTool() validation for non-standard backend schemas
streamableMaxRetries = -1 sentinel: disables SDK-level SSE reconnect retries; guarded by TestMaxRetriesSentinelCanary
- Session reconnection: at-most-once reconnect with mutex serialization for both SDK and plain JSON-RPC paths
Improvement Opportunities
π Quick Wins
1. Context propagation gap in SDK session calls β HIGH
The tool timeout (context.WithTimeout) applied in callBackendTool is never propagated to SDK session method calls. callSDKMethod uses c.ctx (the long-lived connection context) for all session methods:
// connection_methods.go β ignores the per-request context
return c.getSDKSession().CallTool(c.ctx, &sdk.CallToolParams{...})
But SendRequestWithServerID accepts a ctx that is only forwarded for plain JSON-RPC transport:
if c.httpTransportType == HTTPTransportPlainJSON {
result, err = c.sendHTTPRequest(ctx, method, params) // ctx used β
} else {
result, err = c.callSDKMethodWithReconnect(method, params) // ctx dropped β
}
Fix: Thread the request context through callSDKMethodWithReconnect β callSDKMethod β all SDK session calls (CallTool, ListTools, ListResources, etc.). This ensures toolTimeout actually cancels backend SDK calls.
2. Prompt passthrough gap β MEDIUM
callSDKMethod handles prompts/list and prompts/get to fetch prompts from backends, but the gateway's sdk.Server never registers prompts with server.AddPrompt(). Frontend clients cannot discover backend prompts via standard MCP prompts/list. Tools and resources are exposed; prompts are not.
β¨ Feature Opportunities
3. v1.7.0 pre-release monitoring
v1.7.0-pre.1 is available while the project uses v1.6.1. The existing version-pinned comments (// Verified for go-sdk v1.6.1) need re-auditing on each SDK bump. Plan upgrade when v1.7.0 is stable.
4. Client capability declaration
All three client.Connect(ctx, transport, nil) calls pass nil for capabilities. Declaring capabilities can enable enhanced backend behaviors per the MCP spec.
π Best Practice Alignment
5. Missing canary for server.AddTool bypass
There's a TestMaxRetriesSentinelCanary protecting the streamableMaxRetries sentinel. But there's no equivalent test verifying that server.AddTool (method) skips argument validation while sdk.AddTool (function) enforces it β behavior the gateway depends on. A canary test would guard against silent breakage on SDK upgrades.
6. Schema normalization completeness
NormalizeInputSchema handles nil schemas, missing type, and missing properties, but the gateway still bypasses sdk.AddTool entirely. If normalization were extended to handle all edge cases (e.g., $schema annotations from draft-07 backends), the bypass could be narrowed, reducing version-pinning risk.
Module Summary
References
Recommendations (Priority Order)
- [HIGH] Fix context propagation through
callSDKMethodWithReconnect β callSDKMethod for tool timeout enforcement
- [MEDIUM] Add
server.AddPrompt() registration for backend prompts to complete MCP capability parity
- [MEDIUM] Add a canary test for
server.AddTool vs sdk.AddTool behavior difference
- [LOW] Monitor v1.7.0 changelog; audit version-pinned comments on upgrade
- [LOW] Declare client capabilities on backend
Connect calls
Next Steps
Generated by Go Fan Β· Run Β§28156334602
Generated by Go Fan Β· 1.7K AIC Β· β 34.5K Β· β·
πΉ Go Fan Report: modelcontextprotocol/go-sdk
Module Overview
github.com/modelcontextprotocol/go-sdkis the official Go SDK for MCP β the foundational protocol the entire gateway is built around. It provides client/server primitives, typed request/response types, session management, transport implementations (stdio, streamable HTTP, SSE), and testing helpers.This is the most strategically critical direct dependency: every MCP interaction flows through it.
Current Usage in gh-aw
sdk "github.com/modelcontextprotocol/go-sdk/mcp"sdk.NewClient/sdk.ClientSessionsdk.CommandTransportsdk.StreamableClientTransportsdk.SSEClientTransportsdk.NewInMemoryTransportssdk.NewServer+sdk.NewStreamableHTTPHandlersdk.ErrSessionMissingsdk.ClientOptions.KeepAliveTextContent,ImageContent,AudioContent,EmbeddedResourceKey Patterns
server.AddTool()(method) bypassessdk.AddTool()validation for non-standard backend schemasstreamableMaxRetries = -1sentinel: disables SDK-level SSE reconnect retries; guarded byTestMaxRetriesSentinelCanaryImprovement Opportunities
π Quick Wins
1. Context propagation gap in SDK session calls β HIGH
The tool timeout (
context.WithTimeout) applied incallBackendToolis never propagated to SDK session method calls.callSDKMethodusesc.ctx(the long-lived connection context) for all session methods:But
SendRequestWithServerIDaccepts actxthat is only forwarded for plain JSON-RPC transport:Fix: Thread the request context through
callSDKMethodWithReconnectβcallSDKMethodβ all SDK session calls (CallTool,ListTools,ListResources, etc.). This ensurestoolTimeoutactually cancels backend SDK calls.2. Prompt passthrough gap β MEDIUM
callSDKMethodhandlesprompts/listandprompts/getto fetch prompts from backends, but the gateway'ssdk.Servernever registers prompts withserver.AddPrompt(). Frontend clients cannot discover backend prompts via standard MCPprompts/list. Tools and resources are exposed; prompts are not.β¨ Feature Opportunities
3. v1.7.0 pre-release monitoring
v1.7.0-pre.1is available while the project usesv1.6.1. The existing version-pinned comments (// Verified for go-sdk v1.6.1) need re-auditing on each SDK bump. Plan upgrade when v1.7.0 is stable.4. Client capability declaration
All three
client.Connect(ctx, transport, nil)calls passnilfor capabilities. Declaring capabilities can enable enhanced backend behaviors per the MCP spec.π Best Practice Alignment
5. Missing canary for
server.AddToolbypassThere's a
TestMaxRetriesSentinelCanaryprotecting thestreamableMaxRetriessentinel. But there's no equivalent test verifying thatserver.AddTool(method) skips argument validation whilesdk.AddTool(function) enforces it β behavior the gateway depends on. A canary test would guard against silent breakage on SDK upgrades.6. Schema normalization completeness
NormalizeInputSchemahandles nil schemas, missingtype, and missingproperties, but the gateway still bypassessdk.AddToolentirely. If normalization were extended to handle all edge cases (e.g.,$schemaannotations from draft-07 backends), the bypass could be narrowed, reducing version-pinning risk.Module Summary
github.com/modelcontextprotocol/go-sdkv1.6.1References
Recommendations (Priority Order)
callSDKMethodWithReconnectβcallSDKMethodfor tool timeout enforcementserver.AddPrompt()registration for backend prompts to complete MCP capability parityserver.AddToolvssdk.AddToolbehavior differenceConnectcallsNext Steps
Generated by Go Fan Β· Run Β§28156334602