Skip to content

v0.5.0: Production Deployment System#14

Merged
KeshavVarad merged 1 commit intomainfrom
feature/v0.5.0-deployment
Nov 4, 2025
Merged

v0.5.0: Production Deployment System#14
KeshavVarad merged 1 commit intomainfrom
feature/v0.5.0-deployment

Conversation

@KeshavVarad
Copy link
Copy Markdown
Owner

🚀 v0.5.0: Production Deployment System

Complete deployment tooling for Docker and cloud platforms with health checks, graceful shutdown, and one-click deployment commands.


What's New

🏥 Health Check System

Production-ready health monitoring with Kubernetes-compatible endpoints:

  • Liveness checks: Is the app running?
  • Readiness checks: Is the app ready to serve traffic?
  • Custom check registration with status tracking
  • Automatic duration measurement
from nextmcp.deployment import HealthCheck

health = HealthCheck()

def check_database():
    return db.is_connected()

health.add_readiness_check("database", check_database)

🛑 Graceful Shutdown

Clean application termination with resource cleanup:

  • SIGTERM/SIGINT signal handling
  • Configurable shutdown timeout
  • Async and sync cleanup handlers
  • Prevents data loss during deployment
from nextmcp.deployment import GracefulShutdown

shutdown = GracefulShutdown(timeout=30.0)
shutdown.add_cleanup_handler(close_database)
shutdown.register()

🐳 Docker Templates

Optimized Docker deployment with one command:

  • Multi-stage Dockerfile (<100MB images)
  • docker-compose.yml with optional PostgreSQL/Redis
  • Non-root user security
  • Built-in health checks
mcp init --docker --with-database

🚢 One-Command Deployment

Deploy to multiple platforms instantly:

  • Docker: Local development
  • Railway: Automated deployment
  • Render: Git-based deployment
  • Fly.io: Edge deployment
mcp deploy --platform docker
mcp deploy --platform railway

🎯 Enhanced CLI

# Generate Docker files
mcp init --docker --with-database --with-redis

# Deploy with auto-detection
mcp deploy

# Deploy to specific platform
mcp deploy --platform fly

📊 Stats

  • +3,082 lines of production-ready code
  • +66 tests (21 health, 15 lifecycle, 30 templates)
  • 363/363 tests passing
  • 100% backward compatible
  • 2 complete examples with READMEs

📁 Changes

Core Components

  • nextmcp/deployment/health.py - Health check system (210 lines)
  • nextmcp/deployment/lifecycle.py - Graceful shutdown (145 lines)
  • nextmcp/deployment/templates.py - Template rendering (174 lines)

Docker Templates

  • nextmcp/templates/docker/Dockerfile.template - Multi-stage build
  • nextmcp/templates/docker/docker-compose.yml.template - Dev environment
  • nextmcp/templates/docker/.dockerignore.template - Optimized context

CLI Enhancements

  • Enhanced mcp init with --docker, --with-database, --with-redis
  • New mcp deploy command with platform auto-detection

Examples

  • examples/deployment_simple/ - Basic deployment with health checks
  • examples/deployment_docker/ - Production example with database

Tests

  • tests/test_deployment_health.py - 21 health check tests
  • tests/test_deployment_lifecycle.py - 15 lifecycle tests
  • tests/test_deployment_templates.py - 30 template tests

🎬 Demo

Quick Start

# Create new project
mcp init my-app

# Generate Docker files
cd my-app
mcp init --docker --with-database

# Deploy locally
mcp deploy --platform docker

# View health
curl http://localhost:8000/health

Example Output

{
  "status": "healthy",
  "uptime_seconds": 123.45,
  "checks": {
    "database": {
      "status": "healthy",
      "message": "Database connection is healthy",
      "duration_ms": 2.34
    }
  }
}

🏗️ Platform Support

Platform Status CLI Required Notes
Docker ✅ Full docker, docker compose Local development
Railway ✅ Full railway Automated deployment
Render ✅ Full render Git-based deployment
Fly.io ✅ Full flyctl Edge deployment
Kubernetes ✅ Ready kubectl Health checks included

🧪 Testing

All tests passing:

$ pytest tests/ -v
363 passed in 5.34s ✓

Test coverage:

  • ✅ Health check creation and aggregation
  • ✅ Liveness and readiness checks
  • ✅ Signal handling and cleanup
  • ✅ Template rendering with variables/conditionals
  • ✅ Docker template generation
  • ✅ Auto-detection of project config

