This repository contains the official Go SDK for the Model Context Protocol (MCP). The SDK is designed to be idiomatic, future-proof, and extensible.
mcp: The core package defining the primary APIs for constructing and using MCP clients and servers. This is where most logic resides.jsonrpc: Provides the JSON-RPC 2.0 transport layer. Use this if implementing custom transports.auth: Primitives for supporting OAuth.oauthex: Extensions to the OAuth protocol, such as Protected Resource Metadata.internal: Internal implementation details not exposed to users.examples: Example clients and servers. Use these as references for usage patterns.
The project uses the standard Go toolchain.
- Build:
go build ./... - Test:
go test ./...
- Unit Tests: Run
go test ./...to run all unit tests. - Conformance Tests: Use the following scripts to run the official MCP conformance tests against the SDK.
./scripts/server-conformance.shfor server tests../scripts/client-conformance.shfor client tests.- The scripts download the latest conformance suite from npm by default.
- To get possible options pass the
--helpflag to the script.
- Follow standard Go conventions (Effective Go).
- Use
gofmtto format code. - Add copyright headers to all new Go files:
// Copyright 2025 The Go MCP SDK Authors. All rights reserved. // Use of this source code is governed by the license // that can be found in the LICENSE file.
- Do not add comments to the code unless they are really necessary:
- Prefer self-documenting code.
- Focus on the "why" not the "what" in comments.
- README.md: Do NOT edit
README.mddirectly. It is generated frominternal/readme/README.src.md.- Edit
internal/readme/README.src.md. - Run
go generate ./internal/readmeto regenerate. - Commit both files.
- Edit
- docs/: Do NOT edit
docs/directory directly. It is generated from files ininternal/docs.- Edit
internal/docs/*.src.md. - Run
go generate ./internal/docsto regenerate. - Commit files from both directories.
- Edit