MCP Go SDK

The official Go SDK for building Model Context Protocol servers and clients, maintained in collaboration with Google.

SDK
Go
vv1.8.0
5,266 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
90 /100 Excellent
Development Activity 100
Maintenance 100
Community 80
Maturity 40
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 88
Code Quality 92
Innovation 78
Learning Curve 90

MCP Go SDK is the official Go implementation of the Model Context Protocol, the open standard for connecting AI applications to external tools, data sources, and services. It gives Go developers a typed, idiomatic API for constructing both MCP servers (exposing tools, prompts, and resources) and MCP clients (consuming them), without hand-rolling the JSON-RPC message handling and protocol negotiation that MCP requires underneath.

The SDK is organized as a small set of composable packages: mcp for the core client/server APIs, jsonrpc for developers implementing custom transports, and auth/oauthex for OAuth-based authorization flows and protocol extensions. It tracks the evolving MCP specification directly, supporting multiple protocol versions with automatic negotiation, so servers and clients built against different spec revisions can still interoperate.

What You Get

  • A Server type for registering tools, prompts, resources, and resource templates, then running them over stdio, HTTP, or a custom transport
  • A Client type for connecting to MCP servers, listing their capabilities, and invoking tools with typed request/response structs
  • Automatic negotiation across multiple supported MCP protocol versions, so servers and clients on different spec revisions still interoperate
  • Generic mcp.AddTool helpers that derive JSON Schema from Go struct tags, removing manual schema authoring for tool inputs and outputs
  • OAuth primitives in the auth package plus protocol extensions (like Protected Resource Metadata) in oauthex for securing MCP servers
  • A jsonrpc package exposed separately for teams that need to implement their own transport layer
  • Over twenty runnable examples covering stdio and HTTP servers, SSE, middleware, elicitation, rate limiting, and distributed setups

Common Use Cases

  • Building an MCP server in Go that exposes internal tools or APIs to AI assistants like Claude
  • Writing an MCP client embedded in a Go application or agent runtime to call out to external MCP servers
  • Adding OAuth-protected access to a self-hosted MCP server using the SDK’s auth/oauthex packages
  • Implementing a custom MCP transport (beyond stdio/HTTP) using the standalone jsonrpc package
  • Migrating a server built on a third-party Go MCP implementation (e.g. mcp-go) onto the official SDK as MCP tooling consolidates

Under The Hood

Architecture

The SDK centers on two core types in the mcp package: Server and Client, both defined in mcp/server.go and driven over an mcp.Transport. A Server holds mutex-guarded featureSet collections for prompts, tools, resources, and resource templates, tracks active ServerSessions, and negotiates a protocol version per session from a descending-ordered list of supported MCP spec revisions — so a server built against a newer spec can still serve older clients. Session state (ServerSessionState in session.go) captures the initialize handshake, negotiated protocol version, and logging level per connection. Transport-level JSON-RPC framing is isolated in internal/jsonrpc2 and re-exposed publicly via the standalone jsonrpc package for SDK consumers who need to implement their own transport. Authorization is a separate concern layered on top: auth provides OAuth client/server primitives and oauthex implements protocol extensions like resource metadata and dynamic client registration, keeping transport, protocol, and auth cleanly separated. What would break if the core abstraction changed: the featureSet generic collection and the per-session protocol-version negotiation are load-bearing for every server example in the repo.

Tech Stack

The SDK targets Go 1.25 and keeps its dependency footprint deliberately small: google/jsonschema-go for deriving and validating JSON Schema from Go struct tags (used by the generic mcp.AddTool helper), golang-jwt/jwt/v5 and golang.org/x/oauth2 for the OAuth/auth packages, segmentio/encoding for faster JSON encoding on the hot path, yosida95/uritemplate/v3 for RFC 6570 URI templates in resource routing, and golang.org/x/time/golang.org/x/tools for rate limiting and tooling support. There is no web framework dependency — HTTP transport support is built directly on the standard library’s net/http, and the examples/http and examples/server trees show it wired into both plain handlers and SSE-based streaming.

Code Quality

Testing is extensive and central to the project: 61 of 146 Go files in the repository are test files, including protocol-conformance tests (conformance_test.go, a dedicated conformance/ directory, and a conformance.yml CI workflow), example-driven doc tests (*_example_test.go files that double as documentation), and copyright-header enforcement (copyright_test.go). CI runs a full test workflow, CodeQL static analysis, an OpenSSF Scorecard check, and a nightly workflow, indicating active investment in supply-chain and code-quality signals beyond unit tests. Error handling favors explicit, typed error returns over panics, consistent with idiomatic Go and the maintainers’ own AGENTS.md/CONTRIBUTING.md guidance for contributors.

What Makes It Unique

This is the officially blessed Go SDK for MCP, developed by the Model Context Protocol maintainers in collaboration with Google, explicitly positioned to supersede a prior generation of community-built Go MCP implementations (the README credits and points to mcp-go, mcp-golang, and go-mcp as prior art). Its mcp.AddTool pattern — deriving JSON Schema directly from Go struct field tags via generics — removes a class of hand-written schema bugs common in earlier community SDKs, and its explicit multi-version protocol negotiation table is unusually rigorous documentation of exactly which MCP spec revisions each SDK version supports, a compatibility concern most client libraries leave implicit.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers