Skip to main content
Glama

search_documents

Find markdown documents by searching their content and metadata for specific text, returning matching file paths for documentation management.

Instructions

Search for markdown documents containing specific text in their content or frontmatter. Returns the relative paths to matching documents.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
queryYes
basePathNo

Implementation Reference

  • The core handler function that implements the search_documents tool logic. It uses glob to find all .md files recursively from basePath, reads each file's content, and checks if it contains the query string (case-insensitive). Returns relative paths of matching files.
    async searchDocuments(query: string, basePath = ""): Promise<ToolResponse> { try { const baseDir = path.join(this.docsDir, basePath); const pattern = path.join(baseDir, "**/*.md"); const files = await glob(pattern); const results = []; for (const file of files) { const content = await fs.readFile(file, "utf-8"); if (content.toLowerCase().includes(query.toLowerCase())) { results.push(path.relative(this.docsDir, file)); } } return { content: [{ type: "text", text: results.join("\n") }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error searching documents: ${errorMessage}` }, ], isError: true, }; } }
  • Zod schema defining the input parameters for the search_documents tool: 'query' (required string) and 'basePath' (optional string, defaults to empty). Extends ToolInputSchema.
    export const SearchDocumentsSchema = ToolInputSchema.extend({ query: z.string(), basePath: z.string().optional().default(""), });
  • src/index.ts:228-233 (registration)
    Tool registration in the listTools handler: defines the tool name, description, and converts the Zod schema to JSON schema for MCP protocol.
    { name: "search_documents", description: "Search for markdown documents containing specific text in their content or frontmatter. " + "Returns the relative paths to matching documents.", inputSchema: zodToJsonSchema(SearchDocumentsSchema) as any,
  • src/index.ts:362-373 (registration)
    Dispatch logic in the CallToolRequest handler: validates input using SearchDocumentsSchema, then calls the documentHandler.searchDocuments method.
    case "search_documents": { const parsed = SearchDocumentsSchema.safeParse(args); if (!parsed.success) { throw new Error( `Invalid arguments for search_documents: ${parsed.error}` ); } return await documentHandler.searchDocuments( parsed.data.query, parsed.data.basePath ); }

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/alekspetrov/mcp-docs-service'

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