Skip to main content
Glama

searchDocs

Search documentation files (Markdown, MDX, text) in your workspace to find specific information or content using customizable search patterns.

Instructions

Search developer documentation files (Markdown, MDX, text) in the workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch term or phrase to find in documentation
includeNoCustom glob patterns to include (default: markdown and docs files)

Implementation Reference

  • The async handler function for the searchDocs tool, which uses searchFiles to search documentation files with specific glob patterns.
    async ({ query, include }: { query: string; include?: string[] }) => { try { const patterns = include ?? ["**/*.md", "**/*.mdx", "**/*.txt", "docs/**/*", "**/README.*"]; const results = await searchFiles(query, patterns, { maxResults: 50 }); return { content: results }; } catch (error) { return { content: [{ type: "text", text: `Error searching docs: ${error}` }], isError: true }; } }
  • Input schema definition for the searchDocs tool using Zod validators for query and optional include patterns.
    { query: z.string().describe("Search term or phrase to find in documentation"), include: z .array(z.string()) .optional() .describe("Custom glob patterns to include (default: markdown and docs files)"), },
  • src/index.ts:10-29 (registration)
    mcp.tool() call that registers the searchDocs tool with the MCP server.
    mcp.tool( "searchDocs", "Search developer documentation files (Markdown, MDX, text) in the workspace", { query: z.string().describe("Search term or phrase to find in documentation"), include: z .array(z.string()) .optional() .describe("Custom glob patterns to include (default: markdown and docs files)"), }, async ({ query, include }: { query: string; include?: string[] }) => { try { const patterns = include ?? ["**/*.md", "**/*.mdx", "**/*.txt", "docs/**/*", "**/README.*"]; const results = await searchFiles(query, patterns, { maxResults: 50 }); return { content: results }; } catch (error) { return { content: [{ type: "text", text: `Error searching docs: ${error}` }], isError: true }; } } );
  • searchFiles function that implements the core logic for globbing files, reading contents, and matching the query, used by searchDocs.
    export async function searchFiles( query: string, include: string[], options: SearchOptions = {} ): Promise<SearchResultItem[]> { const { maxResults = 100, listOnly = false } = options; const files = await fg(include, { dot: false, ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"], unique: true, }); const results: SearchResultItem[] = []; for (const file of files) { if (listOnly) { results.push({ type: "text", text: file }); if (results.length >= maxResults) break; continue; } try { const content = await fs.readFile(file, "utf8"); if (!query || content.toLowerCase().includes(query.toLowerCase())) { const preview = content.slice(0, 2000); results.push({ type: "text", text: `# ${file}\n\n${preview}` }); } if (results.length >= maxResults) break; } catch { // ignore unreadable files } } return results; }

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/cloud-aspect/Config-MCP-Server'

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