from pathlib import Path from fastmcp import FastMCP fastapi_uv_docker_server = FastMCP("fastapi-uv-docker") _REFERENCE_DIR = ( Path(__file__).resolve().parents[4] / "skills" / "fastapi-uv-docker" / "references" ) _REFERENCE_FILES = { "fastapi_best_practices": _REFERENCE_DIR / "fastapi-best-practices.md", "uv_project_layout": _REFERENCE_DIR / "uv-project-layout.md", "uvicorn_settings": _REFERENCE_DIR / "uvicorn-settings.md", "docker_cloud_native": _REFERENCE_DIR / "docker-cloud-native.md", } def _load_reference_bundle() -> dict[str, str]: bundle: dict[str, str] = {} for key, path in _REFERENCE_FILES.items(): bundle[key] = path.read_text(encoding="utf-8") return bundle @fastapi_uv_docker_server.resource("resource://skills/fastapi_uv_docker/overview") def fastapi_overview() -> dict: """Return high-level intent for FastAPI plus uv plus Docker migration.""" return { "id": "fastapi-uv-docker", "intent": "Migrate projects toward cloud-native FastAPI architecture managed by uv.", "focus": [ "src package layout", "uv-based dependency and lock management", "container-ready runtime conventions", ], } @fastapi_uv_docker_server.resource("resource://skills/fastapi_uv_docker/rules") def fastapi_rules() -> dict: """Return migration rules for stable FastAPI service architecture.""" return { "rules": [ "Prefer src layout and installable package boundaries.", "Use app factory and lifespan hooks for startup/shutdown ownership.", "Keep runtime configuration in environment-backed settings.", "Use uv lockfile and avoid drift between local and container environments.", ] } @fastapi_uv_docker_server.resource("resource://skills/fastapi_uv_docker/checklist") def fastapi_checklist() -> dict: """Return a compact migration checklist for FastAPI plus uv plus Docker.""" return { "checklist": [ "Audit current project manager, layout, and runtime settings.", "Establish uv project metadata and lockfile ownership.", "Implement app factory, lifespan, and health endpoints.", "Create multi-stage Docker image with non-root runtime user.", ] } @fastapi_uv_docker_server.resource("resource://skills/fastapi_uv_docker/references") def fastapi_references() -> dict: """Return bundled references for detailed implementation guidance.""" return { "sources": {key: str(path) for key, path in _REFERENCE_FILES.items()}, "format": "markdown", "content": _load_reference_bundle(), } @fastapi_uv_docker_server.tool() def fastapi_uv_docker_mvp_checklist(current_state: str = "bare python project") -> list[str]: """Return a compact migration checklist for FastAPI + uv + Docker.""" return [ f"Current state: {current_state}", "Create src/ package layout for the FastAPI app.", "Manage dependencies with uv and keep uv.lock committed.", "Use an app factory and lifespan hooks.", "Add /healthz endpoint for operational checks.", "Build with a multi-stage Dockerfile and run as non-root user.", ]