"""jarvis-tools — a tiny FastAPI app whose only job is to host the shared MCP
endpoint (mcp_server.py) on Railway, so every Claude (app, Code, phone) can reach
the shared Jarvis Drive folder through one connector. Same shape as the memory
service: mount the MCP doors + run its session manager from the lifespan.
"""
from __future__ import annotations

from contextlib import asynccontextmanager

from fastapi import FastAPI

import mcp_server


@asynccontextmanager
async def lifespan(app: FastAPI):
    import asyncio

    import memory_backup
    async with mcp_server.lifespan():
        backup_task = asyncio.create_task(memory_backup.scheduler())
        try:
            yield
        finally:
            backup_task.cancel()


app = FastAPI(title="jarvis-tools", lifespan=lifespan)


@app.get("/")
def health():
    return {"ok": True, "service": "jarvis-tools", "mcp": "/mcp"}


mcp_server.mount(app)
