import gradio as gr @gr.mcp.tool( _meta={ "openai/outputTemplate": "ui://widget/app.html", "openai/resultCanProduceWidget": True, "openai/widgetAccessible": True, } ) def letter_counter(word: str, letter: str) -> int: """ Count the number of letters in a word or phrase. Parameters: word (str): The word or phrase to count the letters of. letter (str): The letter to count the occurrences of. """ return word.count(letter) @gr.mcp.resource("ui://widget/app.html", mime_type="text/html+skybridge") def app_html(): visual = """
""" return visual with gr.Blocks() as demo: with gr.Row(): with gr.Column(): word = gr.Textbox(label="Word") letter = gr.Textbox(label="Letter") btn = gr.Button("Count Letters") with gr.Column(): count = gr.Number(label="Count") html = gr.Code(language="html", max_lines=20) btn.click(letter_counter, inputs=[word, letter], outputs=count) btn.click(app_html, outputs=html) if __name__ == "__main__": demo.launch(mcp_server=True, share=True)