📖 Documentation

Each example includes comprehensive README with:

  • Quick start guide
  • Deployment instructions
  • Troubleshooting section
  • Production checklist
  • Platform-specific tutorials

🔄 Migration Guide

No breaking changes! This release is 100% backward compatible.

To use new features:

# Add to existing app
from nextmcp.deployment import HealthCheck, GracefulShutdown

app = NextMCP("my-app")
health = HealthCheck()
shutdown = GracefulShutdown()
shutdown.register()

🎯 Next Steps

After merging:

  1. ✅ Merge to main
  2. ✅ Create release v0.5.0
  3. ✅ Publish to PyPI
  4. 📚 Update main README with deployment docs
  5. 🎥 Create deployment tutorial video (optional)

✅ Pre-merge Checklist

  • All tests passing (363/363)
  • Linting clean (ruff + black)
  • Pre-commit hook passing
  • Examples tested
  • CHANGELOG updated
  • Version bumped (0.4.0 → 0.5.0)
  • Comprehensive commit message
  • Two complete examples with READMEs

Ready to merge! 🚀

Complete deployment tooling for Docker and cloud platforms with health
checks, graceful shutdown, and CLI commands for one-click deployment.

Core Features:
- Health check system with liveness and readiness probes
- Graceful shutdown with SIGTERM/SIGINT handling
- Template system for Dockerfile, docker-compose.yml generation
- CLI commands: `mcp init --docker` and `mcp deploy`
- Platform support: Docker, Railway, Render, Fly.io, Kubernetes

Components Added:

Deployment Infrastructure (nextmcp/deployment/):
- health.py: HealthCheck system with liveness/readiness checks
  - Custom check registration
  - Status types: Healthy, Unhealthy, Degraded
  - Duration measurement for checks
  - Kubernetes-compatible health endpoints

- lifecycle.py: GracefulShutdown for clean termination
  - Signal handler registration (SIGTERM/SIGINT)
  - Cleanup handler management
  - Async and sync support
  - Configurable timeout

- templates.py: TemplateRenderer for config generation
  - Jinja2-like syntax (variables, defaults, conditionals)
  - Auto-detection of project configuration
  - Template variable extraction

Docker Templates (nextmcp/templates/docker/):
- Dockerfile.template: Multi-stage optimized build
  - Python 3.10 slim base (~100MB)
  - Non-root user (UID 1000)
  - Built-in health check

- docker-compose.yml.template: Local dev environment
  - Optional PostgreSQL integration
  - Optional Redis integration
  - Volume management
  - Health checks for all services

- .dockerignore.template: Minimal context

CLI Enhancements (nextmcp/cli.py):
- `mcp init --docker`: Generate Docker deployment files
  - Auto-detects app configuration
  - --with-database: Include PostgreSQL
  - --with-redis: Include Redis
  - --port: Custom port

- `mcp deploy`: One-command deployment
  - Platform auto-detection
  - Supports: docker, railway, render, fly
  - Build control
  - CLI validation

Examples:
- deployment_simple/: Basic deployment with health checks
  - Simple health checks
  - Graceful shutdown
  - Production logging
  - Comprehensive README

- deployment_docker/: Production-ready example
  - Database integration
  - Metrics collection
  - Advanced health checks (disk, database)
  - Multi-service Docker Compose
  - Environment configuration

Tests (66 new tests):
- test_deployment_health.py: 21 tests
  - Health check creation and status
  - Liveness and readiness checks
  - Multiple check handling
  - Error handling

- test_deployment_lifecycle.py: 15 tests
  - Graceful shutdown initialization
  - Signal handling
  - Cleanup handlers (async/sync)
  - Error handling

- test_deployment_templates.py: 30 tests
  - Template rendering
  - Variable substitution and defaults
  - Conditionals
  - Docker template rendering
  - Auto-detection

Deployment Workflow:
  cd my-mcp-project
  mcp init --docker --with-database
  mcp deploy --platform docker

Health Checks:
  GET /health        # Liveness probe
  GET /health/ready  # Readiness probe

Platform Support:
  ✅ Docker - Local development
  ✅ Railway - Automated deployment
  ✅ Render - Git-based deployment
  ✅ Fly.io - Edge deployment
  ✅ Kubernetes - Health checks included

Test Results:
  - 363/363 tests passing
  - 66 new deployment tests
  - 100% backward compatible

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@KeshavVarad KeshavVarad merged commit a4e9916 into main Nov 4, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant