mcp-golang
Write Model Context Protocol servers in few lines of go code. Docs at https://mcpgolang.com . Created by https://metoro.io
Documentation
mcp-golang
mcp-golang is an unofficial implementation of the Model Context Protocol in Go.
Write MCP servers and clients in golang with a few lines of code.
Docs at https://mcpgolang.com
Highlights
- ๐ก๏ธType safety - Define your tool arguments as native go structs, have mcp-golang handle the rest. Automatic schema generation, deserialization, error handling etc.
- ๐ Custom transports - Use the built-in transports (stdio for full feature support, HTTP for stateless communication) or write your own.
- โก Low boilerplate - mcp-golang generates all the MCP endpoints for you apart from your tools, prompts and resources.
- ๐งฉ Modular - The library is split into three components: transport, protocol and server/client. Use them all or take what you need.
- ๐ Bi-directional - Full support for both server and client implementations through stdio transport.
Example Usage
Install with `go get github.com/metoro-io/mcp-golang`
Server Example
package main
import (
"fmt"
"github.com/metoro-io/mcp-golang"
"github.com/metoro-io/mcp-golang/transport/stdio"
)
// Tool arguments are just structs, annotated with jsonschema tags
// More at https://mcpgolang.com/tools#schema-generation
type Content struct {
Title string `json:"title" jsonschema:"required,description=The title to submit"`
Description *string `json:"description" jsonschema:"description=The description to submit"`
}
type MyFunctionsArguments struct {
Submitter string `json:"submitter" jsonschema:"required,description=The name of the thing calling this tool (openai, google, claude, etc)"`
Content Content `json:"content" jsonschema:"required,description=The content of the message"`
}
func main() {
done := make(chan struct{})
server := mcp_golang.NewServer(stdio.NewStdioServerTransport())
err := server.RegisterTool("hello", "Say hello to a person", func(arguments MyFunctionsArguments) (*mcp_golang.ToolResponse, error) {
return mcp_golang.NewToolResponse(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Submitter))), nil
})
if err != nil {
panic(err)
}
err = server.RegisterPrompt("promt_test", "This is a test prompt", func(arguments Content) (*mcp_golang.PromptResponse, error) {
return mcp_golang.NewPromptResponse("description", mcp_golang.NewPromptMessage(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Title)), mcp_golang.RoleUser)), nil
})
if err != nil {
panic(err)
}
err = server.RegisterResource("test://resource", "resource_test", "This is a test resource", "application/json", func() (*mcp_golang.ResourceResponse, error) {
return mcp_golang.NewResourceResponse(mcp_golang.NewTextEmbeddedResource("test://resource", "This is a test resource", "application/json")), nil
})
err = server.Serve()
if err != nil {
panic(err)
}
0 {
log.Printf("Result: %s", response.Content[0].TextContent.Text)
}
}Using with Claude Desktop
Create a file in ~/Library/Application Support/Claude/claude_desktop_config.json with the following contents:
{
"mcpServers": {
"golang-mcp-server": {
"command": "",
"args": [],
"env": {}
}
}
}Contributions
Contributions are more than welcome! Please check out our contribution guidelines.
Discord
Got any suggestions, have a question on the api or usage? Ask on the discord server.
A maintainer will be happy to help you out.
Examples
Some more extensive examples using the library found here:
- **Metoro** - Query and interact with kubernetes environments monitored by Metoro
Open a PR to add your own projects!
Server Feature Implementation
Tools
- [x] Tool Calls
- [x] Native go structs as arguments
- [x] Programatically generated tool list endpoint
- [x] Change notifications
- [x] Pagination
Prompts
- [x] Prompt Calls
- [x] Programatically generated prompt list endpoint
- [x] Change notifications
- [x] Pagination
Resources
- [x] Resource Calls
- [x] Programatically generated resource list endpoint
- [x] Change notifications
- [x] Pagination
Transports
- [x] Stdio - Full support for all features including bidirectional communication
- [x] HTTP - Stateless transport for simple request-response scenarios (no notifications support)
- [x] Gin - HTTP transport with Gin framework integration (stateless, no notifications support)
- [x] SSE
- [x] Custom transport support
- [ ] HTTPS with custom auth support - in progress. Not currently part of the spec but we'll be adding experimental support for it.
Client
- [x] Call tools
- [x] Call prompts
- [x] Call resources
- [x] List tools
- [x] List prompts
- [x] List resources
Frequently asked questions
What is mcp-golang?
mcp-golang is Write Model Context Protocol servers in few lines of go code. Docs at https://mcpgolang.com . Created by https://metoro.io
How do I install mcp-golang?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is mcp-golang open source?
Yes โ it is hosted on GitHub at https://github.com/metoro-io/mcp-golang and has 1,149 stars.
Related MCP tools
A CLI host application that enables Large Language Models (LLMs) to interact with external tools through the Model Context Protocol (MCP).
Query anything (GitHub, Notion, +40 more) with SQL and let LLMs (ChatGPT, Claude) connect to using MCP Go-based implementation. Trusted by 1300+ developers.
ToolHive makes deploying MCP servers easy, secure and fun Go-based implementation. Trusted by 1300+ developers. Trusted by 1300+ developers.
A command-line interface for interacting with MCP (Model Context Protocol) servers using both stdio and HTTP transport. Go-based implementation.
The most powerful MCP Slack Server with no permission requirements, Apps support, multiple transports Stdio and SSE, DMs, Group DMs and smart history fetch l...
Model Context Protocol (MCP) server for Kubernetes and OpenShift Go-based implementation. Trusted by 700+ developers. Trusted by 700+ developers.
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP