$ show modelcontextprotocol/go-sdk
This repository is the official Go SDK for the Model Context Protocol (MCP), a client/server protocol for AI tool orchestration. It provides production-grade implementations of MCP servers and clients, supporting multiple transports (stdio, SSE, streamable HTTP, in-memory) and full OAuth 2.0 authorization code flows with enterprise extensions. The SDK features typed tool handlers with automatic JSON Schema inference, a middleware system for custom processing, generic pagination helpers, and a schema cache for performance in stateless deployments. It maintains backward compatibility with multiple MCP protocol versions (2024-11-05 through 2026-07-28) using compatibility flags and includes conformance tests against the official MCP test suite. The architecture separates JSON-RPC 2.0 wire protocol, transport abstractions, and core client/server logic, with internal packages for low-level RPC handling, OAuth test infrastructure, and configuration compatibility. While the SDK is actively maintained and well-tested, it carries some technical debt from deprecated features (roots, sampling, logging) and protocol version complexity.
The LLM identified 3 files worth highlighting for reuse:
Implements a thread-safe schema cache for JSON Schemas inferred from Go types via reflection. Uses pointer identity and type keys to avoid repeated schema generation, with a configurable eviction policy. This component is self-contained and extractable for any Go application needing static schema caching, demonstrating non-obvious attention to performance in stateless server deployments.
Core JSON-RPC 2.0 connection implementation with support for cancellation, request batching, and asynchronous response handling. Provides a clean abstraction for sending requests and receiving responses over any transport. The implementation is well-isolated and could be reused independently to build JSON-RPC clients or servers in other contexts.
Implements the streamable HTTP transport for MCP, supporting both stateless and stateful sessions over SSE with reconnection, event replay, and OAuth integration. Handles protocol version negotiation, DNS rebinding protection, cross-origin checks, and configurable session timeouts. The pattern of combining SSE with HTTP request/response cycles is reusable for building real-time APIs with session resumption.