Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 10 min read How-to mediumAdept

How to Build an MCP Server with Gradio

Gradio apps become Model Context Protocol servers by passing mcp_server=True to launch(), which auto-converts each Python function into an MCP tool, using its docstring and type hints to build the description and input schema. The server is exposed over SSE at /gradio_api/mcp/sse. Claude Desktop, which lacks SSE support, can reach it through mcp-remote via npx. Newer features include decorators for MCP resources and prompts, MCP-only functions via gr.api(), automatic file and base64 conversion, per-tool latency and success metrics, and free hosting on Hugging Face Spaces with bearer-token auth for private Spaces.

Related posts

  • Implementing MCP Servers in Python: An AI Shopping Assistant with Gradio

    Hugging Face mediumAdept

    Gradio's MCP integration turns Python functions into LLM tools: launching an app with mcp_server=True exposes each endpoint as an MCP tool, with names, descriptions and input schemas generated from function docstrings, plus progress streaming and file upload handling. The walkthrough builds a virtual try-on shopping assistant by wrapping the IDM-VTON diffusion Space, called through the Gradio API client, in a Gradio Interface. That server is registered alongside the Playwright MCP server in VS Code's mcp.json, so the AI chat can browse a clothing store and render the user wearing selected garments.

  • Five Big Improvements to Gradio MCP Servers

    Hugging Face mediumAdept

    Gradio 5.38.0 adds five features for building MCP servers. A "File Upload" MCP server lets agents send local files to remote Gradio apps, and progress notifications now stream to MCP clients. `gr.load_openapi` turns an OpenAPI spec into an MCP server in one line, `gr.Header`-typed arguments extract auth headers and list them in the connection docs, and the `api_description` parameter overrides auto-generated tool descriptions. Short code examples cover the OpenAPI loader, header-based auth and custom descriptions.

  • What’s MCP all about? Comparing MCP with LLM function calling

    Neon mediumAdept

    The Model Context Protocol (MCP) builds on LLM function calling by moving tool definitions and execution out of individual LLM applications into standalone servers that any MCP-compatible client can discover and invoke. A Home Assistant light-control function is implemented both ways. The first version uses OpenAI tool definitions in JSON, with the app parsing tool_calls and executing them itself. The second is an MCP server built with the TypeScript SDK, a Zod schema and stdio transport, registered in Cursor. The takeaway is that function calling leaves discovery and execution to each app, while MCP standardizes them so tools can be reused across agents like Cursor, Windsurf and Claude Desktop.

  • Adding MCP Tools to Reachy Mini

    Hugging Face mediumAdept

    The Reachy Mini conversation app can now call tools hosted in public Hugging Face Gradio Spaces over MCP, alongside built-in robot tools and custom local Python tools, all sharing one registry gated by each profile's tools.txt. A `tool-spaces add` command validates the Space, probes its MCP endpoint, discovers tools and namespaces them (Space slug alias plus double underscore) to avoid collisions, with a fail-fast uniqueness check. Canary search and weather tools showed that prompts matter: explicit instructions are needed to get parallel tool calls, though prompts can't guarantee orchestration, so deterministic logic belongs in code. Private, non-Gradio and arbitrary MCP servers aren't supported yet.

  • Building the Hugging Face MCP Server

    Hugging Face mediumAdept

    Hugging Face's hosted MCP server at hf.co/mcp runs in production on Streamable HTTP in a stateless, direct-response configuration. That choice permits simple horizontal scaling, since per-user tool selections and Gradio Spaces are looked up per request from HF_TOKEN or OAuth credentials. The write-up compares STDIO, deprecated HTTP+SSE, and the Streamable HTTP patterns (direct response, request-scoped streams, server push), including which MCP features each supports and when sessions are needed. It also explains why real-time tool-list-change notifications are impractical for a public server and reports operational findings: VSCode polling the endpoint when served an HTML page, roughly 100 control messages per tool call, and 164 distinct clients in a week, about half connecting via mcp-remote.

The quest for software engineering knowledge.

Look:
Layout: