Unleash type-safe Go implementations of Model Context Protocol with low boilerplate and versatile transport options
mcp-golang is an unofficial implementation of the Model Context Protocol (MCP) designed for developers looking to write MCP servers and clients in Go. This server simplifies the process by leveraging native Go structs, automatic schema generation, error handling, and more, making it highly versatile across various applications.
mcp-golang offers several compelling features that enhance its utility for AI application developers:
mcp-golang supports both STDIO (full feature support) and HTTP transports. Here are a couple of example usages:
Server Example:
package main
import (
"fmt"
"github.com/metoro-io/mcp-golang"
"github.com/metoro-io/mcp-golang/transport/stdio"
)
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(args MyFunctionsArguments) (*mcp_golang.ToolResponse, error) {
return mcp_golang.NewToolResponse(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", args.Submitter))), nil
})
if err != nil {
panic(err)
}
err = server.RegisterPrompt("promt_test", "This is a test prompt", func(args Content) (*mcp_golang.PromptResponse, error) {
return mcp_golang.NewPromptResponse("description", mcp_golang.NewPromptMessage(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", args.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)
}
<-done
}
HTTP Server Example:
// Standard HTTP
transport := http.NewHTTPTransport("/mcp")
transport.WithAddr(":8080")
server := mcp_golang.NewServer(transport)
// Or with Gin framework
transport := http.NewGinTransport()
router := gin.Default()
router.POST("/mcp", transport.Handler())
server := mcp_golang.NewServer(transport)
The above examples demonstrate how to use the stdio and HTTP transports respectively. Note that while HTTP supports request-response scenarios, STDIO offers bidirectional communication capabilities.
mcp-golang implements a comprehensive protocol stack following Model Context Protocol standards:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[mcp-golang Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
The diagram illustrates the communication flow from an AI application (MCP client) through the mcp-golang server to underlying data sources or tools.
To get started, you can install the mcp-golang
library via Go's standard package manager:
go get github.com/metoro-io/mcp-golang
This command will fetch the necessary dependencies and integrate them into your project.
Imagine incorporating mcp-golang into an application that needs to query a knowledge base system for relevant information. You could register a tool within your server and allow CLUDE Desktop or other MCP clients to query the knowledge base seamlessly.
server.RegisterTool("knowledge_base", "Query a knowledge base", func(args QueryArgs) (*mcp_golang.ToolResponse, error) {
// Implementation here...
})
Suppose you want to process real-time data from various sources. Using mcp-golang
, you can define tools that consume and produce data in real time.
Tool: A tool that reads sensor data.
server.RegisterTool("realtime_sensors", "Collect data from sensors", func(args SensorArgs) (*mcp_golang.ToolResponse, error) {
// Implementation here...
})
MCP Client Integration: Using CLUDE Desktop or other MCP clients to consume and act on these sensor data.
client.CallTool("realtime_sensors", args)
mcp-golang is compatible with several MCP clients, including:
These integrations enable seamless communication and data exchange between your Go-based server application and popular AI client applications.
MCP Client Compatibility: mcp-golang supports the following MCP clients with varying levels of integration:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
For advanced configurations, you can customize the server's behavior:
{
"mcpServers": {
"myCustomMCP": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-mycustom"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
The configuration sample above illustrates how to set up environment variables for security and customization purposes.
Contributors are welcome to enhance and improve mcp-golang
. To contribute:
make test
.To stay updated and engage within the broader MCP ecosystem:
By integrating mcp-golang
, you open up new possibilities for AI application development by enabling seamless integration across different tools and clients. Whether you're building a knowledge management system or real-time data processing applications, this protocol stack provides robust support for MCP-based integrations.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
Set up MCP Server for Alpha Vantage with Python 312 using uv and MCP-compatible clients