-
Notifications
You must be signed in to change notification settings - Fork 344
Open
Description
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.
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
Labels
No labels