Skip to content

serving assets #90

@mgathena

Description

@mgathena

Hi, do i always have to serve the files from a different server? I am working on a python example. I took some code from a medium post.

here is the complete code.

and a relevant snippet

def create_calculator_widget():
{SOME_HTML_SNIPPET}

@mcp.resource("ui://widget/calculator-result.html")
async def calculator_widget():
    """Serve the calculator widget HTML."""
    return {
        "uri": "ui://widget/calculator-result.html",
        "mimeType": "text/html+skybridge",
        "text": create_calculator_widget(),
        "_meta": {
            "openai/widgetDescription": "Displays the result of addition calculations in a beautiful gradient card format.",
            "openai/widgetPrefersBorder": False,
        },
    }

@mcp.tool()
def add(a: float, b: float) -> dict:
    """Add two numbers together and return structured result."""
    result = a + b
    return {
        "content": [{"type": "text", "text": f"Added {a} + {b} = {result}"}],
        "structuredContent": {
            "a": a,
            "b": b,
            "result": result,
            "operation": "addition",
            "timestamp": "2024–01–15T10:30:00Z",
        },
        "_meta": {
            "openai/outputTemplate": "ui://widget/calculator-result.html",
            "openai/toolInvocation/invoking": "Calculating…",
            "openai/toolInvocation/invoked": "Calculation complete!",
            "openai/widgetAccessible": True,
            "openai/resultCanProduceWidget": True,
        },
    }

i run the server and then expose via ngrok. here is the response shown on chatgpt

text:
'{ "content": [ { "type": "text", "text": "Added 3.0 + 7.0 = 10.0" } ], "structuredContent": { "a": 3.0, "b": 7.0, "result": 10.0, "operation": "addition", "timestamp": "2024–01–15T10:30:00Z" }, "_meta": { "openai/outputTemplate": "ui://widget/calculator-result.html", "openai/toolInvocation/invoking": "Calculating…", "openai/toolInvocation/invoked": "Calculation complete!", "openai/widgetAccessible": true, "openai/resultCanProduceWidget": true } }'

but no UI (or even placeholder appears)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions