[go-fan] Go Module Review: modelcontextprotocol/go-sdk #30108
Replies: 1 comment 1 reply
-
|
/plan |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🐹 Go Fan Report: modelcontextprotocol/go-sdk
Module Overview
github.com/modelcontextprotocol/go-sdkis the official Go implementation of the Model Context Protocol (MCP) — the standard for how AI agents interact with tools, resources, and prompts. This is one of the most strategically important dependencies in gh-aw: it is the backbone of the entiremcp-servercommand and themcp-inspectfunctionality.Current version: v1.5.0 | Repository | Docs
Current Usage in gh-aw
pkg/cli/mcp(main) andjsonrpc(error codes)Key APIs Used:
mcp.NewServer()+mcp.AddTool[In,Out]()mcp.StdioTransport+mcp.StreamableHTTPHandlermcp.ToolAnnotationsmcp.Middleware+server.AddReceivingMiddleware()mcp.NewClient()+mcp.CommandTransport+mcp.StreamableClientTransportjsonrpc.CodeInternalError/CodeInvalidParamsThe codebase already uses several advanced features well: generic typed tool registration with struct binding, middleware pipelines, dual transport support, and
DisableStandaloneSSEon the inspector client. The comment noting schema caching since v1.3.0 shows active tracking of SDK evolution.Research Findings
Recent Updates (v1.3.0 → v1.5.0)
mcp_server.go:43)CreateMessageWithTools, improved pagination,URLElicitationCapabilitiesBest Practices from Maintainers
AddTool[In, Out]whereOutis a typed struct populatesstructuredContent— AI clients parse this more reliably than raw JSON textreq.Params.GetProgressToken()and callreq.Session.NotifyProgress()for operations > 1 secondInMemoryTransportfor Tests: The SDK providesmcp.NewInMemoryTransports()specifically to avoid spawning subprocesses in testsImprovement Opportunities
🏃 Quick Wins
1. Use
InMemoryTransportfor Unit TestsAll integration tests (
//go:build integration) spawn actual binary subprocesses, requiring a compiled binary. The SDK provides in-process transport:Converting the core tool tests (e.g.,
TestMCPServer_ListTools) to unit tests would remove the binary dependency and run 10-100x faster.2. Populate Structured Output in Tool Handlers
All 10 tool handlers return
nilas the second (structured) return value:For tools like
statusandcompilethat already return JSON text, the second value should be the typed Go struct — AI clients parsestructuredContentmore reliably without re-parsing embedded JSON.✨ Feature Opportunities
3. Progress Notifications for Long-Running Tools
logs,audit, andaudit-diffcan execute for 30+ seconds. MCP clients (Claude, Copilot) display progress indicators when the server callsNotifyProgress. Pattern:This is a low-effort change with high UX impact for the tools users care about most.
4. Event Store for HTTP Sessions
The HTTP server configures
SessionTimeout: 2 * time.Hourbut noEventStore. Addingmcp.NewMemoryEventStore()enables reconnecting clients to replay missed messages without re-running tools.5. Elicitation for Missing Parameters
When a required parameter is absent, the server can interactively request it via
ServerSession.Elicit(). More conversational than an error, especially for tools likelogswhereworkflow_nameis often needed but not always known upfront.📐 Best Practice Alignment
6. Fix
mcpToolParams()Maintenance Burdenmcp_argument_validation.gocontains a hardcoded map of tool names → valid parameter names (acknowledged with a// MAINTENANCE:comment). This can drift from the actual struct JSON tags. The same reflection pass used for schema generation could auto-extract JSON tag names, eliminating the maintenance hazard.7. Mid-Execution Context Cancellation
Tools check
ctx.Done()only at entry. For subprocess-based tools,exec.CommandContextpropagates the cancel (good!) but there is no goroutine watching for cancellation mid-stream if the subprocess hangs.🔧 General Improvements
8. Roots Support in Inspector Client
mcp_inspect_mcp.gousesextractRootsFromResources()to infer roots from the resource list — a workaround for the proper MCP Roots protocol. Setting upClientOptions.RootsHandlerwould enable proper roots discovery from compliant servers.Recommendations (Prioritized)
logs/auditare the most-used tools and progress feedback matters for long-running operations.statustool.mcpToolParams()reflection (item 6) — Eliminates a known maintenance hazard.References:
Module summary saved to:
scratchpad/mods/modelcontextprotocol-go-sdk.mdBeta Was this translation helpful? Give feedback.
All reactions