Get the FREE Ultimate OpenClaw Setup Guide →

example-go

Example implementation of a calculator MCP server in Golang

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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

  1. Build or pull a Docker image for the server (or use an existing image named example-go-mcp-server).
  2. Run the server: docker run -i example-go-mcp-server

Option B: Build and run locally (Go)

  1. Ensure Go is installed: https://golang.org/dl/
  2. Clone the repository: git clone <repository-url> cd example-go-mcp-server
  3. Install dependencies and build: go mod tidy go build -o example-go-mcp-server
  4. 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

Sponsor this space

Reach thousands of developers