Infrastructure
mcp-golang is an unofficial implementation of the Model Context Protocol in Go.
Write MCP servers in golang with a few lines of code.
Docs at https://mcpgolang.com
Install with go get github.com/metoro-io/mcp-golang
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)
}
<-done
}
This will start a server using the stdio transport (used by claude desktop), host a tool called "hello" that will say hello to the user who submitted it.
Create a file in ~/Library/Application Support/Claude/claude_desktop_config.json with the following contents:
{
"mcpServers": {
"golang-mcp-server": {
"command": "<your path to golang MCP server go executable>",
"args": [],
"env": {}
}
}
}
Contributions are more than welcome! Please check out our contribution guidelines.
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.
Some more extensive examples using the library found here:
Open a PR to add your own projects!