From 5d1c63375b8d2b176bb1115186119a8172816421 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sun, 7 Dec 2025 08:37:55 +0000 Subject: [PATCH] MCP refactor Signed-off-by: GitHub --- server/api_server/api_server_start.py | 4 ++-- server/api_server/mcp_endpoint.py | 5 +---- server/models/event_instance.py | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/server/api_server/api_server_start.py b/server/api_server/api_server_start.py index 39b660dc..aeb91bbc 100755 --- a/server/api_server/api_server_start.py +++ b/server/api_server/api_server_start.py @@ -418,7 +418,7 @@ def api_devices_search(): if is_mac(query): device_data = get_device_data(query) - if device_data: + if device_data.status_code == 200: return jsonify({"success": True, "devices": [device_data.get_json()]}) else: return jsonify({"success": False, "error": "Device not found"}), 404 @@ -574,7 +574,7 @@ def api_trigger_scan(): @app.route('/mcp/sse/openapi.json', methods=['GET']) def api_openapi_spec(): if not is_authorized(): - return jsonify({"Success": False, "error": "Unauthorized"}), 401 + return jsonify({"success": False, "error": "Unauthorized"}), 401 return openapi_spec() diff --git a/server/api_server/mcp_endpoint.py b/server/api_server/mcp_endpoint.py index e1c5f9a7..773cd2c2 100644 --- a/server/api_server/mcp_endpoint.py +++ b/server/api_server/mcp_endpoint.py @@ -57,16 +57,13 @@ def openapi_spec(): # Sessions for SSE -_sessions = {} -_sessions_lock = __import__('threading').Lock() _openapi_spec_cache = None API_BASE_URL = f"http://localhost:{get_setting_value('GRAPHQL_PORT')}" def get_openapi_spec(): global _openapi_spec_cache - # Clear cache on each call for now to ensure fresh spec - _openapi_spec_cache = None + if _openapi_spec_cache: return _openapi_spec_cache try: diff --git a/server/models/event_instance.py b/server/models/event_instance.py index 548ee413..bdb5960f 100644 --- a/server/models/event_instance.py +++ b/server/models/event_instance.py @@ -32,6 +32,7 @@ class EventInstance: ORDER BY eve_DateTime DESC LIMIT ? """, (n,)).fetchall() + conn.close() return self._rows_to_list(rows) # --- Specific helper for last 10 ---