Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] MCP ToolCollection raises KeyError: 'type' #626

Open
gonzoramos opened this issue Feb 12, 2025 · 4 comments
Open

[BUG] MCP ToolCollection raises KeyError: 'type' #626

gonzoramos opened this issue Feb 12, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@gonzoramos
Copy link

gonzoramos commented Feb 12, 2025

Describe the bug
When loading an MCP tool (e.g. mcp_server_tavily), an exception occurs in _generate_tool_inputs(...). key "type" is not found.

Code to reproduce the error

# Load an MCP server like so
server_parameters = StdioServerParameters(
    command="python",
    args=["mcp_server_tavily.py"],
)

# then see what tools it exposes
with ToolCollection.from_mcp(server_parameters) as toolset:

    for tool in [*toolset.tools]:
        print(tool.name)

Error logs (if any)

  File ".../lib/python3.11/site-packages/mcpadapt/smolagents_adapter.py", line 30, in <dictcomp>
    k: {"type": v["type"], "description": v.get("description", "")}
                ~^^^^^^^^
KeyError: 'type'

Expected behavior
No exception

Packages version:
smolagents==1.8.1

Additional context
Add any other context about the problem here.

@gonzoramos gonzoramos added the bug Something isn't working label Feb 12, 2025
@gonzoramos
Copy link
Author

This edit fixed the exception, but I am not sure if it causes a regression:

def _generate_tool_inputs(resolved_json_schema: dict[str, Any]) -> dict[str, str]:
    """
    takes an json_schema as used in the MCP protocol and return an inputs dict for
    smolagents tools. see AUTHORIZED_TYPES in smolagents.tools for the types allowed.
    Note that we consider the json_schema to already have $ref resolved with jsonref for
    example.
    """
    
    # debuging
    items = resolved_json_schema.items()
    print(items)

    return {
        # TODO: use google-docstring-parser to parse description of args and pass it here...
        k: {"type": v["type"] if "type" in v else "object", "description": v.get("description", "")}
        for k, v in resolved_json_schema.items()
    }

@aymeric-roucher
Copy link
Collaborator

@grll what do you think, should we merge this change?

@sysradium
Copy link
Contributor

I would carefully check beforehand : 🤔

@grll
Copy link
Contributor

grll commented Feb 13, 2025

I need to find the root cause first, is it because we are not exposing the type as we should in mcpadapt?

@albertvillanova albertvillanova changed the title [BUG] [BUG] MCP ToolCollection raises KeyError: 'type' Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants