Skip to content

MCP call_tool method returns CallToolResult object instead of content #1365

Open
@addypy

Description

@addypy

Initial Checks

Description

When using tools via MCP servers, the call_tool method returns the raw CallToolResult object instead of its content, causing inconsistency with how regular tools work:

Without MCP (regular Tool):

ToolReturnPart(tool_name='get_weather_forecast', content='Weather Forecast Response\nAction: search, Domain: weather-...')

With MCP Server:

ToolReturnPart(tool_name='get_weather_forecast', content=CallToolResult(meta=None, content=[TextContent(type='text', text='Weather Forecast Response\nAction: search, Domain: weather-...')]))

This inconsistency causes issues for those who expect the same structure regardless of how tools are implemented.

Proposed Solution

Modify the call_tool method in the MCPServer class to return result.content instead of the raw CallToolResult object. This would ensure consistent behavior between MCP tools and regular tools.

Affected Components

  • pydantic_ai_slim/pydantic_ai/mcp.py

### Example Code

```Python

Python, Pydantic AI & LLM client version

python3.11
pydantic-ai==0.0.52
openai:gpt-4o,llama3.1:8b

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions