Production-ready Model Context Protocol (MCP) server template in Go with complete MCP 2025-06-18 support.
12 MCP Features Fully Implemented:
| Feature | Description |
|---|---|
| Tools | 4 example tools with structured outputs |
| Prompts | 3 reusable prompt templates |
| Resources | 6 static/dynamic resources |
| Roots | Filesystem root definitions |
| Completion | Structured tool outputs with JSON schemas |
| Logging | Serverβclient log notifications (8 levels) |
| Pagination | Cursor-based pagination (max 100/page) |
| Sampling | Serverβclient LLM requests |
| Elicitation | Serverβuser data requests |
| Progress | Real-time progress notifications |
| Cancellation | Request cancellation support |
| Ping | Health checks |
- Go 1.23+
- (Optional) Docker/Podman
Important: Ensure Go's bin directory is in your PATH:
# Add to PATH (required for air, development tools)
export PATH=$PATH:$(go env GOPATH)/bin
# Make it permanent (add to ~/.zshrc or ~/.bashrc):
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.zshrc
source ~/.zshrcgit clone https://github.com/NP-compete/gomcp.git
cd gomcp
go mod downloadFor Cursor IDE:
make cursor
# Server runs on http://localhost:8081/mcp/sseFor Claude Desktop:
export MCP_TRANSPORT_PROTOCOL=stdio
go run cmd/server/main.goDefault (HTTP):
make run
# Server runs on http://localhost:8081Cursor IDE (~/.cursor/mcp.json):
{
"mcpServers": {
"gomcp": {
"url": "http://localhost:8081/mcp/sse"
}
}
}Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"gomcp": {
"command": "/path/to/gomcp/bin/gomcp",
"args": [],
"env": {
"MCP_TRANSPORT_PROTOCOL": "stdio"
}
}
}
}multiply_numbers- Number multiplication with structured outputcode_review- Generate code review analysislogo- Display server logolong_operation- Demonstrates progress & cancellation
code_review- Code review templategit_commit- Git commit message generatordebug_help- Debugging assistance
project://info- Server informationproject://status- System statusdocs://quickstart- Quick start guidedocs://api-reference- API documentationconfig://template- Configuration templateconfig://env-vars- Environment variables
Environment Variables:
| Variable | Default | Description |
|---|---|---|
MCP_TRANSPORT_PROTOCOL |
http |
Transport: stdio, http, sse |
MCP_PORT |
8081 |
Server port |
CURSOR_COMPATIBLE_SSE |
true |
Enable Cursor compatibility |
ENABLE_AUTH |
true |
Enable OAuth authentication |
LOG_LEVEL |
INFO |
Log level |
Create .env file:
MCP_TRANSPORT_PROTOCOL=http
MCP_PORT=8081
CURSOR_COMPATIBLE_SSE=true
ENABLE_AUTH=false# Run all tests
./scripts/test_all.sh
# Run specific tests
go test -v ./internal/completion
go test -v ./internal/logging
go test -v ./internal/pagination
# Generate coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.htmlTest Coverage: 65 tests, 100% pass rate
gomcp/
βββ cmd/server/ # Main application entry point
βββ internal/
β βββ api/ # HTTP handlers & routing
β βββ completion/ # Structured outputs
β βββ logging/ # Serverβclient logs
β βββ pagination/ # Cursor-based pagination
β βββ prompts/ # Prompt implementations
β βββ resources/ # Resource implementations
β βββ roots/ # Filesystem roots
β βββ tools/ # Tool implementations
β βββ mcp/ # MCP server logic
β βββ config/ # Configuration management
βββ pkg/mcpprotocol/ # MCP protocol implementation
βββ test/ # Integration tests
βββ Makefile # Build & run commands
make dev # Auto-restarts on file changesmake build # Development build
make build-prod # Production build with optimization
make clean # Clean artifacts
make deps # Update dependenciesmake docker-build # Build image
make docker-run # Run containerCreate internal/tools/mytool_sdk.go:
type MyToolInput struct {
Param string `json:"param" jsonschema:"required,parameter description"`
}
type MyToolOutput struct {
Result string `json:"result"`
}
func MyTool(ctx context.Context, req *mcp.CallToolRequest, input MyToolInput) (*mcp.CallToolResult, MyToolOutput, error) {
// Your logic here
output := MyToolOutput{Result: "success"}
return nil, output, nil
}Register in internal/mcp/server_sdk.go:
server.AddTool(mcp.NewTool("mytool", "Description", MyTool))Create internal/prompts/myprompt.go:
func MyPrompt(ctx context.Context, args mcp.GetPromptParams) (*mcp.GetPromptResult, error) {
return &mcp.GetPromptResult{
Messages: []*mcp.PromptMessage{
{Role: "user", Content: &mcp.TextContent{Text: "Prompt text"}},
},
}, nil
}Register in internal/mcp/server_sdk.go.
Create internal/resources/myresource.go:
func MyResource(ctx context.Context, params mcp.ReadResourceParams) (*mcp.ReadResourceResult, error) {
return &mcp.ReadResourceResult{
Contents: []*mcp.ResourceContents{{
URI: "my://resource",
Text: "Content here",
}},
}, nil
}Register in internal/mcp/server_sdk.go.
Enable OAuth:
export ENABLE_AUTH=true
export POSTGRES_HOST=localhost
export POSTGRES_DB=mcp_dbDisable for development:
export ENABLE_AUTH=falsemake build-prod
# Binary: bin/gomcpdocker build -t gomcp-server .
docker run -p 8081:8081 --env-file .env gomcp-server# Set transport
export MCP_TRANSPORT_PROTOCOL=http # or stdio
export MCP_PORT=8081
export CURSOR_COMPATIBLE_SSE=true # For Cursor
export ENABLE_AUTH=false # For developmentcurl http://localhost:8081/metricsReturns:
- Request counts
- Tool usage
- Error rates
- Response times
- Client info
curl http://localhost:8081/healthPort already in use:
lsof -ti:8081 | xargs kill -9Cursor not connecting:
- Use
make cursor(Cursor compatibility is enabled by default) - Verify
~/.cursor/mcp.jsonhas correct URL:http://localhost:8081/mcp/sse - Restart Cursor IDE
Claude Desktop not working:
- Set
MCP_TRANSPORT_PROTOCOL=stdio - Use absolute path to binary
- Restart Claude Desktop
Build errors:
go mod tidy
go mod download
make clean && make buildMIT License - see LICENSE file
- Fork the repository
- Create feature branch
- Add tests
- Submit pull request
Built with β€οΈ using Go and the official MCP SDK
Template ready for production use with all MCP 2025-06-18 features!