-
Notifications
You must be signed in to change notification settings - Fork 373
Spaces as MCP servers #1793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spaces as MCP servers #1793
Changes from 7 commits
e83857b
aebdfa1
efd52cf
97064b5
dc4d59e
085da89
79f49f7
512c39f
39f3b3e
b47d9b0
aea66ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Spaces as MCP servers | ||
|
|
||
| You can **turn any public Space that has a visible `MCP` badge into a callable tool** that will be available in any MCP-compatible client, without writing a single line of code. | ||
|
|
||
| ## Setup your MCP Client | ||
|
|
||
| From your [Hub MCP settings](https://huggingface.co/settings/mcp), select your MCP client (VSCode, Cursor, Claude Code, ...) then follow the setup instructions. | ||
|
|
||
|  | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these |
||
|
|
||
| > **Important:** You need a valid Hugging Face token with **READ** permissions to use MCP tools. If you don't have one, [create a new READ token](https://huggingface.co/settings/tokens/new?tokenType=read) with the **read** scope. | ||
gary149 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Add an existing Space to your MCP tools | ||
|
|
||
|  | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this could come immediately after the intro, to show the badge we're talking about. |
||
|
|
||
|
|
||
| 1. Browse compatible [Spaces](https://huggingface.co/spaces?filter=mcp-server) to find Spaces that are usable via MCP. You can also look for the grey **MCP** badge on any Spaces card. | ||
| 2. Click the badge and choose **Add to MCP tools** then confirm when asked. | ||
| 3. The Space should be listed in your MCP Server settings in the Spaces Tools section. | ||
|
|
||
|  | ||
|
|
||
| ## Use Spaces from your MCP client | ||
gary149 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| If your MCP client is configured correctly the Spaces you added will be available instantly without changing anything. Most MCP clients will list what tools are currently loaded so you can make sure the Space is available. | ||
gary149 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| > **Note:** For ZeroGPU Spaces, your quota will be used when the tool is called, so make sure you [subscribe to PRO](https://huggingface.co/subscribe/pro?from=ZeroGPU) to get 25 minutes of daily quota (on H200 hardware). For example, this lets you generate up to 600 images per day using FLUX.1-schnell. | ||
gary149 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Build your own MCP-compatible Gradio Space | ||
gary149 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| To create your own MCP-enabled Space, you need to [Create a new Gradio Space](https://huggingface.co/new-space?sdk=gradio) then make sure to enable MCP support in the code. See the [complete guide](https://www.gradio.app/guides/building-mcp-server-with-gradio) for more details. | ||
gary149 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| First, install Gradio with MCP support: | ||
| ```bash | ||
| pip install "gradio[mcp]" | ||
| ``` | ||
|
|
||
| Then create your app with clear type hints and docstrings: | ||
|
|
||
| ```python | ||
| import gradio as gr | ||
|
|
||
| def letter_counter(word: str, letter: str) -> int: | ||
| """Count occurrences of a letter in a word. | ||
|
|
||
| Args: | ||
| word: The word to search in | ||
| letter: The letter to count | ||
|
|
||
| Returns: | ||
| Number of times the letter appears in the word | ||
| """ | ||
| return word.lower().count(letter.lower()) | ||
|
|
||
| demo = gr.Interface(fn=letter_counter, | ||
| inputs=["text", "text"], | ||
| outputs="number") | ||
| demo.launch(mcp_server=True) # exposes an MCP schema automatically | ||
| ``` | ||
|
|
||
| Push the app to a **Gradio Space** and it will automatically receive the **MCP** badge. Anyone can then add it as a tool with a single click. | ||
|
|
||
| > **Note:** It's also quite easy to convert an existing Gradio Space to MCP server. Duplicate it from the context menu then just add the `mcp_server=True` parameter to your `launch()` method, and ensure your functions have clear type hints and docstrings - you can use AI tools to automate this quite easily ([example](https://huggingface.co/spaces/Lightricks/ltx-video-distilled/discussions/22/files) of AI generated docstrings). | ||
|
|
||
| ## Be creative by mixing Spaces! | ||
|
|
||
| As Hugging Face Spaces is the largest directory of AI apps, you can find many creative tools that can be used as MCP tools. Mixing and matching different Spaces can lead to powerful and creative workflows. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a CTA for the community to open PRs for spaces they want to be MCP-enabled, or is it better to just promote the duplication? |
||
|
|
||
|
|
||
| <figure> | ||
| <video controls> | ||
| <source src="https://cdn-uploads.huggingface.co/production/uploads/5f17f0a0925b9863e28ad517/jmYCdqYh32iwCgxM9p0Ig.mp4" type="video/mp4"> | ||
| </video> | ||
| <figcaption> | ||
| This video demonstrates the use of | ||
| <a href="https://huggingface.co/spaces/Lightricks/ltx-video-distilled">Lightricks/ltx-video-distilled</a> and | ||
| <a href="https://huggingface.co/spaces/ResembleAI/Chatterbox">ResembleAI/Chatterbox</a> in Claude Code to generate a video with audio. | ||
| </figcaption> | ||
| </figure> | ||
Uh oh!
There was an error while loading. Please reload this page.