A zero-dependency MCP framework that turns any Go program into an AI-accessible service. Tools, resources, and prompts over stdio or Streamable HTTP — with clients for both. Compile, ship, connect.
package main import ( "context" "fmt" "github.com/BackendStack21/go-mcp/gomcp" ) func main() { srv := gomcp.NewServer("greeter", "1.0.0") srv.AddTool(gomcp.Tool{ Name: "greet", Description: "Greet a person by name", InputSchema: gomcp.InputSchema{ Type: "object", Properties: map[string]gomcp.Property{ "name": {Type: "string"}, }, }, Handler: func(ctx context.Context, args map[string]any) (string, error) { return fmt.Sprintf("Hello, %s!", args["name"]), nil }, }) srv.Run() // stdio — or srv.ListenAndServe(":8080") for HTTP }
Register tools, resources, and prompts. The AI client discovers them automatically over stdio or HTTP. Or connect to other MCP servers yourself with the built-in clients.
Wrap PostgreSQL or MySQL as read-only MCP tools. The AI explores schemas, runs queries, and analyzes data — safely.
Expose CPU, memory, and disk as resources. The AI checks system health, diagnoses issues, and monitors trends.
Wrap kubectl as MCP tools. The AI describes deployments, fetches logs, and diagnoses cluster issues — without cluster admin.
Bridge any REST API to AI. Give agents access to GitHub, Stripe, Slack — any HTTP endpoint becomes a callable tool.
Serve MCP over Streamable HTTP — one handler, any port. Optional Bearer auth and Origin allowlist built in.
Connect to any MCP server over HTTP or spawn one over stdio — the same typed Client interface for both.
Give AI scoped file access. Read, list, and search files — with path traversal protection built in.
Go's ecosystem is the limit. gRPC services, crypto operations, image processing — if you can write it in Go, the AI can call it.
Give AI agents safe, read-only SQL access. Query the schema, list tables, run SELECT statements — all scoped and auditable. The AI sees your database without touching your credentials.
srv.AddTool(gomcp.Tool{ Name: "db_query", Description: "Run a read-only SQL query", InputSchema: gomcp.InputSchema{ Type: "object", Properties: map[string]gomcp.Property{ "query": {Type: "string"}, }, }, Handler: func(ctx context.Context, args map[string]any) (string, error) { // Validate, execute, return formatted results return runQuery(ctx, args["query"].(string)) }, })
Expose any server data as MCP resources. CPU, memory, process info, disk usage — read on demand via resources/read. The AI monitors your infrastructure without SSH access.
srv.AddResource(gomcp.Resource{ URI: "system://cpu", Name: "CPU Usage", MimeType: "application/json", Handler: func(ctx context.Context) (string, error) { info := map[string]any{ "cores": runtime.NumCPU(), "percent": getCPUPercent(), } data, _ := json.Marshal(info) return string(data), nil }, })
Tools for actions. Resources for data. Prompts for templates. Register them, the framework handles the rest.
Callable functions with typed input schemas. The AI discovers them via tools/list and invokes them via tools/call. Return text results the AI can reason about.
Readable data sources identified by URI. The AI lists them via resources/list and reads them via resources/read. MIME types included.
Pre-defined conversation templates. The AI requests them by name with arguments via prompts/get. Returns formatted messages ready for the chat.
The same server runs over stdio or Streamable HTTP — and the built-in clients talk to either.
// stdio — the default, for local AI clients srv.Run() // Streamable HTTP — for remote access srv.SetAuthToken(token) // optional srv.SetAllowedOrigins(origins) // optional srv.ListenAndServe(":8080") // or mount on your own mux: mux.Handle("/mcp", srv.Handler())
// connect to a remote server c := gomcp.NewHTTPClientWithToken(url, token) // or spawn a local one c, _ := gomcp.NewStdioClient("./my-server") c.Initialize(ctx, "client", "1.0") tools, _ := c.ListTools(ctx) out, _ := c.CallTool(ctx, "greet", args)
2026-07-28 plus the legacy initialize handshake. Not a subset. Not a work-in-progress. Backward compatible.
Compiles to a single static binary. Ships in any container. Connects to any MCP client.
go get github.com/BackendStack21/go-mcp
102 tests. 91.9% coverage. View on GitHub →