tr4d3r/mcp-go
3.1
If you are the rightful owner of mcp-go and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This document provides a comprehensive overview of a Model Context Protocol (MCP) server setup using Go, designed for efficient development and testing of MCP servers.
Tools
2
Resources
0
Prompts
0
MCP Go Development Container
This is a development container setup for building Model Context Protocol (MCP) servers using Go.
Features
- Go 1.22 development environment
- Pre-configured VS Code with Go extensions
- MCP server implementation with basic tools
- WebSocket support for MCP communication
- Health monitoring endpoint
- Hot reload with Air (for development)
- Static analysis tools (golangci-lint, staticcheck)
Getting Started
Prerequisites
- Docker
- VS Code with Dev Containers extension
Development Setup
-
Open in Dev Container
- Open VS Code in this folder
- Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) - Select "Dev Containers: Reopen in Container"
-
Install Dependencies
go mod tidy -
Run the Server
go run main.go -
Test the Server
- Health check:
curl http://localhost:8080/health - WebSocket endpoint:
ws://localhost:8080/mcp
- Health check:
MCP Server Features
Available Tools
-
Echo Tool
- Echoes back any message
- Useful for testing MCP communication
-
Timestamp Tool
- Returns the current timestamp
- Demonstrates parameter-less tools
MCP Protocol Support
- Protocol version:
2024-11-05 - JSON-RPC 2.0 communication
- WebSocket transport
- Tool execution capabilities
Development Commands
Run with Hot Reload
air
Lint Code
golangci-lint run
Run Static Analysis
staticcheck ./...
Format Code
goimports -w .
Build for Production
go build -o mcp-server main.go
Testing the MCP Server
Using WebSocket Client
You can test the MCP server using a WebSocket client. Here's an example initialization message:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}
List Available Tools
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}
Call Echo Tool
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "echo",
"arguments": {
"message": "Hello, MCP!"
}
}
}
Project Structure
.
├── .devcontainer/
│ ├── devcontainer.json # Dev container configuration
│ └── Dockerfile # Custom container setup
├── static/ # Static files for testing
├── main.go # MCP server implementation
├── go.mod # Go module definition
└── README.md # This file
Adding New Tools
To add a new tool to the MCP server:
- Add the tool definition in the
handleToolsListmethod - Add the tool execution logic in the
handleToolCallmethod - Test the new tool using the WebSocket interface
Environment Variables
PORT: Server port (default: 8080)LOG_LEVEL: Logging level (default: info)
Contributing
- Make your changes
- Run tests:
go test ./... - Lint code:
golangci-lint run - Format code:
goimports -w .