A secure, self-hosted Model Context Protocol (MCP) server written in Go with comprehensive data governance features. This server gives you full control over your data, ensuring privacy, security, and compliance.
- 🔒 Data Governance: Complete audit logging, access control, and data retention policies
- 🛡️ Security: Authentication, encryption, and secure configuration management
- 📊 Monitoring: Built-in metrics and structured logging
- 🔧 Extensible: Easy to add custom tools and resources
- ⚡ Performance: Efficient concurrent request handling
- 📝 Audit Trail: Comprehensive logging of all operations
- Go 1.21 or later
- Basic understanding of MCP (Model Context Protocol)
- Clone the repository:
git clone <your-repo-url>
cd mcp-go- Install dependencies:
go mod download- Copy the example environment file:
cp .env.example .env- Edit
.envand configure your settings (especiallyAPI_KEYifAUTH_ENABLED=true)
The server is configured via environment variables. See .env.example for all available options:
AUTH_ENABLED: Enable/disable authentication (default: true)API_KEY: Secret key for authentication (required if auth enabled)AUDIT_ENABLED: Enable audit logging (default: true)AUDIT_LOG_PATH: Path to audit log file (default: ./audit.log)DATA_RETENTION_DAYS: Days to retain audit data (default: 90)ENCRYPTION_ENABLED: Enable data encryption (default: true)LOG_LEVEL: Logging level (debug, info, warn, error)LOG_FORMAT: Log format (json or console)
The MCP server communicates via stdin/stdout (standard MCP protocol):
make runOr build and run:
make build
./bin/mcp-serverThe server follows the MCP protocol and can be integrated with any MCP-compatible client. Example configuration for Claude Desktop:
{
"mcpServers": {
"mcp-go": {
"command": "/path/to/bin/mcp-server",
"env": {
"API_KEY": "your-api-key",
"AUDIT_ENABLED": "true",
"AUDIT_LOG_PATH": "./audit.log"
}
}
}
}Or create a .env file in the same directory as the binary with your configuration.
Echoes back the input message.
Parameters:
message(string, required): The message to echo
Example:
{
"message": "Hello, World!"
}Performs basic arithmetic operations.
Parameters:
operation(string, required): One of "add", "subtract", "multiply", "divide"a(number, required): First numberb(number, required): Second number
Example:
{
"operation": "add",
"a": 10,
"b": 5
}Returns system information and governance metrics.
Parameters: None
Returns current server configuration (read-only).
Returns current data governance metrics.
All operations are logged to the audit log file (configurable via AUDIT_LOG_PATH). Each entry includes:
- Timestamp
- Action type
- Tool/resource accessed
- Success/failure status
- Error messages (if any)
- Data size
- Request ID
The server supports authentication via API keys. When AUTH_ENABLED=true, all requests must include a valid API key.
Audit logs are retained according to DATA_RETENTION_DAYS. Automatic cleanup runs daily.
When ENCRYPTION_ENABLED=true, sensitive data can be encrypted (implementation can be extended with proper encryption libraries).
To add a custom tool, edit internal/tools/tools.go and add a new tool definition:
// Define your tool arguments struct
type MyToolArgs struct {
Param1 string `json:"param1" jsonschema:"description=Parameter description,required"`
}
// Register the tool
if err := server.RegisterTool("my_tool", "Description of my tool", func(ctx context.Context, args MyToolArgs) (*mcp_golang.ToolResponse, error) {
// Your tool logic here
// Don't forget to audit!
gov.Audit(AuditEntry{
Action: "tool_execution",
Tool: "my_tool",
Success: true,
})
result := map[string]interface{}{
"result": "your result",
}
resultJSON, _ := json.Marshal(result)
return mcp_golang.NewToolResponse(mcp_golang.NewTextContent(string(resultJSON))), nil
}); err != nil {
return fmt.Errorf("failed to register my_tool: %w", err)
}To add a custom resource, edit internal/resources/resources.go:
if err := server.RegisterResource(
"resource://my-resource",
"My Resource",
"Description of my resource",
"application/json",
func(ctx context.Context) (*mcp_golang.ResourceResponse, error) {
// Your resource logic here
gov.Audit(AuditEntry{
Action: "resource_access",
Resource: "resource://my-resource",
Success: true,
})
data := map[string]interface{}{
"data": "your data",
}
dataJSON, _ := json.Marshal(data)
return mcp_golang.NewResourceResponse(
mcp_golang.NewTextEmbeddedResource("resource://my-resource", string(dataJSON), "application/json"),
), nil
},
); err != nil {
return fmt.Errorf("failed to register resource: %w", err)
}<|tool▁calls▁begin|><|tool▁call▁begin|> todo_write
- Always set a strong API_KEY when enabling authentication
- Restrict ALLOWED_ORIGINS to specific domains in production
- Enable audit logging to track all operations
- Regularly review audit logs for suspicious activity
- Keep dependencies updated with
go get -u ./... - Use encryption for sensitive data in transit and at rest
- Implement rate limiting for production deployments
- Monitor metrics regularly for anomalies
The project follows standard Go project layout:
mcp-go/
├── cmd/
│ └── mcp-server/ # Main application entry point
│ └── main.go
├── internal/ # Private application code
│ ├── config/ # Configuration management
│ ├── governance/ # Data governance and audit logging
│ ├── logger/ # Logging setup
│ ├── resources/ # MCP resource definitions
│ ├── security/ # Security utilities
│ ├── server/ # MCP server setup
│ └── tools/ # MCP tool definitions
├── bin/ # Build output
├── go.mod # Go module file
├── env.example # Example configuration
├── PROJECT_STRUCTURE.md # Detailed structure documentation
└── README.md # This file
See PROJECT_STRUCTURE.md for detailed information about the project organization.
go test ./...go build -o mcp-go-server- Check that all required environment variables are set
- Verify
API_KEYis set ifAUTH_ENABLED=true - Check log output for specific error messages
- Verify tool registration in
tools.go - Check audit logs for error details
- Ensure input schema matches expected format
- Check
AUDIT_LOG_PATHis writable - Verify
AUDIT_ENABLED=true - Check file permissions
[Specify your license here]
[Your contribution guidelines]
[Your support information]