{"record":{"id":"5b9d966c9f635374","repo":"PrefectHQ/fastmcp","slug":"unsupported-content-type-type-content-5b9d96","errorCode":null,"errorMessage":"Unsupported content type: {type(content)}","messagePattern":"Unsupported content type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py","lineNumber":273,"sourceCode":"        # toolUseId, while Google's FunctionResponse requires the function name.\n        tool_use_id = content.tool_use_id\n        if \"_\" in tool_use_id:\n            # Split and rejoin all but the last part (the UUID suffix)\n            parts = tool_use_id.rsplit(\"_\", 1)\n            function_name = parts[0]\n        else:\n            # Fallback: use the full ID as the name\n            function_name = tool_use_id\n\n        return Part(\n            function_response=FunctionResponse(\n                name=function_name,\n                response={\"result\": result_text},\n            )\n        )\n\n    msg = f\"Unsupported content type: {type(content)}\"\n    raise ValueError(msg)\n\n\ndef _convert_messages_to_google_genai_content(\n    messages: Sequence[SamplingMessage],\n) -> list[Content]:\n    \"\"\"Convert MCP messages to Google GenAI content.\"\"\"\n    google_messages: list[Content] = []\n\n    for message in messages:\n        content = message.content\n\n        # Handle list content (tool calls + results)\n        if isinstance(content, list):\n            parts: list[Part] = [\n                _sampling_content_to_google_genai_part(item) for item in content\n            ]\n\n            if message.role == \"user\":","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py#L255-L291","documentation":"_sampling_content_to_google_genai_part raises ValueError for a sampling message content item that is not TextContent, ImageContent, AudioContent, ToolUseContent, or ToolResultContent — the only MCP types it knows how to map to Google GenAI parts. Prevents silently dropping content.","triggerScenarios":"A sampling message contains EmbeddedResource, ResourceLink, or another MCP content type outside the supported set.","commonSituations":"Servers embedding resources in sampling prompts; new MCP content types added after the handler was written; custom content subclasses.","solutions":["Convert unsupported content (e.g. EmbeddedResource) to TextContent before sending the sampling request.","Filter out unsupported content blocks in your sampling callback wrapper.","Upgrade fastmcp-slim if a newer version maps additional content types.","Choose a handler/fallback that tolerates the content types your server emits."],"exampleFix":"// before\nmessages = [SamplingMessage(role=\"user\", content=EmbeddedResource(resource=TextResourceContents(uri=\"file:///a.txt\", text=\"hi\", mimeType=\"text/plain\")))]\n// after\nmessages = [SamplingMessage(role=\"user\", content=TextContent(type=\"text\", text=\"Contents of file:///a.txt:\\nhi\"))","handlingStrategy":"type-guard","validationCode":"from mcp.types import TextContent, ImageContent, AudioContent\nSUPPORTED = (TextContent, ImageContent, AudioContent)\ndef validate_content(messages):\n    for m in messages:\n        contents = m.content if isinstance(m.content, list) else [m.content]\n        for c in contents:\n            if not isinstance(c, SUPPORTED) and not hasattr(c, \"toolUseId\"):\n                raise ValueError(f\"Unsupported for Gemini: {type(c).__name__}\")","typeGuard":"def is_gemini_supported(c) -> bool:\n    from mcp.types import TextContent, ImageContent, AudioContent\n    return isinstance(c, (TextContent, ImageContent, AudioContent)) or hasattr(c, \"toolUseId\")","tryCatchPattern":"try:\n    result = await handler(messages, params, context)\nexcept ValueError as e:\n    if \"Unsupported content type\" in str(e):\n        result = CreateMessageResult(content=TextContent(type=\"text\", text=\"Prompt contained unsupported content.\"), role=\"assistant\", model=\"unknown\")\n    else:\n        raise","preventionTips":["Convert EmbeddedResource to TextContent before sampling","Filter resource links/embeddings out of sampling prompts","Keep fastmcp-slim current for new content-type mappings","Normalize content centrally in one sampling wrapper"],"tags":["google-genai","sampling","unsupported-content","valueerror"],"backgroundTag":"unsupported-content-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}