diff --git a/nextcloud_mcp_server/app.py b/nextcloud_mcp_server/app.py index f5d0d8c2..5a01f745 100644 --- a/nextcloud_mcp_server/app.py +++ b/nextcloud_mcp_server/app.py @@ -2475,6 +2475,29 @@ def get_app(transport: str = "streamable-http", enabled_apps: list[str] | None = response = await call_next(request) return response + # Log the inbound User-Agent on management API and webhook receiver routes + # so we can tell which Astrolabe (or other PHP-side client) build is + # talking to the backend. Astrolabe sends ``Nextcloud-Astrolabe/``. + _UA_LOGGED_PATH_PREFIXES = ("/api/v1/", "/webhooks/nextcloud") + + @app.middleware("http") + async def log_client_user_agent(request, call_next): + path = request.url.path + if path.startswith(_UA_LOGGED_PATH_PREFIXES): + ua = request.headers.get("user-agent") or "(none)" + logger.info( + "%s %s from %s", + request.method, + path, + ua, + extra={ + "user_agent": ua, + "http_method": request.method, + "http_path": path, + }, + ) + return await call_next(request) + # Add CORS middleware to allow browser-based clients like MCP Inspector app.add_middleware( CORSMiddleware, # type: ignore[invalid-argument-type]