Skip to content

fix: support List[<MCP types>] return values for mcp_tool#337

Open
hallvictoria wants to merge 2 commits intodevfrom
hallvictoria/structured-content-fix
Open

fix: support List[<MCP types>] return values for mcp_tool#337
hallvictoria wants to merge 2 commits intodevfrom
hallvictoria/structured-content-fix

Conversation

@hallvictoria
Copy link
Copy Markdown
Contributor

Fixes an issue where functions with List[<MCP types>] return values were not returned correctly.

Example function:

@app.mcp_tool()
@app.mcp_tool_property(arg_name="label", description="The label text for the badge.", is_required=True)
@app.mcp_tool_property(arg_name="value", description="The value text for the badge.", is_required=True)
@app.mcp_tool_property(arg_name="color", description="The hex color for the value section (e.g., '#4CAF50').", is_required=False)
def generate_badge(label: str, value: str, color: str = "#4CAF50") -> List[ContentBlock]:
    """Demonstrates returning multiple content blocks (List[ContentBlock]). Generates an SVG status badge and returns it alongside a text description."""
    logging.info(f"Generating badge: {label} | {value}")
    
    label_width = len(label) * 7 + 12
    value_width = len(value) * 7 + 12
    total_width = label_width + value_width
    
    svg = f"""<svg xmlns="http://www.w3.org/2000/svg" width="{total_width}" height="20">
  <rect width="{label_width}" height="20" fill="#555"/>
  <rect x="{label_width}" width="{value_width}" height="20" fill="{color}"/>
  <text x="{label_width // 2}" y="14" fill="#fff" text-anchor="middle"
        font-family="Verdana,sans-serif" font-size="11">{label}</text>
  <text x="{label_width + value_width // 2}" y="14" fill="#fff" text-anchor="middle"
        font-family="Verdana,sans-serif" font-size="11">{value}</text>
</svg>"""
    
    return [
        TextContent(type="text", text=f"Badge: {label} — {value}"),
        ImageContent(
            type="image",
            data=base64.b64encode(svg.encode('utf-8')).decode('utf-8'),
            mimeType="image/svg+xml"
        )
    ]

@hallvictoria hallvictoria marked this pull request as ready for review May 4, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant