For the complete documentation index, see llms.txt. This page is also available as Markdown.

Best Practices

Guidelines for production MCP servers.

Security Checklist 🔒

Authentication & Authorization

  • ✅ Use .withBasicAuth() for sensitive operations

  • ✅ Use .withApiKeyProvider() for programmatic access

  • ✅ Implement role-based access control in auth providers

  • ✅ Store credentials in environment variables, not code

  • ✅ Rotate credentials periodically

Network & Transport

  • ✅ Always use HTTPS in production

  • ✅ Configure CORS with specific origins (avoid *)

  • ✅ Use .withAllowedIPs() to restrict source networks for sensitive servers

  • ✅ Set appropriate request body size limits

  • ✅ Monitor for authentication failures

Server Management

  • ✅ Separate public and admin servers

  • ✅ Use different API keys per server

  • ✅ Log all authentication failures

  • ✅ Implement rate limiting if needed

  • ✅ Enable statistics for monitoring

Design Patterns

Multi-Server Architecture

Progressive Security

Annotation-Based Auto-Discovery

Monitoring & Observability

Health Check Endpoint

Performance Monitoring

Detailed Logging

Documentation

Tool Descriptions

Tool Arguments

Testing

Unit Tests

Integration Tests

Performance Optimization

Server Sizing

Caching

Tool Timeouts

Deployment

Environment Variables

Docker

Health Checks

Next Steps

Last updated