From e09af9c9bb9cdc9a119ed5ce02148ec4f7779bc7 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sat, 18 Jul 2026 16:59:30 +0200 Subject: [PATCH] feat(mcp): routes GET/PUT/test du catalogue de serveurs Co-Authored-By: Claude Opus 4.8 --- backend/app/main.py | 3 ++- backend/app/routes/mcp.py | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 backend/app/routes/mcp.py diff --git a/backend/app/main.py b/backend/app/main.py index 51cdc20..0c1b97c 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -15,7 +15,7 @@ from fastapi.staticfiles import StaticFiles from . import agent_config, coder, db, rag from .config import settings from .ollama_client import ollama -from .routes import benchmark, chat, config, files, git, models, sessions, shell, system +from .routes import benchmark, chat, config, files, git, mcp, models, sessions, shell, system async def _warm_default_model() -> None: @@ -77,6 +77,7 @@ app.include_router(shell.router) app.include_router(system.router) app.include_router(benchmark.router) app.include_router(git.router) +app.include_router(mcp.router) @app.get("/api/health") diff --git a/backend/app/routes/mcp.py b/backend/app/routes/mcp.py new file mode 100644 index 0000000..5681766 --- /dev/null +++ b/backend/app/routes/mcp.py @@ -0,0 +1,54 @@ +"""Routes de configuration des serveurs MCP (catalogue + toggles).""" +from __future__ import annotations + +from fastapi import APIRouter, HTTPException +from pydantic import BaseModel + +from ..mcp_client import CATALOG, get_mcp_state, manager, set_mcp_state + +router = APIRouter(prefix="/api/mcp", tags=["mcp"]) + + +def _payload() -> dict: + state = get_mcp_state() + statuses = manager.statuses() + return { + "servers": [ + { + "id": sid, + "label": entry["label"], + "description": entry["description"], + "url_param": entry["url_param"], + "env_params": entry["env_params"], + "enabled": state[sid]["enabled"], + "params": state[sid]["params"], + **statuses[sid], + } + for sid, entry in CATALOG.items() + ] + } + + +@router.get("") +async def list_servers() -> dict: + return _payload() + + +class McpUpdate(BaseModel): + enabled: bool + params: dict = {} + + +@router.put("/{sid}") +async def update_server(sid: str, req: McpUpdate) -> dict: + if sid not in CATALOG: + raise HTTPException(404, "serveur inconnu") + set_mcp_state(sid, enabled=req.enabled, params=req.params) + return _payload() + + +@router.post("/{sid}/test") +async def test_server(sid: str) -> dict: + if sid not in CATALOG: + raise HTTPException(404, "serveur inconnu") + return await manager.test_server(sid)