Overview
The Go MCP SDK is the official library for building MCP servers in Go. It supports tools, resources, prompts, transports, and the stdio and streamable-http transport.
Installation
go get github.com/modelcontextprotocol/go-sdkMinimal Server Example
server := mcp.NewServer("my-server", "1.0.0")
server.AddTool(mcp.Tool{
Name: "add",
Description: "Add two numbers",
InputSchema: mcp.ToolInputSchema{
Type: "object",
Properties: map[string]any{
"a": map[string]any{"type": "number"},
"b": map[string]any{"type": "number"},
},
},
}, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
a := req.Params.Arguments["a"].(float64)
b := req.Params.Arguments["b"].(float64)
return mcp.NewToolResultText(fmt.Sprintf("%v", a+b)), nil
})Adding a Tool
Tools are the primary way MCP servers expose functionality to clients. Each tool has a name, input schema, and handler function.
// Add more tools with server.AddTool(...)Supported Features
tools
resources
prompts
transports
Testing Your Server
- Start the server and verify it prints no startup errors.
- Run
npx @modelcontextprotocol/inspectorand connect over stdio. - Call your tools and verify they return the expected responses.
- Connect from Claude Desktop and confirm tool visibility.