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
      );
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It mentions the return format ('Returns the relative paths to matching documents') which is helpful, but doesn't address important behavioral aspects like: whether this is a read-only operation, if there are rate limits, what happens with no matches, whether search is case-sensitive, or how the 'path' and 'basePath' parameters affect the search scope. For a search tool with zero annotation coverage, this leaves significant gaps.

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 perfectly concise - two sentences that efficiently convey the core functionality and return value. The first sentence explains what the tool does, the second explains what it returns. There's no wasted language or unnecessary elaboration. It's appropriately sized for a search tool.

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

Completeness2/5

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

For a search tool with 3 parameters (0% documented in schema), no annotations, and no output schema, the description is insufficient. While it states the basic purpose and return format, it doesn't explain parameter usage, search behavior, error conditions, or how this tool relates to the 13 sibling document management tools. The agent would struggle to use this tool correctly without additional context about the parameters and their interactions.

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

Parameters2/5

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

With 0% schema description coverage for all 3 parameters, the description provides no information about what 'path', 'query', or 'basePath' mean or how they should be used. The description mentions 'specific text' which relates to the 'query' parameter, but doesn't explain its format, syntax, or behavior. The other two parameters aren't mentioned at all. The description fails to compensate for the complete lack of schema documentation.

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 for markdown documents containing specific text in their content or frontmatter.' It specifies the verb (search), resource (markdown documents), and scope (content/frontmatter). However, it doesn't explicitly differentiate from sibling tools like 'list_documents' or 'validate_documentation_metadata' which might also involve document retrieval.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With 13 sibling tools including 'list_documents' (which presumably lists documents without searching) and 'read_document' (which reads specific documents), there's no indication of when search is appropriate versus these other document access methods. The description only states what the tool does, not when to choose it.

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

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