"""FastAPI routes for the tool manifest registry.""" from __future__ import annotations from fastapi import APIRouter, HTTPException, status from app.tools.models import ToolManifest from app.tools.registry import registry router = APIRouter(prefix="/tools", tags=["tools"]) @router.get("", response_model=list[ToolManifest]) def list_tools() -> list[ToolManifest]: return registry.list() @router.get("/{tool_id}", response_model=ToolManifest) def get_tool(tool_id: str) -> ToolManifest: manifest = registry.get(tool_id) if manifest is None: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail=f"Tool '{tool_id}' not found", ) return manifest @router.post("", response_model=ToolManifest, status_code=status.HTTP_201_CREATED) def create_tool(manifest: ToolManifest) -> ToolManifest: if registry.get(manifest.id) is not None: raise HTTPException( status_code=status.HTTP_409_CONFLICT, detail=f"Tool '{manifest.id}' already exists", ) registry.register(manifest) return manifest