Skip to content

feat: production readiness — health checks, uv migration, middleware fixes#7

Open
BeArchiTek wants to merge 2 commits intoCloud-Temple:mainfrom
BeArchiTek:feat/prod-readiness-improvements
Open

feat: production readiness — health checks, uv migration, middleware fixes#7
BeArchiTek wants to merge 2 commits intoCloud-Temple:mainfrom
BeArchiTek:feat/prod-readiness-improvements

Conversation

@BeArchiTek
Copy link
Copy Markdown

@BeArchiTek BeArchiTek commented Apr 14, 2026

Summary

Supersedes #6 with additional fixes discovered during testing.

  • /health endpoint now probes both S3 and LLMaaS (was S3-only), returns healthy/degraded/unhealthy with per-service detail
  • CLI health command uses HTTP /health directly instead of full MCP protocol handshake — faster, no auth needed
  • Audit middleware moved before Auth in the ASGI stack to capture 403 rejections in audit logs
  • Migrated from requirements.txt to pyproject.toml + uv.lock — single source of truth for dependencies
  • Dockerfile uses uv sync --frozen with two-step layer caching (deps layer cached separately from source)
  • Added .mcp.json to .gitignore

From #6 (unchanged)

  • RequestIdMiddleware — UUID correlation per request (X-Request-Id header)
  • MetricsMiddleware/metrics in Prometheus + JSON format
  • ResponseLimitMiddleware — truncates responses > 512 KB
  • AuditMiddleware — structured JSON audit trail
  • Config validation — fail-fast startup for misconfigured ports, S3, LLM, etc.
  • MCP tool annotationsreadOnlyHint, destructiveHint, idempotentHint on all 38 tools
  • 36 unit tests — middleware + config validation, all passing

Test plan

  • uv run python -m pytest tests/ — 36/36 passing
  • docker compose build — multi-stage build with uv sync --frozen
  • curl localhost:8080/health — returns S3 + LLMaaS status
  • curl localhost:8080/metrics — Prometheus format output
  • X-Request-Id header present on responses
  • python scripts/mcp_cli.py health — uses HTTP endpoint, shows both services
  • 403 rejections now appear in audit logs

BeArchiTek and others added 2 commits April 13, 2026 15:16
Inspired by opsmill/infrahub-mcp#62, this adds production-readiness
improvements to the MCP server:

Middleware stack (new src/live_mem/middleware.py):
- RequestIdMiddleware: UUID correlation ID per request (contextvars),
  exposed as X-Request-Id response header
- MetricsMiddleware: per-path request counts, error rates, latency;
  /metrics endpoint in Prometheus and JSON formats
- ResponseLimitMiddleware: truncates responses exceeding configurable
  limit (default 512 KB) with structured JSON error for JSON responses
- AuditMiddleware: structured JSON audit trail (who, what, when) on a
  dedicated live_mem.audit logger

Health endpoint:
- /health now probes S3 connectivity and returns 503 with specific
  failure reason when S3 is unreachable (was always returning 200)

Structured logging:
- JSON log formatter for production log aggregation (ELK, Datadog)
- LoggingMiddleware emits structured entries with request_id, client
  identity, method, path, status, latency

Configuration:
- Startup validation: port range, S3 all-or-nothing, URL format,
  LLM pair consistency, consolidation ranges, temperature bounds
- Fail-fast with clear error messages on misconfiguration
- New RESPONSE_MAX_BYTES setting

Tool annotations:
- All 38 MCP tools annotated with readOnlyHint, destructiveHint,
  and idempotentHint per MCP spec (ToolAnnotations)

Docker:
- Multi-stage build: builder installs deps, runtime copies only the
  venv — no pip/setuptools in production image
- PYTHONDONTWRITEBYTECODE and PYTHONUNBUFFERED for container hygiene

Tests:
- 36 unit tests covering all new middleware, config validation
…ware fix

- /health endpoint now probes both S3 and LLMaaS (was S3-only)
- CLI health command uses HTTP /health directly instead of MCP protocol
- Audit middleware moved before Auth to capture 403 rejections
- Migrated from requirements.txt to pyproject.toml + uv.lock
- Dockerfile uses uv sync --frozen with Docker layer caching
- Added .mcp.json to .gitignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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