Navigation
MCP Go SDK: Fast, Reliable MCP Server Development - MCP Implementation

MCP Go SDK: Fast, Reliable MCP Server Development

Build Model Context Protocol servers in Go fast & easy with MCP Go SDK – expert tools for seamless integration, reliability, and developer-friendly simplicity.

Developer Tools
4.7(124 reviews)
186 saves
86 comments

This tool saved users approximately 5712 hours last month!

About MCP Go SDK

What is MCP Go SDK: Fast, Reliable MCP Server Development?

The MCP Go SDK is a production-ready implementation of the Model Context Protocol (MCP) specification, engineered to simplify the development of robust LLM integration solutions. Built with Go's renowned efficiency and concurrency model, this SDK provides a battle-tested framework for building both MCP clients and servers that adhere strictly to the MCP standard.

Key Features of MCP Go SDK: Fast, Reliable MCP Server Development?

Protocol Conformance

Full implementation of MCP lifecycle management, including initialization, resource discovery, and advanced message handling

Transport Flexibility

Supports stdio-based communication out of the box with upcoming SSE (Server-Sent Events) support for real-time scenarios

Event-Driven Architecture

Pre-built handlers manage protocol messages and lifecycle events, allowing developers to focus on business logic implementation

MCP Go SDK Features

How to Use MCP Go SDK: Fast, Reliable MCP Server Development?

Server Implementation Example

// Create resource-aware server
type FSServer struct {
    fs fs.FS
    mcp.UnimplementedServer
}

// Implement core protocol methods
func (s *FSServer) ListResources(ctx context.Context, req *mcp.Request[mcp.ListResourcesRequest]) (*mcp.Response[mcp.ListResourcesResponse], error) {
    // Walk file system and map resources
    // ...
}

Deploy with standard Go workflows and integrate via mcp.NewStdioServer() for seamless MCP compatibility

Use Cases of MCP Go SDK: Fast, Reliable MCP Server Development?

LLM Context Providers

Expose document repositories or API endpoints as MCP resources for consumption by LLM platforms

Hybrid Workflows

Integrate custom tools and domain-specific knowledge bases into LLM-driven applications through standardized interfaces

Debugging Environments

Create mock MCP servers for testing LLM interactions without relying on external services

MCP Go SDK FAQ

FAQ from MCP Go SDK: Fast, Reliable MCP Server Development?

How does error handling work?

Every protocol operation returns structured errors conforming to MCP's defined error taxonomy, with built-in logging middleware for observability

What authentication options are available?

While core protocol doesn't mandate auth, developers can layer standard Go HTTP handlers or implement custom auth middleware for transport layers

Does it support asynchronous operations?

Yes, the async/notifications feature is in active development with preliminary API surface available in the development branch

Content

MCP Go SDK

Build Go Report Card GoDoc

A Go implementation of the Model Context Protocol (MCP), providing both client and server capabilities for integrating with LLM surfaces.

Overview

The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Go SDK implements the full MCP specification, making it easy to:

  • Build MCP clients that can connect to any MCP server
  • Create MCP servers that expose resources, prompts and tools
  • Use standard transports like stdio and SSE (coming soon)
  • Handle all MCP protocol messages and lifecycle events

A small example

Curious what all this looks like in practice? Here's an example server that exposes the contents of an io.FS as resources.

package main

import (
	"context"
	"flag"
	"io/fs"
	"log"
	"mime"
	"os"
	"path/filepath"
	"strings"

	"github.com/riza-io/mcp-go"
)

type FSServer struct {
	fs fs.FS

	mcp.UnimplementedServer
}

func (s *FSServer) Initialize(ctx context.Context, req *mcp.Request[mcp.InitializeRequest]) (*mcp.Response[mcp.InitializeResponse], error) {
	return mcp.NewResponse(&mcp.InitializeResponse{
		ProtocolVersion: req.Params.ProtocolVersion,
		Capabilities: mcp.ServerCapabilities{
			Resources: &mcp.Resources{},
		},
	}), nil
}

func (s *FSServer) ListResources(ctx context.Context, req *mcp.Request[mcp.ListResourcesRequest]) (*mcp.Response[mcp.ListResourcesResponse], error) {
	var resources []mcp.Resource
	fs.WalkDir(s.fs, ".", func(path string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		if d.IsDir() {
			return nil
		}
		resources = append(resources, mcp.Resource{
			URI:      "file://" + path,
			Name:     path,
			MimeType: mime.TypeByExtension(filepath.Ext(path)),
		})
		return nil
	})
	return mcp.NewResponse(&mcp.ListResourcesResponse{
		Resources: resources,
	}), nil
}

func (s *FSServer) ReadResource(ctx context.Context, req *mcp.Request[mcp.ReadResourceRequest]) (*mcp.Response[mcp.ReadResourceResponse], error) {
	contents, err := fs.ReadFile(s.fs, strings.TrimPrefix(req.Params.URI, "file://"))
	if err != nil {
		return nil, err
	}
	return mcp.NewResponse(&mcp.ReadResourceResponse{
		Contents: []mcp.ResourceContent{
			{
				URI:      req.Params.URI,
				MimeType: mime.TypeByExtension(filepath.Ext(req.Params.URI)),
				Text:     string(contents), // TODO: base64 encode
			},
		},
	}), nil
}

func main() {
	flag.Parse()

	root := flag.Arg(0)
	if root == "" {
		root = "/"
	}

	server := mcp.NewStdioServer(&FSServer{
		fs: os.DirFS(root),
	})

	if err := server.Listen(context.Background(), os.Stdin, os.Stdout); err != nil {
		log.Fatal(err)
	}
}

You can compile this example and wire it up to Claude Desktop (or any other MCP client).

{
	"mcpServers": {
		"fs": {
			"command": "/path/to/mcp-go-fs",
			"args": [
				"/path/to/root/directory"
			]
		}
	}
}

Documentation

Roadmap

The majority of the base protocol is implemented. The following features are on our roadmap:

  • Notifications
  • Sampling
  • Roots

Legal

Offered under the MIT license.

Related MCP Servers & Clients