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.
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:
-
Clone the repository: git clone https://github.com/rameshsunkara/go-mcp-example.git cd go-mcp-example
-
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
-
Install dependencies (modules): go mod download
-
Build (optional): go build -o go-mcp-example main.go
-
Run the server:
Via Go run (default MCP transport)
go run main.go
Or if using a Makefile (recommended for convenience):
make run
-
Verify the server is running by checking logs or contacting the HTTP transport (if enabled):
- Default HTTP transport endpoint: http://localhost:8080
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
mcp-proxy
An MCP proxy server that aggregates and serves multiple MCP resource servers through a single HTTP server.
sandbox
A Model Context Protocol (MCP) server that enables LLMs to run ANY code safely in isolated Docker containers.
github-brain
An experimental GitHub MCP server with local database.
mcp-tts
MCP Server for Text to Speech
tasker
An MCP server for Android's Tasker automation app.
godoc
A mcp server provide infomation from pkg.go.dev. For all golang programmers