Open
Description
Unsolicited feature idea 💡
You could expose a Tool that hits the HF semantic Space search (the one that's on https://huggingface.co/spaces) (see early snippet below) tweaked to dynamically add the Top 1 result as a Tool itself.
(If I understood correctly, a MCP server can now send a notification to the client that it got new tools)
You'd probably want to filter to only (running) Gradio Spaces though. cc @mishig25 @gary149 for visibility
server.tool(
"space-semantic-search",
"Search for Spaces on Hugging Face from a natural language query",
{
query: z
.string()
.describe(
"Description of what the Space or AI App should achieve, like Generate a 3D model, find LLM models, etc"
),
},
async ({ query }) => {
const res = await (
await fetch(`${HUB_URL}/api/spaces/semantic-search?` + new URLSearchParams({ q: query }), {
headers: {
Authorization: `Bearer ${process.env.HF_TOKEN}`,
"Content-Type": "application/json",
},
})
).json();
const spaces = z
.array(
z.object({
id: z.string(),
shortDescription: z.string().optional(),
ai_short_description: z.string().optional(),
runtime: z.object({
stage: z.string(),
}),
})
)
.parse(res);
if (!spaces.length) {
return {
content: [
{
type: "text",
text: "No Spaces were found",
},
],
};
}
const formattedText =
`Found the following Spaces:\n\n` +
spaces
.map(
s =>
<
5E5B
span class="pl-s">`${HUB_URL}/spaces/${s.id} ${s.shortDescription ?? s.ai_short_description ?? ""} (currently ${s.runtime.stage})`
)
.join("\n");
return {
content: [
{
type: "text",
text: formattedText,
},
],
};
}
);