Get the FREE Ultimate OpenClaw Setup Guide →

go-sdk

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

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-go-sdk go run ./cmd/server/main.go \
  --env MCP_BIND_ADDR="address to bind the MCP server (e.g., 0.0.0.0:8080)" \
  --env MCP_LOG_LEVEL="info (optional: debug, info, warn, error)"

How to use

The MCP Go SDK provides a set of packages to build MCP clients and servers in Go. With the mcp.Server abstraction, you can define and expose tools that can be invoked by MCP clients over a transport (such as standard input/output, a socket, or a custom protocol). Tools are functions that take a request, input payload, and return a result along with an output payload. The SDK includes core mcp, jsonrpc (for custom transports), and authentication primitives to support OAuth flows. To start a server, create an mcp.Server, register tools using mcp.AddTool, and run it over a transport like StdioTransport or a custom transport you implement. Clients can then connect to the server via the corresponding transport, call tools by name, provide arguments, and receive results or errors. The examples demonstrate a minimal server with a single tool and a sample client that connects over stdin/stdout, illustrating the typical workflow of defining tool inputs/outputs, wiring a server, and performing tool invocations over MCP. If you need authentication or advanced transport customization, you can leverage the auth and jsonrpc packages to implement OAuth primitives or a bespoke transport layer while preserving MCP semantics.

How to install

Prerequisites:

  • Go 1.20+ installed and available on PATH
  • A working Go workspace or module-aware project setup

Installation steps:

  1. Create or navigate to your Go module/project
  2. Pull the MCP Go SDK module go get github.com/modelcontextprotocol/go-sdk
  3. Build or run an example server (adjust paths to your project structure) go run ./cmd/server/main.go

Optional: if you want to run tests or examples that rely on transport implementations, ensure your GOPATH/module mode is configured as your project requires.

Additional notes

Notes and tips:

  • The SDK is modular; use mcp.Server for server composition, and mcp.AddTool to expose tools. Each tool has a function signature to handle requests and produce outputs.
  • transports: The SDK includes StdioTransport for stdin/stdout and CommandTransport for spawning a separate process; you can implement additional transports by conforming to the MCP transport interface.
  • Authentication: If you require OAuth or protected resources, explore the auth and oauthex packages for primitives and extensions.
  • Environment variables: Consider MCP_LOG_LEVEL for logging verbosity and MCP_BIND_ADDR / MCP_PORT for binding the server network address when using network transports.
  • Version compatibility: The Go SDK targets specific MCP spec versions; ensure client implementations align with the MCP spec version you intend to support.
  • If you run into module resolution issues, ensure module mode is enabled (GO111MODULE=on) and your go.mod declares the correct module path.

Related MCP Servers

Sponsor this space

Reach thousands of developers