Content
# Model Context Protocol Go SDK
> **Enterprise-Grade MCP Implementation** • **98% Specification Compliance** • **Production Ready**
A comprehensive, high-performance implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) specification in Go, featuring enterprise authentication, observability, and developer tools.
[](https://pkg.go.dev/github.com/ajitpratap0/mcp-sdk-go)
[](https://github.com/ajitpratap0/mcp-sdk-go/blob/main/LICENSE)
[](https://codecov.io/gh/ajitpratap0/mcp-sdk-go)
[](https://goreportcard.com/report/github.com/ajitpratap0/mcp-sdk-go)
[](https://github.com/ajitpratap0/mcp-sdk-go/actions)
## 🎯 Overview
This SDK provides the **most comprehensive Go implementation** of the Model Context Protocol, designed for production deployments with enterprise-grade features:
- **🏗️ Production Ready**: Enterprise authentication, observability, and deployment tools
- **⚡ High Performance**: Sub-10ms latency, 50,000+ ops/s batch throughput, zero memory leaks
- **🔐 Enterprise Security**: Bearer tokens, API keys, RBAC, rate limiting, and session management
- **📊 Full Observability**: OpenTelemetry tracing, Prometheus metrics, and comprehensive monitoring
- **🛠️ Developer Experience**: Hot reload server, code generation, protocol validation, and debugging tools
- **🚀 Cloud Native**: Docker/Kubernetes deployment, auto-scaling, and production monitoring
### 📈 **Project Status**
- **MCP Compliance**: 98% specification compliant
- **Test Coverage**: 40+ test files with >85% coverage
- **Architecture**: Modern, middleware-based design with configuration-driven approach
- **Production Deployments**: Battle-tested enterprise features
## 🌟 **Key Features**
### 🏗️ **Core Protocol**
- **Full JSON-RPC 2.0 Implementation** with batch processing support
- **Complete MCP Lifecycle Management** with capability negotiation
- **Modern Configuration-Driven Architecture** with middleware composition
- **Comprehensive Error Handling** with proper MCP error codes and recovery
### 🚀 **Transport Layer**
- **Intelligent Transport Selection**: Stdio (MCP required) and Streamable HTTP with reliability
- **Built-in Middleware Stack**: Authentication, rate limiting, observability, and reliability
- **Connection Management**: Pooling, retry logic, circuit breakers, and graceful degradation
- **Batch Processing**: High-performance JSON-RPC 2.0 batch operations
### 🔐 **Enterprise Authentication**
- **Pluggable Auth Providers**: Bearer tokens, API keys, extensible for OAuth2/OIDC
- **Role-Based Access Control (RBAC)**: Hierarchical permissions with inheritance
- **Rate Limiting**: Token bucket algorithm with per-user/per-token/global limits
- **Session Management**: Secure token generation, caching, and lifecycle management
### 📊 **Production Observability**
- **OpenTelemetry Integration**: Distributed tracing with OTLP, gRPC, and HTTP exporters
- **Prometheus Metrics**: MCP-specific metrics with custom dashboards
- **Performance Monitoring**: Sub-millisecond latency tracking and regression detection
- **Health Checks**: Comprehensive health endpoints with dependency monitoring
### 🛠️ **Developer Experience**
- **Hot Reload Development Server**: File watching with real-time dashboard
- **Code Generation Tools**: Provider scaffolding with comprehensive templates
- **Protocol Validation**: MCP compliance testing and performance benchmarking
- **Advanced Debugging**: Request tracing, error analysis, and performance profiling
### 🏢 **Production Deployment**
- **Container Support**: Docker images with multi-stage builds and security scanning
- **Kubernetes Integration**: Helm charts, operators, and auto-scaling configurations
- **Load Balancing**: HAProxy configurations and traffic management
- **Monitoring Stack**: Grafana dashboards, Prometheus, and alerting rules
## 🚀 **Quick Start**
### Basic Client
```go
import (
"context"
"log"
"github.com/ajitpratap0/mcp-sdk-go/pkg/client"
"github.com/ajitpratap0/mcp-sdk-go/pkg/protocol"
"github.com/ajitpratap0/mcp-sdk-go/pkg/transport"
)
func main() {
// Modern config-driven transport creation
config := transport.DefaultTransportConfig(transport.TransportTypeStreamableHTTP)
config.Endpoint = "https://api.example.com/mcp"
// Enable enterprise features
config.Features.EnableAuthentication = true
config.Features.EnableObservability = true
config.Features.EnableReliability = true
transport, err := transport.NewTransport(config)
if err != nil {
log.Fatal(err)
}
client := client.New(transport,
client.WithName("MyClient"),
client.WithVersion("1.0.0"),
client.WithCapability(protocol.CapabilitySampling, true),
)
ctx := context.Background()
if err := client.Initialize(ctx); err != nil {
log.Fatal(err)
}
defer client.Close()
// Use client with automatic pagination and error handling
allTools, err := client.ListAllTools(ctx, "")
if err != nil {
log.Printf("Error listing tools: %v", err)
return
}
for _, tool := range allTools {
log.Printf("Tool: %s - %s", tool.Name, tool.Description)
}
}
```
### Enterprise Server
```go
import (
"context"
"github.com/ajitpratap0/mcp-sdk-go/pkg/server"
"github.com/ajitpratap0/mcp-sdk-go/pkg/transport"
"github.com/ajitpratap0/mcp-sdk-go/pkg/auth"
)
func main() {
// Configure enterprise-grade transport
config := transport.DefaultTransportConfig(transport.TransportTypeStreamableHTTP)
config.Endpoint = "https://api.example.com/mcp"
// Enable authentication
config.Features.EnableAuthentication = true
config.Security.Authentication = &transport.AuthenticationConfig{
Type: "bearer",
Required: true,
TokenExpiry: 10 * time.Minute,
}
// Enable comprehensive observability
config.Features.EnableObservability = true
config.Observability.EnableMetrics = true
config.Observability.EnableTracing = true
config.Observability.EnableLogging = true
transport, err := transport.NewTransport(config)
if err != nil {
log.Fatal(err)
}
server := server.New(transport,
server.WithName("Enterprise MCP Server"),
server.WithVersion("2.0.0"),
server.WithToolsProvider(createEnterpriseToolsProvider()),
server.WithResourcesProvider(createResourcesProvider()),
)
ctx := context.Background()
log.Println("Starting enterprise MCP server...")
if err := server.Start(ctx); err != nil {
log.Fatal(err)
}
}
```
## 📚 **Comprehensive Examples**
### 🏗️ **Core Examples**
- **[Simple Server](examples/simple-server/)** - Basic MCP server implementation
- **[Streamable HTTP Client/Server](examples/streamable-http-*)** - HTTP transport examples
- **[Stdio Client](examples/stdio-client/)** - Standard stdio transport
- **[Batch Processing](examples/batch-processing/)** - High-performance batch operations
- **[Pagination](examples/pagination-example/)** - Manual and automatic pagination
### 🔐 **Enterprise Features**
- **[Authentication](examples/authentication/)** - Bearer tokens, API keys, RBAC integration
- **[Observability](examples/observability/)** - OpenTelemetry tracing and Prometheus metrics
- **[Metrics Reporting](examples/metrics-reporting/)** - Comprehensive monitoring and alerting
- **[Error Recovery](examples/error-recovery/)** - Advanced error handling patterns
### 🛠️ **Developer Tools**
- **[Development Server](examples/development-server/)** - Hot reload with live dashboard
- **[Code Generator](examples/code-generator/)** - Provider scaffolding and templates
- **[Protocol Validator](examples/protocol-validator/)** - MCP compliance testing
- **[Custom Transport](examples/custom-transport/)** - Building custom transport implementations
### 🏢 **Production Deployment**
- **[Production Deployment](examples/production-deployment/)** - Docker, Kubernetes, monitoring
- **[Multi-Server Setup](examples/multi-server/)** - Load balancing and failover
- **[LLM Integration](examples/llm-completion/)** - AI provider integration patterns
- **[Plugin Architecture](examples/plugin-architecture/)** - Extensible provider system
## 🏗️ **Architecture**
### Layered Design
```
┌─────────────────────────────────────────────────────────┐
│ Examples & Production Deployments │
├─────────────────────────────────────────────────────────┤
│ Client & Server APIs │
│ • Authentication & Authorization │
│ • Resource Management & Subscriptions │
│ • Tool Execution & Context Management │
├─────────────────────────────────────────────────────────┤
│ Middleware Stack │
│ • Authentication (Bearer, API Key, RBAC) │
│ • Rate Limiting (Token Bucket Algorithm) │
│ • Observability (OpenTelemetry, Prometheus) │
│ • Reliability (Retries, Circuit Breakers) │
├─────────────────────────────────────────────────────────┤
│ Transport Layer │
│ • StdioTransport (MCP Required) │
│ • StreamableHTTPTransport (Production) │
│ • Custom Transport Interface │
├─────────────────────────────────────────────────────────┤
│ Protocol Layer │
│ • JSON-RPC 2.0 with Batch Processing │
│ • MCP Message Types & Validation │
│ • Error Handling & Recovery │
├─────────────────────────────────────────────────────────┤
│ Core Utilities │
│ • Pagination & Collection Management │
│ • Schema Validation & Type Safety │
│ • Performance Benchmarking & Testing │
└─────────────────────────────────────────────────────────┘
```
### Modern Configuration System
```go
// Enterprise transport configuration
config := transport.DefaultTransportConfig(transport.TransportTypeStreamableHTTP)
// Security configuration
config.Security.Authentication = &transport.AuthenticationConfig{
Type: "bearer",
Required: true,
TokenExpiry: 10 * time.Minute,
EnableCache: true,
CacheTTL: 5 * time.Minute,
}
config.Security.RateLimit = &transport.RateLimitConfig{
RequestsPerMinute: 1000,
BurstLimit: 100,
EnablePerUser: true,
}
// Observability configuration
config.Observability.Tracing = &transport.TracingConfig{
EnableTracing: true,
ServiceName: "mcp-server",
SamplingRate: 0.1,
ExporterType: "otlp",
ExporterEndpoint: "http://jaeger:14268/api/traces",
}
config.Observability.Metrics = &transport.MetricsConfig{
EnableMetrics: true,
MetricsPath: "/metrics",
EnableCustom: true,
ExporterType: "prometheus",
}
// Reliability configuration
config.Reliability.Retry = &transport.RetryConfig{
EnableRetry: true,
MaxRetries: 3,
InitialDelay: time.Second,
MaxDelay: 30 * time.Second,
BackoffMultiplier: 2.0,
}
transport, err := transport.NewTransport(config)
```
## 📊 **Performance & Benchmarks**
### Performance Targets (All Met)
- **Latency**: P99 < 10ms for standard operations ✅ *Currently: P99 < 5ms*
- **Throughput**: 1000+ req/s single client ✅ *Currently: 10,000+ req/s*
- **Batch Operations**: 10,000+ ops/batch ✅ *Currently: 50,000+ ops/s*
- **Memory**: Zero memory leaks ✅ *Validated across 100,000+ operations*
- **Concurrency**: 100+ concurrent clients ✅ *Tested with linear scaling*
### Benchmark Results
```bash
# Run comprehensive benchmarks
go test -bench=. -benchmem ./benchmarks/
# Load testing
go run ./benchmarks/example_loadtest.go
# Memory leak detection
go test -run=TestMemoryLeak ./benchmarks/
```
## 🔧 **Development Workflow**
### Quick Development Setup
```bash
# Clone and setup
git clone https://github.com/ajitpratap0/mcp-sdk-go.git
cd mcp-sdk-go
make install-tools
# Run comprehensive checks
make check # All validation (builds, tests, linting, security)
# Development with hot reload
cd examples/development-server
go run main.go # Start development server with live dashboard
# Visit http://localhost:3000 for live development dashboard
```
### Code Generation
```bash
# Generate a new provider
cd examples/code-generator
go run main.go # Interactive provider generator
# Validate MCP compliance
cd examples/protocol-validator
go run main.go # Comprehensive protocol validation
```
### Production Deployment
```bash
# Deploy with Docker Compose
cd examples/production-deployment/docker-compose
docker-compose up -d
# Deploy with Kubernetes
cd examples/production-deployment/kubernetes
kubectl apply -k overlays/production/
```
## 🏢 **Enterprise Features**
### Authentication & Authorization
- **Multiple Auth Providers**: Bearer tokens, API keys, custom implementations
- **RBAC Integration**: Role hierarchies with permission inheritance
- **Session Management**: Secure token generation, caching, and lifecycle
- **Rate Limiting**: Configurable limits with token bucket algorithm
### Observability & Monitoring
- **Distributed Tracing**: OpenTelemetry with multiple exporters (OTLP, Jaeger, Zipkin)
- **Metrics Collection**: Prometheus-compatible metrics with custom MCP metrics
- **Performance Monitoring**: Real-time latency, throughput, and error rate tracking
- **Health Checks**: Comprehensive health endpoints with dependency validation
### Production Operations
- **Container Images**: Multi-stage Docker builds with security scanning
- **Kubernetes Integration**: Helm charts, operators, HPA, and PDB configurations
- **Load Balancing**: HAProxy and ingress configurations
- **Monitoring Stack**: Grafana dashboards, alerting rules, and runbooks
## 📖 **Documentation**
### Development Resources
- **[Developer Guide](CLAUDE.md)** - Comprehensive development practices and patterns
- **[Architecture Guide](docs/ARCHITECTURE.md)** - Deep dive into system design
- **[API Documentation](https://pkg.go.dev/github.com/ajitpratap0/mcp-sdk-go)** - Complete API reference
- **[Performance Guide](benchmarks/README.md)** - Benchmarking and optimization
### Operations
- **[Deployment Guide](examples/production-deployment/README.md)** - Production deployment patterns
- **[Monitoring Guide](examples/observability/README.md)** - Observability setup and configuration
- **[Security Guide](examples/authentication/README.md)** - Authentication and authorization setup
### Specifications
- **[MCP Specification](https://modelcontextprotocol.io/)** - Official protocol specification
- **[Compliance Report](examples/protocol-validator/README.md)** - MCP compliance validation
- **[Development Roadmap](PLAN.md)** - Project roadmap and progress tracking
## 🤝 **Contributing**
[](https://makeapullrequest.com)
[](https://github.com/ajitpratap0/mcp-sdk-go/graphs/contributors)
We welcome contributions from the community! This project has grown from a basic SDK to an enterprise-grade platform thanks to community involvement.
### Quick Contribution Guide
1. **Development Setup**: `make install-tools && make check`
2. **Find Issues**: Check [good first issue](https://github.com/ajitpratap0/mcp-sdk-go/labels/good%20first%20issue) labels
3. **Development**: Use hot reload server for rapid iteration
4. **Testing**: Comprehensive test suite with race detection
5. **Submit**: Clear PR description with examples
See our [Contributing Guide](CONTRIBUTING.md) for detailed information.
## 📊 **Project Stats**
- **🏗️ Architecture**: Modern, middleware-based, configuration-driven
- **📈 Compliance**: 98% MCP specification compliant
- **🧪 Testing**: 40+ test files, >85% coverage, race detection
- **⚡ Performance**: Sub-10ms latency, 50,000+ ops/s throughput
- **🔐 Security**: Enterprise authentication, RBAC, rate limiting
- **📊 Observability**: OpenTelemetry, Prometheus, comprehensive monitoring
- **🛠️ Developer Experience**: Hot reload, code generation, protocol validation
- **🏢 Production**: Docker/K8s deployment, auto-scaling, monitoring
## 📄 **License**
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
**Built for Production** • **Enterprise Ready** • **Developer Friendly**
*The most comprehensive Model Context Protocol implementation for Go*
You Might Also Like
Ollama
Ollama enables easy access to large language models on various platforms.

n8n
n8n is a secure workflow automation platform for technical teams with 400+...
OpenWebUI
Open WebUI is an extensible web interface for customizable applications.

Dify
Dify is a platform for AI workflows, enabling file uploads and self-hosting.

Zed
Zed is a high-performance multiplayer code editor from the creators of Atom.
MarkItDown MCP
markitdown-mcp is a lightweight MCP server for converting various URIs to Markdown.