gomcp
gomcp provides a Go implementation of the Model Context Protocol (MCP), enabling communication between language models/agents and external tools or resources via a standardized protocol.
claude mcp add --transport stdio localrivet-gomcp go run ./cmd/server/main.go
How to use
GoMCP is a complete Go implementation of the Model Context Protocol (MCP). It provides an idiomatic Go API for both clients and servers and supports multiple transports (including stdio, HTTP, WebSocket, and Server-Sent Events) with automatic version negotiation across MCP specification versions. This repository/documentation focuses on the gomcp library, which enables you to create MCP clients and, with the accompanying examples, automatically manage external MCP server processes. You can use the client API to call tools, fetch resources, prompt rendering, and manage sessions, while the server management features allow you to launch and manage external MCP servers on-demand in your application. The library emphasizes a type-safe API, stable interfaces, and a clear path to production deployments.
To get started, create a client that uses the stdio transport to communicate with an MCP server, or leverage the automatic server management to spin up server processes on demand. The client exposes methods such as CallTool, GetResource, GetPrompt, and more, enabling tool calls and structured data exchange with LLMs through the MCP protocol. The gomcp ecosystem also includes facilities for session management, transport adapters, and a robust event system, making it suitable for complex workflows that require real-time updates and server orchestration.
For typical usage, initialize a client with the desired transport (e.g., stdio) and protocol version, then perform tool calls or resource retrieval. If you need to run dependent MCP servers automatically, configure the ServerConfig with the definitions (command, args, and environment) and let the client manage lifecycle, health checks, and cleanup. This approach reduces operational overhead and simplifies integration in development, CI, and desktop applications.
How to install
Prerequisites:
- Go (1.18+ recommended)
- Basic Go workspace setup (GOPATH, modules enabled)
Installation steps:
- Ensure Go is installed and your environment is configured.
- Install the gomcp module (as a library) from GitHub: go get github.com/localrivet/gomcp
- Optionally set up a sample server binary or script that can be launched by gomcp as part of automatic server management. If you intend to run a local server executable, ensure it is on your PATH or provide an absolute path in the ServerConfig.
- Build and run a minimal example to verify the setup. For example, create a small Go program that imports gomcp and uses the stdio transport, then run it.
Example snippet to validate installation (paste into a .go file): package main import ( "log" "github.com/localrivet/gomcp/client" ) func main() { c, err := client.NewClient("stdio:///", client.WithStdio()) if err != nil { log.Fatalf("failed to create client: %v", err) } defer c.Close() // Example: call a tool when a server is available // result, err := c.CallTool("example_tool", map[string]interface{}{"arg": 1}) // handle result and error... }
Additional notes
Notes and tips:
- The library supports automatic server management, which can start external MCP servers on demand. Provide the server definitions (command, args, and environment variables) in ServerConfig to enable this feature.
- When using stdio transport, your MCP server must be compatible with stdio-based MCP communication.
- Ensure you manage environment variables securely when injecting keys or credentials into child processes.
- If you encounter protocol negotiation issues, verify that both client and server support the same MCP specification versions (e.g., 2025-03-26, 2024-11-05, or draft).
- For production deployments, prefer stable server definitions and explicit health checks within your server management logic to ensure robustness during restarts and updates.
Related MCP Servers
trpc-agent-go
trpc-agent-go is a powerful Go framework for building intelligent agent systems using large language models (LLMs) and tools.
station
Station is our open-source runtime that lets teams deploy agents on their own infrastructure with full control.
tiger-cli
Tiger CLI is the command-line interface for Tiger Cloud. It includes an MCP server for helping coding agents write production-level Postgres code.
gopls
MCP server for golang projects development: Expand AI Code Agent ability boundary to have a semantic understanding and determinisic information for golang projects.
kubernetes
A Model Context Protocol (MCP) server for the Kubernetes API.
gcp-cost
💰 An MCP server that enables AI assistants to estimate Google Cloud costs, powered by Cloud Billing Catalog API and built with Genkit for Go