Skip to main content
Glama

search_docs

Search Fumadocs documentation by keyword to find specific topics, features, or sections. Returns matching pages with titles, descriptions, and paths for integration assistance.

Instructions

Search Fumadocs documentation by keyword. Returns matching documentation pages with titles, descriptions, and paths. Use this to find specific topics or features.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query to find in documentation
sectionNoFilter results to a specific documentation section

Implementation Reference

  • The main searchDocs handler function that processes search requests. It validates the query, calls the searchDocsIndex helper, formats results, and returns formatted output with up to 15 matches including suggestions when no results are found.
    export async function searchDocs(params: SearchDocsParams): Promise<string> {
      const { query, section } = params;
    
      if (!query || query.trim().length === 0) {
        return "Error: Please provide a search query.";
      }
    
      const sectionFilter = section === "all" ? undefined : (section as SectionId);
      const results = searchDocsIndex(query, sectionFilter);
    
      if (results.length === 0) {
        const suggestions = [
          "No results found for: " + query,
          "",
          "Suggestions:",
          "- Try different keywords",
          "- Use more general terms",
          "- Check spelling",
          "",
          "Popular topics:",
          "- 'manual installation' - Setup guides for existing projects",
          "- 'components' - UI component documentation",
          "- 'search' - Search implementation",
          "- 'mdx' - MDX content source setup",
        ];
        return suggestions.join("\n");
      }
    
      const output: string[] = [
        `# Search Results for "${query}"`,
        `Found ${results.length} result${results.length === 1 ? "" : "s"}${sectionFilter ? ` in ${SECTIONS[sectionFilter]}` : ""}:\n`,
      ];
    
      // Limit to top 15 results
      const topResults = results.slice(0, 15);
    
      for (const entry of topResults) {
        output.push(`## ${entry.title}`);
        output.push(`**Section:** ${SECTIONS[entry.section as SectionId]} | **Path:** ${entry.path}`);
        output.push(`${entry.description}\n`);
      }
    
      if (results.length > 15) {
        output.push(`\n---\n*Showing top 15 of ${results.length} results. Refine your search for more specific results.*`);
      }
    
      output.push("\n---");
      output.push("Use `get_page` with a path to fetch the full content of a documentation page.");
    
      return output.join("\n");
    }
  • The searchDocsSchema definition using Zod for input validation. Defines a required 'query' string parameter and an optional 'section' enum parameter with values: all, cli, headless, framework, mdx, ui.
    export const searchDocsSchema = {
      query: z.string().describe("Search query to find in documentation"),
      section: z
        .enum(["all", "cli", "headless", "framework", "mdx", "ui"])
        .optional()
        .describe("Filter results to a specific documentation section"),
    };
  • TypeScript type definition SearchDocsParams that defines the shape of parameters for the searchDocs function, including the query string and optional section filter.
    export type SearchDocsParams = {
      query: string;
      section?: "all" | SectionId;
    };
  • src/index.ts:39-50 (registration)
    Tool registration with the MCP server. Registers 'search_docs' tool with description, schema, and handler that wraps the searchDocs function and returns results as text content.
    // Register search_docs tool
    server.tool(
      "search_docs",
      "Search Fumadocs documentation by keyword. Returns matching documentation pages with titles, descriptions, and paths. Use this to find specific topics or features.",
      searchDocsSchema,
      async (params) => {
        const result = await searchDocs(params);
        return {
          content: [{ type: "text", text: result }],
        };
      }
    );
  • The searchDocsIndex helper function that performs the actual search logic. It filters entries by section, scores matches based on title, description, keywords, and path, then returns sorted results by relevance score.
    export function searchDocsIndex(
      query: string,
      section?: SectionId
    ): DocEntry[] {
      const normalizedQuery = query.toLowerCase();
      const queryWords = normalizedQuery.split(/\s+/);
    
      let results = DOCS_INDEX;
    
      // Filter by section if specified
      if (section) {
        results = results.filter((entry) => entry.section === section);
      }
    
      // Score and filter results
      const scored = results
        .map((entry) => {
          let score = 0;
          const titleLower = entry.title.toLowerCase();
          const descLower = entry.description.toLowerCase();
    
          for (const word of queryWords) {
            // Title matches (highest weight)
            if (titleLower.includes(word)) {
              score += 10;
              if (titleLower === word || titleLower.startsWith(word)) {
                score += 5;
              }
            }
    
            // Description matches
            if (descLower.includes(word)) {
              score += 5;
            }
    
            // Keyword matches
            for (const keyword of entry.keywords) {
              if (keyword.includes(word)) {
                score += 3;
                if (keyword === word) {
                  score += 2;
                }
              }
            }
    
            // Path matches
            if (entry.path.toLowerCase().includes(word)) {
              score += 2;
            }
          }
    
          return { entry, score };
        })
        .filter((item) => item.score > 0)
        .sort((a, b) => b.score - a.score);
    
      return scored.map((item) => item.entry);
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions what the tool returns (pages with titles, descriptions, paths) but lacks details on behavioral traits such as pagination, rate limits, authentication needs, error handling, or whether it's a read-only operation. For a search tool with no annotations, this leaves significant gaps in understanding how it behaves beyond the basic output.

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 concise and well-structured: two sentences that efficiently state the purpose and usage without waste. The first sentence covers the action and output, and the second provides usage context. Every sentence earns its place, making it front-loaded and easy to understand quickly.

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

Completeness3/5

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

Given the context: no annotations, no output schema, 2 parameters with full schema coverage, and sibling tools present, the description is moderately complete. It explains the core functionality but lacks details on behavioral aspects (e.g., how results are formatted, limitations) and doesn't fully differentiate from siblings. For a search tool, this is adequate but has clear gaps in providing a full picture for an AI agent.

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?

The input schema has 100% description coverage, with clear descriptions for both parameters ('query' and 'section'), including an enum for 'section'. The description doesn't add any semantic details beyond what the schema provides (e.g., it doesn't explain query syntax or section meanings further). According to the rules, with high schema coverage (>80%), the baseline is 3 even without param info in the description, which fits here.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Search Fumadocs documentation by keyword' with the verb 'search' and resource 'documentation'. It specifies what it returns ('matching documentation pages with titles, descriptions, and paths'), making the purpose clear. However, it doesn't explicitly distinguish this tool from sibling tools like 'get_page' or 'list_topics', which might also retrieve documentation content, so it doesn't reach the highest score.

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

Usage Guidelines3/5

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

The description provides implied usage guidance: 'Use this to find specific topics or features' suggests it's for keyword-based searching rather than direct retrieval. However, it doesn't explicitly state when to use this tool versus alternatives like 'get_page' (which might fetch a specific page by path) or 'list_topics' (which might list topics without searching). No exclusions or clear alternatives are mentioned, so the guidance is basic.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/k4cper-g/fumadocs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server