Get the FREE Ultimate OpenClaw Setup Guide →

go -example

An idiomatic, minimal example of building an MCP (Model Context Protocol) server in Go, complete with essential tooling for developing Go-based microservices.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio rameshsunkara-go-mcp-example go run main.go \
  --env API_KEY="your-api-key-here" \
  --env HTTP_ADDR="localhost:8080" \
  --env LOG_LEVEL="info" \
  --env LOG_FORMAT="json" \
  --env API_BASE_URL="https://api.gsa.gov/analytics/dap/v2"

How to use

This MCP server implements a Go-based MCP server that provides analytics reporting capabilities by interfacing with the Digital Analytics Program (DAP) API. It features a clean, idiomatic Go architecture with dependency injection, structured logging, and configurable runtime behavior. The server exposes tools for fetching analytics reports, a resources system for static/dynamic assets, and prompts to enhance interactive usage. To get started, ensure your environment is configured with your DAP API key and base URL, then run the server. Once running, you can invoke the built-in tool get_report to retrieve various analytics data (e.g., traffic, top-pages, devices) by specifying report types and optional filters such as date ranges or limits. The server is designed for easy testing and mocking via injectable HTTP clients and provides MCP-compatible error responses for robust integration with clients.

How to install

Prerequisites:

  • Go 1.24+ installed on your system
  • Git (optional, for cloning the repository)
  • Make (optional, for convenience commands)

Step-by-step installation:

  1. Clone the repository: git clone https://github.com/rameshsunkara/go-mcp-example.git cd go-mcp-example

  2. Set up environment variables (example): cp .env.example .env

    Edit .env to configure API keys and endpoints

    Example contents:

    API_KEY=your-actual-api-key

    API_BASE_URL=https://api.gsa.gov/analytics/dap/v2

  3. Install dependencies (modules): go mod download

  4. Build (optional): go build -o go-mcp-example main.go

  5. Run the server:

    Via Go run (default MCP transport)

    go run main.go

    Or if using a Makefile (recommended for convenience):

    make run

  6. Verify the server is running by checking logs or contacting the HTTP transport (if enabled):

Notes:

  • The project is designed to be configured via environment variables or a .env file. Ensure API keys and base URLs are set before running.

Additional notes

Tips and common issues:

  • Ensure API_KEY and API_BASE_URL are correctly configured; missing credentials will cause authentication errors from the DAP API.
  • If you enable HTTP transport for debugging, you can use HTTP_ADDR to specify the address (e.g., localhost:8080).
  • Use the provided Makefile targets (e.g., make run, make build, make run-http) for convenience during development.
  • When testing with unit tests or mocks, the HTTP client is injectable to simplify testing without hitting the real API.
  • Logs are structured (JSON by default) to facilitate integration with logging systems; adjust LOG_FORMAT and LOG_LEVEL as needed.

Related MCP Servers

Sponsor this space

Reach thousands of developers