MCP Go SDK: Official Go Implementation for Model Context Protocol
The MCP Go SDK is a robust and official software development kit (SDK) designed specifically for implementing the Model Context Protocol (MCP) in Go. MCP is an emerging standard protocol aimed at facilitating seamless communication between AI models, servers, and clients, particularly in scenarios involving large language models (LLMs) and agentic AI systems. This SDK serves as a foundational tool for developers building MCP-compliant applications, allowing them to create servers that expose tools, resources, and prompts to AI models, as well as clients that can interact with these servers over various transports.
Key Features and Packages
The SDK is structured into several modular, importable packages to ensure flexibility and ease of use:
-
github.com/modelcontextprotocol/go-sdk/mcp: This is the core package that defines the primary APIs for constructing and managing MCP clients and servers. It handles essential operations such as tool invocation, resource management, and prompt handling, aligning closely with the MCP specification. -
github.com/modelcontextprotocol/go-sdk/jsonrpc: Tailored for developers who need to implement custom transports. It provides the underlying JSON-RPC machinery required for MCP communication, enabling support for protocols like stdin/stdout, WebSockets, or HTTP. -
github.com/modelcontextprotocol/go-sdk/auth: Offers primitives for OAuth integration, ensuring secure authentication in MCP sessions. This is crucial for production environments where access control is necessary. -
github.com/modelcontextprotocol/go-sdk/oauthex: Extends the OAuth protocol with features like ProtectedResourceMetadata, enhancing security and metadata handling in AI-driven interactions.
The SDK strives for full compliance with the MCP specification, with detailed feature documentation available in the docs/ directory. This documentation maps MCP concepts (e.g., tools, resources, sessions) directly to SDK packages, making it easier for developers to understand and implement protocol-compliant features.
Getting Started with the SDK
Building an MCP Server
To quickly set up an MCP server, developers can instantiate an mcp.Server, register features like tools, and run it over a transport. Here's a basic example from the README that demonstrates a simple greeting tool server using stdin/stdout transport:
package main
import (
"context"
"log"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type Input struct {
Name string `json:"name" jsonschema:"the name of the person to greet"`
}
type Output struct {
Greeting string `json:"greeting" jsonschema:"the greeting to tell to the user"`
}
func SayHi(ctx context.Context, req *mcp.CallToolRequest, input Input) (
*mcp.CallToolResult,
Output,
error,
) {
return nil, Output{Greeting: "Hi " + input.Name}, nil
}
func main() {
// Create a server with a single tool.
server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}, nil)
mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi)
// Run the server over stdin/stdout, until the client disconnects.
if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatal(err)
}
}This example shows how straightforward it is to define a tool handler and expose it via MCP.
Building an MCP Client
Clients can connect to servers, discover capabilities, and invoke tools. The following example connects to the above server via a command transport and calls the "greet" tool:
package main
import (
"context"
"log"
"os/exec"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
ctx := context.Background()
// Create a new client, with no features.
client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil)
// Connect to a server over stdin/stdout.
transport := &mcp.CommandTransport{Command: exec.Command("myserver")}
session, err := client.Connect(ctx, transport, nil)
if err != nil {
log.Fatal(err)
}
defer session.Close()
// Call a tool on the server.
params := &mcp.CallToolParams{
Name: "greet",
Arguments: map[string]any{"name": "you"},
}
res, err := session.CallTool(ctx, params)
if err != nil {
log.Fatalf("CallTool failed: %v", err)
}
if res.IsError {
log.Fatal("tool failed")
}
for _, c := range res.Content {
log.Print(c.(*mcp.TextContent).Text)
}
}The examples/ directory provides more advanced samples, including full server-client interactions and custom transports.
Contributing and Community
The project welcomes contributions from the Go and AI developer communities. Guidelines are outlined in CONTRIBUTING.md, covering code style, testing, and pull request processes. This collaborative approach has led to rapid evolution, with the SDK reaching stable v1.0.0 in late 2025.
Acknowledgements and Alternatives
The official SDK draws inspiration from community-driven efforts, such as:
- mcp-go by Ed Zynda and contributors.
- mcp-golang.
- go-mcp.
These alternatives remain useful for specific use cases, highlighting the vibrant ecosystem around MCP in Go.
License and Maintenance
Licensed under the permissive MIT License, the SDK is maintained by the Model Context Protocol organization in partnership with Google, ensuring ongoing updates and compatibility with evolving MCP standards. With over 3,200 stars on GitHub, it has gained significant traction in the AI development community for enabling efficient, standardized AI model integrations.
