From 8211816b37af415df3abbe5012113084c931c82e Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Tue, 3 Feb 2026 16:51:31 +0100 Subject: [PATCH] feat(mcp): Expose OpenAPI spec as a resource (netalertx://api/openapi.json) --- server/api_server/mcp_endpoint.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/api_server/mcp_endpoint.py b/server/api_server/mcp_endpoint.py index db65ebe3..827338a2 100644 --- a/server/api_server/mcp_endpoint.py +++ b/server/api_server/mcp_endpoint.py @@ -795,8 +795,17 @@ def get_log_dir() -> str: def _list_resources() -> List[Dict[str, Any]]: - """List available MCP resources (read-only data like logs).""" + """List available MCP resources (read-only data like logs and API spec).""" resources = [] + + # API Specification + resources.append({ + "uri": "netalertx://api/openapi.json", + "name": "OpenAPI Specification", + "description": "The full OpenAPI 3.1 specification for the NetAlertX API and MCP tools", + "mimeType": "application/json" + }) + log_dir = get_log_dir() if not log_dir: return resources @@ -840,6 +849,16 @@ def _list_resources() -> List[Dict[str, Any]]: def _read_resource(uri: str) -> List[Dict[str, Any]]: """Read a resource by URI.""" + # Handle API Specification + if uri == "netalertx://api/openapi.json": + from flask import current_app + spec = get_openapi_spec(flask_app=current_app) + return [{ + "uri": uri, + "mimeType": "application/json", + "text": json.dumps(spec, indent=2) + }] + log_dir = get_log_dir() if not log_dir: return [{"uri": uri, "text": "Error: NETALERTX_LOG directory not configured"}]