Gradio now allows developers to launch apps as Model Context Protocol (MCP) servers, enabling LLMs to call Python functions as tools. By setting mcp_server=True in the launch method, apps can be integrated with MCP clients like Cursor, Cline, and Claude Desktop.
Gradio is a Python library used by more than 1 million developers each month to build interfaces for machine learning models. Beyond just creating UIs, Gradio also exposes API capabilities and — now! — Gradio apps can be launched Model Context Protocol (MCP) servers for LLMs. This means that your Gradio app, whether it's an image generator or a tax calculator or something else entirely, can be called as a tool by an LLM.
This guide will show you how to use Gradio to build an MCP server in just a few lines of Python.
If not already installed, please install Gradio with the MCP extra:
Gradio automatically converts the letter_counter function into an MCP tool that can be used by LLMs. The docstring of the function is used to generate the description of the tool and its parameters.
Some MCP Clients, notably Claude Desktop, do not yet support SSE-based MCP Servers. In those cases, you can use a tool such as mcp-remote . First install Node.js. Then, add the following to your own MCP Client config:
Gradio has recently added several powerful features to MCP servers. For a detailed overview of five major improvements including seamless local file support, real-time progress notifications, OpenAPI to MCP transformation, enhanced authentication, and customizable tool descriptions, check out our dedicated blog post: Five Big Improvements to Gradio MCP Servers .
Environment variable support . There are two ways to enable the MCP server functionality:
This will install the necessary dependencies, including the mcp package. You'll also need an LLM application that supports tool calling using the MCP protocol, such as Claude Desktop, Cursor, or Cline (these are known as "MCP Clients").
An MCP server is a standardized way to expose tools so that they can be used by LLMs. An MCP server can provide LLMs with all kinds of additional capabilities, such as the ability to generate or edit images, synthesize audio, or perform specific calculations such as prime factorize numbers.
Gradio makes it easy to build these MCP servers, turning any Python function into a tool that LLMs can use.
This integration bridges traditional machine learning UIs and LLM tool-calling ecosystems, making it simpler for developers to equip AI models with custom Python-backed capabilities.