[go-fan] Go Module Review: modelcontextprotocol/go-sdk #5190
Closed
Replies: 1 comment
-
|
⚓ Avast! This discussion be marked as outdated by Go Fan. |
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: MCP Go SDK
The official Go SDK for the Model Context Protocol (MCP) is a critical dependency that enables gh-aw to both expose its functionality as an MCP server and connect to external MCP servers. This review analyzes how gh-aw leverages the SDK and identifies opportunities to better utilize its latest features.
Module Overview
Repository: https://github.com/modelcontextprotocol/go-sdk
Current Version: v1.1.0 (latest)
Release Date: October 30, 2025
The MCP Go SDK provides a comprehensive implementation of the Model Context Protocol, enabling standardized communication between AI agents and tools. It supports multiple transport mechanisms (stdio, HTTP/SSE, custom I/O) and provides both client and server implementations.
Current Usage in gh-aw
gh-aw uses the SDK in two distinct roles:
Role 1: MCP Server (Exposing gh-aw Tools)
Primary implementation:
pkg/cli/mcp_server.gogh-aw runs as an MCP server exposing 7 tools to external MCP clients:
status- Show workflow statuscompile- Compile workflows with validationlogs- Download and analyze workflow logsaudit- Investigate workflow runsmcp-inspect- Inspect MCP server capabilitiesadd- Add workflows from remote repositoriesupdate- Update workflows and extensionKey patterns used:
mcp.NewServer()with Implementation metadatamcp.AddTool()for automatic schema generation from Go structsmcp.NewStreamableHTTPHandler()for HTTP/SSE transportStdioTransportfor subprocess communicationloggingHandlerwrapping HTTP handlerTransport support:
Role 2: MCP Client (Connecting to External Servers)
Primary implementation:
pkg/cli/mcp_inspect_mcp.goThe
mcp inspectcommand connects to external MCP servers to discover their capabilities:Key patterns used:
mcp.NewClient()with Implementation metadatamcp.CommandTransportfor stdio/Docker serversmcp.StreamableClientTransportfor HTTP serverssession.ListTools(),session.ListResources()for capability discoveryResearch Findings
Recent Updates in v1.1.0 (October 30, 2025)
Major Behavior Change:
StreamableHTTPOptions.EventStore. This reduces memory usage for high-traffic servers.New Features:
IOTransport- General-purpose transport fromio.ReadCloser/io.WriteCloserServerOptions.Logger- Built-in structured logging supportStreamableHTTPOptions.Logger- HTTP transport-level loggingStreamableHTTPOptions.SessionTimeout- Automatic idle session cleanupmcp_go_client_oauthbuild tagRecent Bug Fixes:
Best Practices from SDK Documentation
The SDK documentation emphasizes:
mcp.AddTool()with struct types for automatic JSON schema inferencemcp.Middlewarefor request/response logging instead of HTTP-level wrappingsession.Tools(),session.Resources()iterators for paginationNewLoggingHandler()to getslog.Handlerfor server-side loggingKnown Rough Edges (v2 Wishlist)
The SDK maintainers document several API rough edges to fix in v2:
EventStore.Openis unnecessary (artifact from earlier version)ResourceUpdatedNotificationsParams,ProgressNotificationParamsAudioContent.MarshalJSONshould have pointer receiverImprovement Opportunities
🏃 Quick Wins
Use ServerOptions.Logger for structured logging
Benefit: Structured logging, easier debugging, consistent log format
Add SessionTimeout to prevent resource leaks
Benefit: Automatic cleanup of idle connections
Remove unnecessary defer cancel() after WithTimeout
Benefit: Cleaner code, prevent confusion
Validate tool names at startup
Benefit: Catch configuration errors early (SDK only logs warnings)
✨ Feature Opportunities
Migrate to Middleware pattern for logging
Current: HTTP-level logging wrapper blocks SSE streaming
Better: Use MCP middleware (as fixed in SDK examples/http Fix text sanitization to preserve markdown bold notation #614)
Benefit: Non-blocking SSE streams, protocol-level logging
Add Resource support for workflow files
Opportunity: Expose workflow files as MCP resources
Benefit: Clients could read workflow content directly through MCP protocol
Add Prompt support for common operations
Use cases:
Benefit: LLM-friendly interaction patterns, guided workflows
Leverage IOTransport for custom transports
New in v1.1.0: General-purpose transport from io.ReadCloser/WriteCloser
Use case: Custom transport implementations (e.g., Unix sockets, named pipes)
Add health check endpoint for HTTP server
Current: No health check mechanism
Benefit: Monitoring, load balancer integration
📐 Best Practice Alignment
Consolidate timeout values as constants
Current: Hardcoded timeouts scattered throughout
Better:
Consistent error handling in tool handlers
Current: Mix of returning errors in CallToolResult vs as function errors
Best practice: Return errors directly, let
AddToolhandle wrappingExtract test helper for MCP client creation
Current: Repeated in every test file
Better:
testutil.NewMCPTestClient()helperAdd graceful shutdown for HTTP server
Current: Server blocks indefinitely
Better: Handle shutdown signals
Add connection retry logic for MCP clients
Current: Single connection attempt
Enhancement: Exponential backoff retry
Recommendations
🎯 Priority 1: Immediate Improvements (Next Sprint)
ServerOptions.Loggerfor structured loggingSessionTimeoutto prevent resource leaksEstimated effort: 2-3 hours
Risk: Low
Impact: Better reliability and maintainability
🎯 Priority 2: Medium-term Enhancements (Next Month)
Estimated effort: 1-2 days
Risk: Medium (requires testing)
Impact: Better observability and robustness
🎯 Priority 3: Future Considerations (Backlog)
Estimated effort: 2-3 days
Risk: Low (additive features)
Impact: Enhanced functionality for MCP clients
Next Steps
Generated by Go Fan
Module summary saved to: specs/mods/go-sdk.md
Beta Was this translation helpful? Give feedback.
All reactions