Skip to main content
Glama

search-spaces

Find Hugging Face Spaces endpoints using semantic search. Enter a task description to discover relevant AI models and tools for your project.

Instructions

Use semantic search to find an endpoint on the Hugging Face Spaces service. The search term will usually be 3-7 words describing a task or activity the Person is trying to accomplish. The results are returned in a markdown table. Present all results to the Person. Await specific guidance from the Person before making further Tool calls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoThe semantic search term to use.

Implementation Reference

  • Handler for the 'search-spaces' tool call. Extracts the query argument, performs semantic search using SemanticSearch instance, formats results into markdown table, and returns as text content. Includes error handling.
    if (SEARCH_FOR_SPACE === request.params.name) {
      try {
        const query = request.params.arguments?.query as string;
        if (!query || typeof query !== "string") {
          throw new Error("Search query must be a non-empty string");
        }
    
        const results = await semanticSearch.search(query);
        const markdownTable = semanticSearch.formatSearchResults(results);
    
        return {
          content: [
            {
              type: "text",
              text: markdownTable,
            },
          ],
        };
      } catch (error) {
        if (error instanceof Error) {
          return {
            content: [
              {
                type: "text",
                text: `Search error: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • src/index.ts:92-109 (registration)
    Tool registration for 'search-spaces' in the ListToolsRequestSchema handler, including name, description, and input schema definition.
    {
      name: SEARCH_FOR_SPACE,
      description:
        "Use semantic search to find an endpoint on the `Hugging Face Spaces` service. The search term will usually " +
        "be 3-7 words describing a task or activity the Person is trying to accomplish. The results are returned in a markdown table. " +
        "Present all results to the Person. Await specific guidance from the Person before making further Tool calls.",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            // TODO description assumes  user is using claude desktop which has knowledge of HF Spaces.
            // consider updating for not CLAUDE_DESKTOP mode. 3.7 sys prompt refers to Human as Person
            description: "The semantic search term to use.",
          },
        },
      },
    },
  • Input schema definition for the 'search-spaces' tool, specifying an object with a required 'query' string parameter.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          // TODO description assumes  user is using claude desktop which has knowledge of HF Spaces.
          // consider updating for not CLAUDE_DESKTOP mode. 3.7 sys prompt refers to Human as Person
          description: "The semantic search term to use.",
        },
      },
    },
  • Core search logic in SemanticSearch class: performs HTTP GET to Hugging Face Spaces semantic search API, filters for Gradio SDK, limits results, with auth and error handling.
    async search(
      query: string,
      limit: number = RESULTS_TO_RETURN,
    ): Promise<SearchResult[]> {
      try {
        if (!query) {
          return [];
        }
    
        const url =
          `${this.apiUrl}?` + new URLSearchParams({ q: query, sdk: "gradio" });
    
        const headers: HeadersInit = {
          "Content-Type": "application/json",
        };
    
        if (config.hfToken) {
          headers["Authorization"] = `Bearer ${config.hfToken}`;
        }
    
        const response = await fetch(url, headers);
    
        if (!response.ok) {
          throw new Error(
            `Search request failed: ${response.status} ${response.statusText}`,
          );
        }
    
        const results = (await response.json()) as SearchResult[];
    
        // Filter for gradio results and limit by count
        return results
          .filter((result) => result.sdk === "gradio")
          .slice(0, limit);
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to search for spaces: ${error.message}`);
        }
        throw error;
      }
    }
  • Formats the SemanticSearch results into a markdown table with links to HF Spaces, including title, description, author, and ID.
    formatSearchResults(results: SearchResult[]): string {
      if (results.length === 0) {
        return "No matching Hugging Face Spaces found. Try a different query.";
      }
    
      let markdown = "# Search Results for Hugging Face Spaces\n\n";
      markdown += "| Space | Description | Author | ID |\n";
      markdown += "|-------|-------------|--------|----|\n";
    
      for (const result of results) {
        const title = result.title || "Untitled";
        const description = result.shortDescription || "No description";
        const author = result.authorData?.fullname || result.author || "Unknown";
        const id = result.id || "";
    
        markdown +=
          `| [${escapeMarkdown(title)}](https://hf.co/spaces/${id}) ` +
          `| ${escapeMarkdown(description)} ` +
          `| ${escapeMarkdown(author)} ` +
          `| \`${escapeMarkdown(id)}\` |\n`;
      }
    
      markdown +=
        "\nTo use one of these spaces, you can provide the ID in the format: `owner/space` or `owner/space/endpoint`";
    
      return markdown;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses key behavioral traits: the search is semantic (not keyword-based), results come in markdown table format, and the agent should present all results and await Person's guidance. However, it doesn't mention rate limits, authentication requirements, or what happens with empty/no results.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: first sentence states core purpose, second adds query guidance, third specifies output format, fourth provides workflow instructions. Every sentence earns its place with no wasted words or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 1 parameter with full schema coverage and no output schema, the description provides good context about the search approach, result format, and agent workflow. It could be more complete by addressing edge cases (no results, error handling) or explaining the semantic search mechanism, but covers the essential usage scenario adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% (the single parameter 'query' is fully described in schema), so baseline is 3. The description adds marginal value by suggesting query length (3-7 words) and content (task/activity description), but doesn't provide syntax examples or format details beyond what the schema already states.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('semantic search'), target resource ('endpoint on the Hugging Face Spaces service'), and distinguishes from siblings by focusing on search rather than file listing or inference. It explicitly mentions what the tool does: finding endpoints via semantic search with results in markdown table format.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: when the Person has a task/activity description (3-7 words) and needs to find relevant endpoints. It instructs to present all results and await further guidance, establishing a workflow. However, it doesn't explicitly mention when NOT to use it or name specific alternatives among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools