Get the FREE Ultimate OpenClaw Setup Guide →

go

deprecated: use the official MCP sdk! (https://github.com/modelcontextprotocol/go-sdk) / ⚡ A type-safe, intuitive Go SDK for building MCP servers with ease and confidence

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio ktr0731-go-mcp go run ./cmd/temperature

How to use

go-mcp is a type-safe Go SDK for building MCP (Model Context Protocol) servers. The repository demonstrates a temperature conversion MCP server that exposes a tool named convert_temperature. When you run the server, you can interact with it via JSON-RPC over standard IO as described by the MCP protocol. This setup uses Go's strong typing and generated code to ensure that tool inputs and prompts are validated at compile time, reducing runtime errors and making the server reliable for prompt-driven interactions.

To use the server, first ensure your environment has Go installed and that you can run Go commands. Start the temperature MCP server with the provided command, then use the Go SDK's generated interfaces to define and register tools, prompts, and handlers. The example includes a tool called convert_temperature which converts temperatures between Celsius and Fahrenheit. You can extend the server by adding more tool definitions and corresponding handlers, leveraging the type-safe code generation pattern shown in the quick start. The server communicates via JSON-RPC and supports standard MCP features such as Ping, Tools, Prompts, Resource subscriptions, and Logging.

How to install

Prerequisites:

  • Go 1.20+ (or newer)
  • Basic familiarity with Go modules and building Go binaries

Installation steps:

  1. Clone the repository or create your Go module and import the go-mcp package as described in the project docs.
  2. Ensure you have Go modules enabled: export GO111MODULE=on
  3. Build or run the example server:

Code example to run the temperature MCP server (as shown in the Quick Start):

# From the repository root (or your module workspace)
go run ./cmd/temperature

If you prefer to build the binary first and then run it:

# Build
go build -o temperature-server ./cmd/temperature

# Run
./temperature-server

You can also run the code generation step if you are extending the server with new tools, following the instructions in the Quick Start section of the repository.

Additional notes

Tips and common considerations:

  • The example uses stdio transport for JSON-RPC, but the library supports other transports as your needs evolve (e.g., HTTP). If you expand to HTTP transport, ensure you handle JSON-RPC 2.0 semantics correctly.
  • Generated code provides strong typing for tool inputs. Avoid runtime casts; prefer updating the codegen definitions when adding new tools.
  • When adding more tools, consider updating tests to cover type safety for inputs and outputs.
  • If you encounter module resolution issues, ensure your Go environment is configured with GOFLAGS and that your module path imports match those in the examples.
  • Environment variables such as GOPROXY or GOENV typically aren’t required for the basic server; they can be used to customize module fetching in restricted environments.
  • For debugging, run the server with verbose logging if supported by the SDK, and inspect the JSON-RPC payloads for understanding tool invocation and responses.

Related MCP Servers

Sponsor this space

Reach thousands of developers