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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search term or phrase to find in documentation | |
| include | No | Custom glob patterns to include (default: markdown and docs files) |
Implementation Reference
- src/index.ts:20-28 (handler)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 }; } }
- src/index.ts:13-19 (schema)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 }; } } );
- src/lib/search.ts:15-46 (helper)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; }