Skip to content

Conversation

electrocucaracha
Copy link

The current CrewAI adapter implementation requires passing all the values for arguments that don't have a default value, but fails when the MCP tool provides an optional argument. For example, the following code:

@mcp.tool()
def echo_tool(
    id: int | float | None,
    text: str = Field(description="The text to echo"),
) -> str:
    pass

Results in the following error

starting echo server
[06/11/25 18:23:31] INFO     Processing request of type ListToolsRequest                                                                                                                                                                                                                                      server.py:551
                    INFO     Processing request of type ListToolsRequest                                                                                                                                                                                                                                      server.py:551
[CrewAIMCPTool(name='echo_tool', description="Tool Name: echo_tool\nTool Arguments: {'properties': {'id': {'anyOf': [{'type': 'integer'}, {'type': 'number'}, {'type': 'null'}], 'description': '', 'enum': None, 'items': None, 'properties': {}, 'title': 'Id'}, 'text': {'anyOf': [], 'description': 'The text to echo', 'enum': None, 'items': None, 'properties': {}, 'title': 'Text', 'type': 'string'}}, 'required': ['id', 'text'], 'title': 'echo_toolArguments', 'type': 'object'}\nTool Description: Echo the input text\n\n    Args:\n        id (int|float|None): (Optional) Id\n        text (str): The text to echo\n\n    Returns:\n        str: The echoed text\n    ", args_schema=<class 'mcpadapt.utils.modeling.echo_toolArguments'>, description_updated=False, cache_function=<function BaseTool.<lambda> at 0x108f2d5a0>, result_as_answer=False)]
Using Tool: echo_tool
                    INFO     Processing request of type CallToolRequest                                                                                                                                                                                                                                       server.py:551
Error executing tool echo_tool: 1 validation error for echo_toolArguments
id
  Field required [type=missing, input_value={'text': 'hello'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing

When the tool doesn't provide an id value, like tools[0].run(text="hello")

This change modifies the way to populate filtered_kwargs variable utilizing the schema_properties values instead of the kwargs

@grll
Copy link
Owner

grll commented Jun 14, 2025

Hey @electrocucaracha, thanks a lot for your contribution! I understand the issue however I am just wondering as we are using in this case a python function as the basis for the tool, in python the behavior of failing if id is not specified would be the expected behavior, wouldnt it?

@electrocucaracha
Copy link
Author

Hey @electrocucaracha, thanks a lot for your contribution! I understand the issue however I am just wondering as we are using in this case a python function as the basis for the tool, in python the behavior of failing if id is not specified would be the expected behavior, wouldnt it?

Do you mean that maybe other programming languages that don't allow this kind Python unique nullable required case could raise an error when they are called? I can figure out, but if this an exception I guess it needs to be address in the MCP SDK

The current implementation of the CrewAI adapter doesn't cover the
scenario where the argument is optional. This change fixes that and
provides an assertion to validate what is received by the MCP echo
server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants