komodo_api_call fails with JSON body/params - type validation error #1

Open
opened 2025-12-26 14:08:19 -06:00 by b3nw · 0 comments
Owner

Bug Description

The komodo_api_call tool fails when receiving JSON body or params parameters from MCP clients due to type validation issues.

Error Message

Input should be a valid string [type=string_type, input_value={...}, input_type=dict]

Root Cause

The tool signature declares body and params parameters as str type, but when MCP clients pass JSON objects, they are automatically parsed into Python dictionaries before reaching the tool. This causes a type mismatch and validation failure.

Affected Code

The komodo_api_call function likely has a signature similar to:

@server.call_tool()
async def komodo_api_call(
    endpoint: str,
    method: str = "GET",
    params: str | None = None,  # <-- Only accepts str
    body: str | None = None,    # <-- Only accepts str
) -> list[TextContent]:

Solution

Update the function signature to accept Union[str, dict[str, Any]] for both params and body parameters:

@server.call_tool()
async def komodo_api_call(
    endpoint: str,
    method: str = "GET",
    params: str | dict[str, Any] | None = None,
    body: str | dict[str, Any] | None = None,
) -> list[TextContent]:
    # Handle both string and dict types
    if isinstance(params, str):
        params = json.loads(params)
    if isinstance(body, str):
        body = json.loads(body)
    # ... rest of implementation

Reference

This same issue was identified and fixed in the gitea-mcp-custom project:

Impact

This bug prevents users from making API calls with JSON body or params, severely limiting the functionality of the komodo_api_call tool.

## Bug Description The `komodo_api_call` tool fails when receiving JSON body or params parameters from MCP clients due to type validation issues. ## Error Message ``` Input should be a valid string [type=string_type, input_value={...}, input_type=dict] ``` ## Root Cause The tool signature declares `body` and `params` parameters as `str` type, but when MCP clients pass JSON objects, they are automatically parsed into Python dictionaries before reaching the tool. This causes a type mismatch and validation failure. ## Affected Code The `komodo_api_call` function likely has a signature similar to: ```python @server.call_tool() async def komodo_api_call( endpoint: str, method: str = "GET", params: str | None = None, # <-- Only accepts str body: str | None = None, # <-- Only accepts str ) -> list[TextContent]: ``` ## Solution Update the function signature to accept `Union[str, dict[str, Any]]` for both `params` and `body` parameters: ```python @server.call_tool() async def komodo_api_call( endpoint: str, method: str = "GET", params: str | dict[str, Any] | None = None, body: str | dict[str, Any] | None = None, ) -> list[TextContent]: # Handle both string and dict types if isinstance(params, str): params = json.loads(params) if isinstance(body, str): body = json.loads(body) # ... rest of implementation ``` ## Reference This same issue was identified and fixed in the gitea-mcp-custom project: - Issue: https://gitea.ext.ben.io/b3nw/gitea-mcp-custom/issues/1 - Fix commit: https://gitea.ext.ben.io/b3nw/gitea-mcp-custom/commit/f8eda211e607ae1cfb532a1bf37ff7fa82a3231e ## Impact This bug prevents users from making API calls with JSON body or params, severely limiting the functionality of the komodo_api_call tool.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: b3nw/komodo-mcp-custom#1