{"record":{"id":"5d5e720f68d12ca2","repo":"PrefectHQ/fastmcp","slug":"unsupported-content-type-for-anthropic-type-item","errorCode":null,"errorMessage":"Unsupported content type for Anthropic: {type(item).__name__}","messagePattern":"Unsupported content type for Anthropic: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py","lineNumber":242,"sourceCode":"                                TextBlockParam(type=\"text\", text=sub_item.text)\n                                for sub_item in item.content\n                                if isinstance(sub_item, TextContent)\n                            ]\n                            if len(text_blocks) == 1:\n                                result_content = text_blocks[0][\"text\"]\n                            elif text_blocks:\n                                result_content = text_blocks\n\n                        content_blocks.append(\n                            ToolResultBlockParam(\n                                type=\"tool_result\",\n                                tool_use_id=item.tool_use_id,\n                                content=result_content,\n                                is_error=item.is_error if item.is_error else False,\n                            )\n                        )\n                    else:\n                        raise ValueError(\n                            f\"Unsupported content type for Anthropic: {type(item).__name__}\"\n                        )\n\n                if content_blocks:\n                    anthropic_messages.append(\n                        MessageParam(\n                            role=message.role,\n                            content=content_blocks,\n                        )\n                    )\n                continue\n\n            # Handle ToolUseContent (assistant's tool calls)\n            if isinstance(content, ToolUseContent):\n                anthropic_messages.append(\n                    MessageParam(\n                        role=\"assistant\",\n                        content=[","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py#L224-L260","documentation":"ValueError from `_convert_to_anthropic_messages` (list-content branch): a content block of a type the Anthropic converter doesn't recognize was encountered, and it names the concrete class so you can see what leaked in.","triggerScenarios":"A SamplingMessage's list content contains a block that is not TextContent, ImageContent, AudioContent, or ToolResultContent (e.g. EmbeddedResource, AudioContent subclasses, or a custom content type) passed to AnthropicSamplingHandler.","commonSituations":"Servers returning EmbeddedResource or other MCP content types in sampling contexts; custom middleware injecting non-standard blocks; version drift where newer MCP content types predate the converter.","solutions":["Inspect `type(item).__name__` from the message to identify the offending block","Pre-process messages to convert/strip unsupported blocks (e.g. extract text from EmbeddedResource)","Update fastmcp-slim — newer versions may support the type","Report or subclass the handler to add conversion for the custom type"],"exampleFix":"// before\nmessages = [SamplingMessage(role=\"user\", content=[EmbeddedResource(...)])]  # raises\n\n// after\ntext = resource_to_text(EmbeddedResource(...))\nmessages = [SamplingMessage(role=\"user\", content=[TextContent(type=\"text\", text=text)])]","handlingStrategy":"type-guard","validationCode":"ALLOWED = (TextContent, ImageContent, AudioContent, ToolResultContent)\nbad = [b for m in messages for b in as_list(m.content) if not isinstance(b, ALLOWED)]\nassert not bad, f\"unsupported blocks: {[type(b).__name__ for b in bad]}\"","typeGuard":"def is_anthropic_convertible(block) -> bool:\n    from mcp.types import TextContent, ImageContent, AudioContent, ToolResultContent\n    return isinstance(block, (TextContent, ImageContent, AudioContent, ToolResultContent))","tryCatchPattern":"try:\n    return await handler(messages, params, ctx)\nexcept ValueError as e:\n    if e.args and e.args[0].startswith(\"Unsupported content type\"):\n        return await handler(convert_blocks(messages), params, ctx)\n    raise","preventionTips":["Convert EmbeddedResource and custom blocks to TextContent before sampling","Pin fastmcp-slim versions consistent with the MCP types you emit","Sanitize message content in middleware before provider dispatch","Log the offending class name (it's in the message) to find the producing tool"],"tags":["anthropic","sampling","content-type","conversion"],"backgroundTag":"unsupported-content-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}