Skip to content

Fix bug arising from instantiation of CallToolResult class #48

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

Merged

Conversation

meerkat-citronella
Copy link
Contributor

In mcp_aggregator.py, CallToolResult is being instantiated incorrectly. message is being passed as a string instead of content which should be a list of TextContent. It is causing the following error:

Traceback (most recent call last):
  File "/path/to/project/.venv/lib/python3.12/site-packages/mcp_agent/workflows/llm/augmented_llm.py", line 373, in call_tool
    result = await self.aggregator.call_tool(tool_name, tool_args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/.venv/lib/python3.12/site-packages/mcp_agent/agents/agent.py", line 205, in call_tool
    return await super().call_tool(name, arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/.venv/lib/python3.12/site-packages/mcp_agent/mcp/mcp_aggregator.py", line 323, in call_tool
    return await try_call_tool(server_connection.session)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/.venv/lib/python3.12/site-packages/mcp_agent/mcp/mcp_aggregator.py", line 306, in try_call_tool
    return CallToolResult(
    ^^^^^^^^^^^^^^^
  File "/path/to/project/.venv/lib/python3.12/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for CallToolResult
content
  Field required [type=missing, input_value={'message': "Failed to ca...er 'my_server': "}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing

Instantiating CallToolResult like:

CallToolResult(isError=True, message=f"my error msg")

is inconsistent with the other uses of CallToolResult in agent.py, augmented_llm.py, augmented_llm_openai.py, and swarm.py, which instantiate it thusly:

return CallToolResult(
                    isError=True,
                    content=[TextContent(type="text", text=f"my error msg")],
                )

I have updated the instantiation of CallToolResult to align with agent.py, augment_llm.py, etc. and the above error no longer occurs.

Copy link
Collaborator

@saqadri saqadri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome catch, thank you @meerkat-citronella!

@saqadri saqadri merged commit aac0211 into lastmile-ai:main Mar 10, 2025
4 checks passed
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