EDteam API Integration
This example demonstrates how to build a production-ready MCP server in Go that integrates with a real-world API, handles authentication, and follows best practices.Overview
The EDteam server showcases:- Authentication: Secure login and token management
- HTTP Client: Reusable HTTP request handling
- Multiple Endpoints: Integrating various API endpoints
- Error Handling: Robust error handling patterns
- Environment Variables: Secure credential management
- Production Patterns: Real-world API integration strategies
Project Structure
Data Models
Subscription Model
models.go
Course Model
HTTP Client
Reusable Request Function
http.go
- Handles both raw bytes and JSON marshaling
- Sets appropriate headers
- Manages authentication tokens
- Includes context for cancellation
- Properly closes response bodies
Authentication
Login Flow
login.go
API Integrations
Subscriptions
subscription.go
Courses
courses.go
Shopping Cart
shopping-cart.go
MCP Server Setup
Main Server
main.go
Tool: List Subscriptions
Tool: List Courses
Tool: Add to Shopping Cart
Environment Configuration
Setting Credentials
Claude Desktop Configuration
claude_desktop_config.json
Building and Running
Dependencies
go.mod
Build
Production Patterns
Error Handling
Context Propagation
Resource Cleanup
Type Safety
Security Best Practices
- Environment Variables: Never hardcode credentials
- Token Management: Store tokens securely, not in logs
- HTTPS Only: Always use HTTPS for API calls
- Error Messages: Don’t leak sensitive information in errors
- Logging: Use
os.Stderrfor logs (not stdout)
Testing
Unit Test Example
Key Takeaways
- Reusable HTTP Client: Create utilities for common operations
- Authentication First: Handle auth before registering tools
- Struct Tags: Use JSON tags for proper serialization
- Error Wrapping: Use
fmt.Errorfwith%wfor error chains - Environment Config: Use env vars for sensitive data
- Context Usage: Always propagate context for cancellation
Next Steps
- Explore Todo Management for state patterns
- Learn about External APIs
- See how to use with Ollama