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:
24
server.py
24
server.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
import httpx
|
import httpx
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
from starlette.applications import Starlette
|
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
|
# Note: Return str (JSON) instead of dict to work around FastMCP/Gemini CLI
|
||||||
# schema compatibility issue with additionalProperties
|
# schema compatibility issue with additionalProperties
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def list_servers() -> str:
|
def list_servers() -> str:
|
||||||
"""Lists all servers (periphery nodes) connected to Komodo.
|
"""Lists all servers (periphery nodes) connected to Komodo.
|
||||||
@@ -198,9 +200,7 @@ def get_container_status(deployment: str) -> str:
|
|||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def komodo_api_call(
|
def komodo_api_call(
|
||||||
endpoint: str,
|
endpoint: str, request_type: str, params: str | dict[str, Any] = "{}"
|
||||||
request_type: str,
|
|
||||||
params: str = "{}"
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Execute a raw Komodo API call.
|
"""Execute a raw Komodo API call.
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ def komodo_api_call(
|
|||||||
Args:
|
Args:
|
||||||
endpoint: API endpoint - 'read', 'write', or 'execute'
|
endpoint: API endpoint - 'read', 'write', or 'execute'
|
||||||
request_type: Request type name (e.g., 'GetServer', 'Deploy', 'ListBuilds')
|
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:
|
Examples:
|
||||||
- Get server: endpoint='read', request_type='GetServer', params='{"server": "my-server"}'
|
- Get server: endpoint='read', request_type='GetServer', params='{"server": "my-server"}'
|
||||||
@@ -221,10 +221,17 @@ def komodo_api_call(
|
|||||||
return json.dumps(error)
|
return json.dumps(error)
|
||||||
|
|
||||||
if endpoint not in ("read", "write", "execute"):
|
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:
|
try:
|
||||||
parsed_params = json.loads(params) if params else {}
|
if isinstance(params, str):
|
||||||
|
parsed_params = json.loads(params) if params else {}
|
||||||
|
else:
|
||||||
|
parsed_params = params or {}
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
return json.dumps({"error": f"Invalid JSON in params: {e}"})
|
return json.dumps({"error": f"Invalid JSON in params: {e}"})
|
||||||
|
|
||||||
@@ -237,7 +244,9 @@ async def health(request):
|
|||||||
"""Health check endpoint for Docker."""
|
"""Health check endpoint for Docker."""
|
||||||
client, error = _get_client()
|
client, error = _get_client()
|
||||||
if error:
|
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"})
|
return JSONResponse({"status": "ok"})
|
||||||
|
|
||||||
|
|
||||||
@@ -262,4 +271,5 @@ app = create_app()
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
|
|||||||
Reference in New Issue
Block a user