mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
feat(mcp): Expose OpenAPI spec as a resource (netalertx://api/openapi.json)
This commit is contained in:
@@ -795,8 +795,17 @@ def get_log_dir() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _list_resources() -> List[Dict[str, Any]]:
|
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 = []
|
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()
|
log_dir = get_log_dir()
|
||||||
if not log_dir:
|
if not log_dir:
|
||||||
return resources
|
return resources
|
||||||
@@ -840,6 +849,16 @@ def _list_resources() -> List[Dict[str, Any]]:
|
|||||||
|
|
||||||
def _read_resource(uri: str) -> List[Dict[str, Any]]:
|
def _read_resource(uri: str) -> List[Dict[str, Any]]:
|
||||||
"""Read a resource by URI."""
|
"""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()
|
log_dir = get_log_dir()
|
||||||
if not log_dir:
|
if not log_dir:
|
||||||
return [{"uri": uri, "text": "Error: NETALERTX_LOG directory not configured"}]
|
return [{"uri": uri, "text": "Error: NETALERTX_LOG directory not configured"}]
|
||||||
|
|||||||
Reference in New Issue
Block a user