Skip to content

labs/module4/notebooks/1_mcp.ipynb: AttributeError in call_tool — stale MCP SDK return shape #57

@ManojRamani

Description

@ManojRamani

Summary

Running the call_tool cell in labs/module4/notebooks/1_mcp.ipynb raises:

AttributeError: 'list' object has no attribute 'model_dump_json'

The notebook is built against an older version of the mcp Python SDK where FastMCP.call_tool returned Sequence[ContentBlock]. Current SDK (mcp==1.26.0) returns a tuple (list[ContentBlock], dict)(content, structured_result). Iterating the tuple yields the list (no .model_dump_json) and the dict, both of which fail.

Repro

  1. Branch: main
  2. Open labs/module4/notebooks/1_mcp.ipynb
  3. Run the cell containing:
    async def call_tool(name, arguments):
        results = await mcp_server.call_tool(name, arguments)
        for result in results:
            print(result.model_dump_json(indent=2))
    asyncio.run(call_tool("get_alerts", {"state": "CA"}))

Environment

  • Python 3.12.8
  • mcp==1.26.0
  • Windows 11 / WSL-less (native)

Root cause

mcp.server.fastmcp.FastMCP.call_tool signature:

async def call_tool(self, name, arguments) -> Sequence[ContentBlock] | dict[str, Any]

But the runtime returns a 2-tuple (content, structured):

type(results): tuple
len(results): 2
  [0] type=list, value=[TextContent(...)]
  [1] type=dict, value={'result': '...'}

Proposed fix

Update the cell to unpack:

async def call_tool(name: str, arguments: Dict[str, Any]) -> None:
    content, structured = await mcp_server.call_tool(name, arguments)
    for result in content:
        print(result.model_dump_json(indent=2))

Also check other call_tool usages in the notebook (and any sibling notebooks) for the same drift.

Scope

Limited to labs/module4/notebooks/1_mcp.ipynb — will expand if the same pattern is present elsewhere after audit.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions