claude-agent-sdk-python
claude-agent-sdk-python copied to clipboard
create_sdk_mcp_server implicitly fails when receiving AudioContent, ResourceLink, EmbeddedResource content blocks
As per the official mcp SDK's mcp.types:
ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource
but the claude agent sdk (version 0.1.4) currently does this in the create_sdk_mcp_server function:
# Register call_tool handler to execute tools
@server.call_tool() # type: ignore[misc]
async def call_tool(name: str, arguments: dict[str, Any]) -> Any:
"""Execute a tool by name with given arguments."""
if name not in tool_map:
raise ValueError(f"Tool '{name}' not found")
tool_def = tool_map[name]
# Call the tool's handler with arguments
result = await tool_def.handler(arguments)
# Convert result to MCP format
# The decorator expects us to return the content, not a CallToolResult
# It will wrap our return value in CallToolResult
content: list[TextContent | ImageContent] = []
if "content" in result:
for item in result["content"]:
if item.get("type") == "text":
content.append(TextContent(type="text", text=item["text"]))
if item.get("type") == "image":
content.append(
ImageContent(
type="image",
data=item["data"],
mimeType=item["mimeType"],
)
)
# Return just the content list - the decorator wraps it
return content
That is, it assumes that the content is a TextContent or ImageContent.
- It should not implicitly fail when it stumbles upon for example an EmbeddedResource.
- Support for at the very least EmbeddedResource should probably be implemented. Currently I'm proxying the MCP call and adding the blob file to the agent's CWD which mostly works, but is a bit hacky and annoying.