PrefectHQ/fastmcp · error · ValueError
Unsupported tool result content type: {type(item).__name__}
Error message
Unsupported tool result content type: {type(item).__name__} What it means
_sampling_content_to_google_genai_part raises ValueError when a ToolResultContent block contains an item whose type is not TextContent (e.g. ImageContent or EmbeddedResource). Google GenAI function responses are text-only here, so non-text tool-result items are rejected.
Source
Thrown at fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py:249
# See: https://ai.google.dev/gemini-api/docs/thought-signatures
return Part(
function_call=FunctionCall(
name=content.name,
args=content.input,
),
thought_signature=b"skip_thought_signature_validator",
)
if isinstance(content, ToolResultContent):
# Extract text from tool result content
result_parts: list[str] = []
if content.content:
for item in content.content:
if isinstance(item, TextContent):
result_parts.append(item.text)
else:
msg = f"Unsupported tool result content type: {type(item).__name__}"
raise ValueError(msg)
result_text = "".join(result_parts)
# Extract function name from toolUseId
# Our IDs are formatted as "{function_name}_{uuid8}", so extract the name.
# Note: This is a limitation of MCP's ToolResultContent which only carries
# toolUseId, while Google's FunctionResponse requires the function name.
tool_use_id = content.tool_use_id
if "_" in tool_use_id:
# Split and rejoin all but the last part (the UUID suffix)
parts = tool_use_id.rsplit("_", 1)
function_name = parts[0]
else:
# Fallback: use the full ID as the name
function_name = tool_use_id
return Part(
function_response=FunctionResponse(
name=function_name,View on GitHub (pinned to 1f02114297)
Solutions
- Make tools return plain text results when the client uses the Gemini sampling handler.
- Strip/downgrade non-text items from tool result content before invoking the handler.
- Catch ValueError and serialize the offending item to a text description in your sampling callback.
- Use a handler/provider that supports multimodal tool results if rich results are required.
Example fix
// before
def my_tool(path: str) -> ImageContent: ...
// after
def my_tool(path: str) -> str:
return f"Image at {path}: <describe or omit>" Defensive patterns
Strategy: type-guard
Validate before calling
from mcp.types import TextContent
def validate_tool_results(messages):
for m in messages:
contents = m.content if isinstance(m.content, list) else [m.content]
for c in contents:
if hasattr(c, "content") and c.content: # ToolResultContent
for item in c.content:
if not isinstance(item, TextContent):
raise ValueError(f"Tool result item {type(item).__name__} not supported by Gemini handler") Type guard
def is_text_tool_result(c) -> bool:
return not hasattr(c, "content") or all(isinstance(i, TextContent) for i in (c.content or [])) Try / catch
try:
result = await handler(messages, params, context)
except ValueError as e:
if "Unsupported tool result content type" in str(e):
result = CreateMessageResult(content=TextContent(type="text", text="Tool returned non-text output that cannot be forwarded."), role="assistant", model="unknown")
else:
raise Prevention
- Design tools to return plain text when clients sample via Gemini
- Serialize images/resources in tool results to text descriptions
- Test tool flows end-to-end with the Gemini handler
- Document the text-only tool-result constraint for server authors
When it happens
Trigger: A server returns a tool result whose content list includes images/audio/resources, and the client routes sampling through GoogleGenaiSamplingHandler.
Common situations: Tools returning screenshots or files in results; servers attaching resources to tool outputs; rich tool results designed for clients that support multimodal content.
Related errors
- Unsupported content type: {type(content)}
- Unsupported content type: {type(content)}
- Invalid message role: {message.role}
- No candidate in response from completion.
- Model returned only thinking/reasoning content with no respo
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/9778528e5fd21dce.
Report an issue: GitHub.