[go-fan] Go Module Review: modelcontextprotocol/go-sdk #19534
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-03-05T07:19:58.583Z.
|
Beta Was this translation helpful? Give feedback.
0 replies
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 — reviewing the most recently updated direct dependency in gh-aw.
Today's pick:
github.com/modelcontextprotocol/go-sdk— selected because it's the most recently updated unreviewed direct dependency (v1.4.0released 2026-02-27, just 5 days ago).Module Overview
The official Go SDK for the [Model Context Protocol (MCP)]((modelcontextprotocol.io/redacted), the open standard that lets AI models connect to external data sources and tools. The SDK provides both server-side and client-side APIs, supporting stdio, HTTP (Streamable HTTP), and command transports.
gh-aw uses this SDK heavily — it's the backbone of the
mcp-servercommand and themcp inspectcommand.Current Usage in gh-aw
mcp(server + client APIs),jsonrpc(error codes)Key APIs Used
mcp.NewServer+mcp.AddTool[T]mcp.StdioTransportmcp.NewStreamableHTTPHandler--portflag)mcp.NewClient+mcp.CommandTransportmcp.StreamableClientTransportjsonrpc.Error+ error code constantsmcp.ToolAnnotationsmcp.IconThe usage is well-structured and idiomatic — generic
AddTool[T]for type-safe handlers, correct transport selection, proper context management with per-operation timeouts.Research Findings
Recent Updates (v1.4.0 — 2026-02-27)
DNS Rebinding Protection — Localhost servers now reject requests with non-localhost
Hostheaders by default. This is a security win that is already active in gh-aw's HTTP server mode without any code changes needed.No HTML Escaping in JSON — Switched from default
encoding/jsonHTML escaping to no-escape marshaling by default.<,>,&in tool output will no longer be escaped to\u003cetc. This improves readability of JSON output from tools.Sampling with Tools — Servers can now issue
CreateMessageWithTools, clients can handle them. Not currently used by gh-aw, but relevant if future tools need AI assistance.Client-side OAuth (experimental, build tag
mcp_go_client_oauth) — For MCP client authentication flows. Could be relevant for the HTTP MCP server inspector when connecting to authenticated endpoints.Extensions field in capabilities (SEP-2133) — Servers can now expose custom metadata in capabilities.
OSSF Scorecard 8.7 — The SDK project added security scanning; reassuring for a critical dependency.
Security fix: Case-sensitive JSON unmarshaling (backported to v1.3.1).
Best Practices from Maintainers
mcp.AddTool[T]generic form for type-safe handlers ✅ (gh-aw does this)ListChanged: falsewhen tools are static ✅ (gh-aw does this)DisableStandaloneSSE: truein client transport when you don't need server-initiated messages ✅ (correctly set inmcp_inspect_mcp.go)ctx.Done()in long-running tools ✅ (gh-aw has pre-flight checks)SessionTimeoutin HTTP server ✅ (2 hours, reasonable for MCP sessions)Improvement Opportunities
🏃 Quick Wins
1.
responseWritermissingWriteHeaderoverride (mcp_server_http.go:26-29)The HTTP logging middleware captures status codes for logging, but never overrides
WriteHeader. This means every logged response shows status 200, even for 4xx/5xx errors from the MCP framework:2. Duplicate client inspection code (
mcp_inspect_mcp.go:131-221,224-309)connectStdioMCPServerandconnectHTTPMCPServershare ~30 lines of identical ListTools/ListResources logic. Extracting to aqueryServerCapabilities(ctx, session)helper would reduce the duplication and make it easier to add future capability queries (e.g., ListPrompts once the SDK supports it).✨ Feature Opportunities
1. Extensions Capability Field (v1.4.0 SEP-2133)
The new
extensionsfield inServerCapabilitieslets servers expose custom metadata that MCP Apps can read. gh-aw could expose:This makes gh-aw more discoverable for MCP-aware tooling.
2. Client-side OAuth for HTTP MCP Inspector
The
StreamableClientTransportfor HTTP inspection (mcp_inspect_mcp.go:238-256) uses a customheaderRoundTripperfor auth headers. As client OAuth stabilizes in v1.5.0, the inspector could support OAuth flows for connecting to authenticated MCP endpoints in workflow frontmatter — enabling inspection of secured MCP servers without hardcoding tokens.3. ListPrompts Support
When the MCP spec's Prompts capability sees wider adoption, the inspector could add
session.ListPromptsalongside the existingListTools/ListResourcescalls. The SDK currently supports this.📐 Best Practice Alignment
1. Outer timeout context in
connectToMCPServerThe 30-second outer context acts as a safety cap. The relationship between the two timeouts should be documented so future contributors understand why both exist.
2. Consider
slices.Containsfor allowed tool checkIn
mcp_inspect_mcp.go:452, the code already usesslices.Containscorrectly. Good — no action needed.🔧 General Improvements
ctx.Err().Error()nil-safety — Several tool handlers passctx.Err().Error()as MCP error data in the cancellation check. There's a theoretical (though unlikely) race wherectx.Err()could returnnil. A nil-safe pattern:Recommendations
Priority order based on impact:
WriteHeaderinresponseWriter(Quick Win, 3 lines) — Correct logging is needed for debugging HTTP transport issuesqueryServerCapabilitieshelper (Quick Win, refactor) — Reduces code duplication, easier to extendextensionstoServerCapabilities(Feature, ~5 lines) — Low risk, improves discoverabilityNext Steps
responseWriter.WriteHeaderoverride inmcp_server_http.gomcp_inspect_mcp.goextensionscapability field for exposing gh-aw metadataGenerated by Go Fan 🐹 — §22659050095
Module summary saved to:
scratchpad/mods/modelcontextprotocol-go-sdk.mdReferences:
Beta Was this translation helpful? Give feedback.
All reactions