Skip to content

python SDK and metadata #133

@idling-mind

Description

@idling-mind

I tried passing in the preferred-frame-size as metadata from python sdk's create_ui_resource as shown below

@mcp.tool
def some_ui_resource():
    """plot a dataframe"""
    df = fetch_a_dataframe()
    axes = df.plot()
    #convert matplotlib plot to base64 string
    import io
    import base64
    buf = io.BytesIO()
    fig = axes.get_figure()
    fig.savefig(buf, format='png')
    buf.seek(0)
    plot_data = base64.b64encode(buf.read()).decode('utf-8')
    buf.close()
    return create_ui_resource({
        "uri": f"ui://some/ui/path",
        "uiMetadata": {
            "preferred-frame-size": [800, 600],
        },
        "content": {
            "type": "rawHtml",
            "htmlString": f"""
                <img src="data:image/jpeg;base64,{plot_data}" alt="plot"/>
            """
        },
        "encoding": "text"
    })

I tried a model_dump of the created resource object and seems like the metadata is null.

{
    "type": "resource",
    "resource": {
        "uri": "ui://some/uipath",
        "mimeType": "text/html",
        "meta": null,
        "text": "\n                <img src=\"data:image/jpeg;base64,some_data_here\" alt=\"plot\"/>\n            "
    },
    "annotations": null,
    "meta": null
}

is this a missing feature in python sdk?

Metadata

Metadata

Assignees

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