{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: mcp_letter_counter_app"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "\n", "@gr.mcp.tool(\n", " _meta={\n", " \"openai/outputTemplate\": \"ui://widget/app.html\",\n", " \"openai/resultCanProduceWidget\": True,\n", " \"openai/widgetAccessible\": True,\n", " }\n", ")\n", "def letter_counter(word: str, letter: str) -> int:\n", " \"\"\"\n", " Count the number of letters in a word or phrase.\n", "\n", " Parameters:\n", " word (str): The word or phrase to count the letters of.\n", " letter (str): The letter to count the occurrences of.\n", " \"\"\"\n", " return word.count(letter)\n", "\n", "\n", "@gr.mcp.resource(\"ui://widget/app.html\", mime_type=\"text/html+skybridge\")\n", "def app_html():\n", " visual = \"\"\"\n", "
\n", " \n", " \"\"\"\n", " return visual\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " word = gr.Textbox(label=\"Word\")\n", " letter = gr.Textbox(label=\"Letter\")\n", " btn = gr.Button(\"Count Letters\")\n", " with gr.Column():\n", " count = gr.Number(label=\"Count\")\n", " html = gr.Code(language=\"html\", max_lines=20)\n", "\n", " btn.click(letter_counter, inputs=[word, letter], outputs=count)\n", " btn.click(app_html, outputs=html)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch(mcp_server=True, share=True)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}