Skip to content

feat: add support for structured content for MCP#318

Draft
hallvictoria wants to merge 2 commits intodevfrom
hallvictoria/structured-content
Draft

feat: add support for structured content for MCP#318
hallvictoria wants to merge 2 commits intodevfrom
hallvictoria/structured-content

Conversation

@hallvictoria
Copy link
Contributor

@hallvictoria hallvictoria commented Mar 17, 2026

fixes: Azure/azure-functions-python-worker#1825, Azure/azure-functions-python-worker#1836, Azure-Samples/remote-mcp-functions-python#38

Examples:

# ============================================================================
# Example 1: Returning ResourceLinkBlock - defined class
# ============================================================================
@app.mcp_tool()
def get_functions_logo(context: func.MCPToolContext) -> func.ResourceLinkBlock:
    """Returns the Azure Functions logo as a resource link."""
    return func.ResourceLinkBlock(
        uri="file://logo.png",
        name="Azure Functions Logo",
        mime_type="image/png"
    )

# ============================================================================
# Example 2: Structured Content with @mcp_content decorator - custom classes
# ============================================================================

@func.mcp_content
@dataclass
class Snippet:
    """Code snippet with metadata.
    """
    name: str
    content: Optional[str] = None

# In-memory snippet storage
snippets_cache = {}


@app.mcp_tool(use_result_schema=True)
def get_snippet(name: str) -> Optional[Snippet]:
    """
    Retrieves a code snippet by name.
    Returns structured content automatically because Snippet has @mcp_content.
    """
    if name in snippets_cache:
        return Snippet(name=name, content=snippets_cache[name])
    return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MCP Tool] Implement support for structured content

1 participant