example-go
Example implementation of a calculator MCP server in Golang
claude mcp add --transport stdio slashben-example-go-mcp-server docker run -i example-go-mcp-server
How to use
This MCP server exposes four math tools that follow the Model Context Protocol (MCP). The server is implemented in Go using the mark3labs MCP Go library and follows a pattern similar to Kubescape's MCP server. The available tools are: add, sub, mul, and div. Each tool accepts numeric inputs and returns a structured JSON response containing the operation name, input values, and the computed result. To use the server, start it with the mcpserver command (as shown in the installation and run instructions), then invoke the desired tool by issuing an MCP request that specifies the tool name and parameters. Examples of responses are provided in the README, demonstrating how inputs are mapped to outputs for each operation.
How to install
Prerequisites:
- Docker installed and running (if using the Docker-based run).
- Alternatively, Go toolchain installed if you prefer building locally (Go 1.18+ is typical).
Option A: Run with Docker
- Build or pull a Docker image for the server (or use an existing image named example-go-mcp-server).
- Run the server: docker run -i example-go-mcp-server
Option B: Build and run locally (Go)
- Ensure Go is installed: https://golang.org/dl/
- Clone the repository: git clone <repository-url> cd example-go-mcp-server
- Install dependencies and build: go mod tidy go build -o example-go-mcp-server
- Run the server (assuming the mcpserver command is exposed by the built binary):
./example-go-mcp-server mcpserver
or, if using the Go runner directly
go run main.go mcpserver
Notes:
- The README indicates the server starts with the mcpserver subcommand and supports the four mathematical tools described.
- If you choose Docker, you may need to adapt image names and ports to fit your environment.
Additional notes
Tips and considerations:
- The server logs MCP tool inputs and outputs to a log file under the temp directory, which is useful for debugging and audit trails.
- Division includes zero-division protection to prevent runtime errors.
- If you add new tools, follow the same pattern shown in the Development section of the README: update createMathTools(), extend CallTool() with a handler, and implement the corresponding operation logic.
- Ensure your MCP client uses the correct operation names exactly as defined (add, sub, mul, div) when constructing requests.
- If running in Docker, consider mounting a volume for logs and configuring temp directories to persist logs if needed.
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