{"record":{"id":"9b6bdfd4550bd3e0","repo":"microsoft/autogen","slug":"unsupported-content-type-content-type","errorCode":null,"errorMessage":"Unsupported content type: {content.type}","messagePattern":"Unsupported content type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/tools/mcp/_host/_sampling.py","lineNumber":55,"sourceCode":"        Converted content as string or Image object\n\n    Raises:\n        RuntimeError: If image content is provided but model doesn't support vision\n        ValueError: If content type is unsupported\n    \"\"\"\n    if content.type == \"text\":\n        return content.text\n    elif content.type == \"image\":\n        if model_info and not model_info.get(\"vision\", False):\n            model_family = model_info.get(\"family\", \"unknown\")\n            raise RuntimeError(f\"model {model_family} does not support vision.\")\n\n        # Decode base64 image data and create PIL Image\n        image_data = base64.b64decode(content.data)\n        pil_image = PILImage.open(io.BytesIO(image_data))\n        return Image.from_pil(pil_image)\n    else:\n        raise ValueError(f\"Unsupported content type: {content.type}\")\n\n\ndef parse_sampling_message(message: mcp_types.SamplingMessage, model_info: ModelInfo | None = None) -> LLMMessage:\n    \"\"\"Convert MCP sampling messages to AutoGen LLM messages.\n\n    Args:\n        message: MCP sampling message with role and content\n        model_info: Optional model information for content parsing\n\n    Returns:\n        Converted AutoGen LLM message (UserMessage or AssistantMessage)\n\n    Raises:\n        ValueError: If message role is not recognized\n        AssertionError: If assistant message content is not text\n    \"\"\"\n    content = parse_sampling_content(message.content, model_info=model_info)\n    if message.role == \"user\":","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/tools/mcp/_host/_sampling.py#L37-L73","documentation":"The MCP sampling content converter handles only 'text' and 'image' content types. A block with any other type (per MCP spec, 'audio' exists; servers may also send future types on newer protocol versions) raises ValueError(f'Unsupported content type: {content.type}'). This is a capability gap between the sampling host and the content the server sent.","triggerScenarios":"An MCP server includes content with type='audio' (or a newer spec type) in a sampling message; parse_content hits the final else and raises. Requires a server that actively uses non-text/image blocks.","commonSituations":"Voice/multimodal MCP servers sending audio blocks; protocol version negotiated higher than what this autogen-ext release supports; a custom server sending experimental content types.","solutions":["Filter the sampling request server-side so only text (and, for vision models, image) content is sent to the host.","Upgrade autogen-ext to a release whose _sampling converter supports the content type you need (e.g. audio).","If you control the server, downgrade content to text (e.g. transcribe audio server-side).","Catch ValueError around sampling handling and fail that single request with a descriptive message instead of crashing the host."],"exampleFix":"# server side — before\ncontent = [types.ContentBlock(type=\"audio\", data=b64, mimeType=\"audio/wav\")]\n\n# server side — after\ntranscript = transcribe(b64)\ncontent = [types.ContentBlock(type=\"text\", text=transcript)]","handlingStrategy":"type-guard","validationCode":"SUPPORTED = {\"text\", \"image\"}\nbad = [c for c in message_content if getattr(c, \"type\", None) not in SUPPORTED]\nif bad:\n    raise ValueError(f\"sampling content contains unsupported types: {[c.type for c in bad]}\")","typeGuard":"from typing import Any, TypeGuard\n\ndef is_supported_content(content: Any) -> TypeGuard[Any]:\n    return getattr(content, \"type\", None) in {\"text\", \"image\"}","tryCatchPattern":"try:\n    value = parse_content(content, model_info)\nexcept ValueError as e:\n    if \"Unsupported content type\" in str(e):\n        return error_result(f\"content type rejected: {e}\")\n    raise","preventionTips":["Keep autogen-ext updated when adopting newer MCP protocol content types (audio etc.).","Constrain server-side sampling messages to text unless the host advertises more.","Add a regression test with each content type your servers emit."],"tags":["mcp","sampling","content-type","multimodal","protocol"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}