fix: accept both str and dict params in komodo_api_call
All checks were successful
Build and Push Komodo MCP Docker Image / build (push) Successful in 8s
All checks were successful
Build and Push Komodo MCP Docker Image / build (push) Successful in 8s
Resolves issue #1 - allows params parameter to accept either JSON string or dict type, fixing type validation errors when calling the function.
This commit is contained in:
22
server.py
22
server.py
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
import httpx
|
||||
from fastmcp import FastMCP
|
||||
from starlette.applications import Starlette
|
||||
@@ -145,6 +146,7 @@ def get_api_reference() -> str:
|
||||
# Note: Return str (JSON) instead of dict to work around FastMCP/Gemini CLI
|
||||
# schema compatibility issue with additionalProperties
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def list_servers() -> str:
|
||||
"""Lists all servers (periphery nodes) connected to Komodo.
|
||||
@@ -198,9 +200,7 @@ def get_container_status(deployment: str) -> str:
|
||||
|
||||
@mcp.tool()
|
||||
def komodo_api_call(
|
||||
endpoint: str,
|
||||
request_type: str,
|
||||
params: str = "{}"
|
||||
endpoint: str, request_type: str, params: str | dict[str, Any] = "{}"
|
||||
) -> str:
|
||||
"""Execute a raw Komodo API call.
|
||||
|
||||
@@ -209,7 +209,7 @@ def komodo_api_call(
|
||||
Args:
|
||||
endpoint: API endpoint - 'read', 'write', or 'execute'
|
||||
request_type: Request type name (e.g., 'GetServer', 'Deploy', 'ListBuilds')
|
||||
params: Request parameters as a JSON string (default: "{}")
|
||||
params: Request parameters as a JSON string or dict (default: "{}")
|
||||
|
||||
Examples:
|
||||
- Get server: endpoint='read', request_type='GetServer', params='{"server": "my-server"}'
|
||||
@@ -221,10 +221,17 @@ def komodo_api_call(
|
||||
return json.dumps(error)
|
||||
|
||||
if endpoint not in ("read", "write", "execute"):
|
||||
return json.dumps({"error": f"Invalid endpoint '{endpoint}'. Use 'read', 'write', or 'execute'."})
|
||||
return json.dumps(
|
||||
{
|
||||
"error": f"Invalid endpoint '{endpoint}'. Use 'read', 'write', or 'execute'."
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
if isinstance(params, str):
|
||||
parsed_params = json.loads(params) if params else {}
|
||||
else:
|
||||
parsed_params = params or {}
|
||||
except json.JSONDecodeError as e:
|
||||
return json.dumps({"error": f"Invalid JSON in params: {e}"})
|
||||
|
||||
@@ -237,7 +244,9 @@ async def health(request):
|
||||
"""Health check endpoint for Docker."""
|
||||
client, error = _get_client()
|
||||
if error:
|
||||
return JSONResponse({"status": "degraded", "error": error["error"]}, status_code=503)
|
||||
return JSONResponse(
|
||||
{"status": "degraded", "error": error["error"]}, status_code=503
|
||||
)
|
||||
return JSONResponse({"status": "ok"})
|
||||
|
||||
|
||||
@@ -262,4 +271,5 @@ app = create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
|
||||
Reference in New Issue
Block a user