Skip to main content
Glama
pathakkhhimanshu

AI Dev Assistant

doc_search

Search local documentation folders for keywords across markdown, text, JSON, YAML, and code files to find relevant information quickly.

Instructions

Searches all documents in a local docs/ folder (or any directory) for one or more keywords. Supports case-insensitive multi-keyword search across markdown, text, JSON, YAML, code, and other text files. Returns matching lines with surrounding context. Searchable extensions: .md, .txt, .rst, .html, .json, .yaml, .ts, .js, .py, .sh, .bat, .ps1, and more.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docs_pathYesAbsolute path to the docs folder to search. Windows example: C:\Users\YourName\Projects\my-repo\docs
keywordsYesList of keywords to search for. All keywords must appear on the same line (AND logic).
case_sensitiveNoWhether the search is case-sensitive. Default: false.
file_extension_filterNoOptional: only search files with this extension (e.g., '.md', '.txt'). Leave blank to search all supported file types.

Implementation Reference

  • The handler implementation for the doc_search tool. It performs directory traversal, file filtering, and line-by-line keyword matching.
    async handler(args: {
      docs_path: string;
      keywords: string[];
      case_sensitive?: boolean;
      file_extension_filter?: string;
    }): Promise<string> {
      const { keywords, case_sensitive = false, file_extension_filter } = args;
      const docsPath = path.resolve(args.docs_path);
    
      if (!fs.existsSync(docsPath)) {
        return `ERROR: Docs path does not exist: ${docsPath}`;
      }
      if (!fs.statSync(docsPath).isDirectory()) {
        return `ERROR: Path is not a directory: ${docsPath}`;
      }
      if (!keywords.length || keywords.some((k) => !k.trim())) {
        return `ERROR: Please provide at least one non-empty keyword.`;
      }
    
      let files = walkDirectory(docsPath);
    
      if (file_extension_filter) {
        const ext = file_extension_filter.startsWith(".")
          ? file_extension_filter.toLowerCase()
          : `.${file_extension_filter.toLowerCase()}`;
        files = files.filter((f) => path.extname(f).toLowerCase() === ext);
      }
    
      if (files.length === 0) {
        return `No searchable files found in: ${docsPath}`;
      }
    
      const results: SearchResult[] = [];
      let totalMatches = 0;
    
      for (const file of files) {
        const matches = searchFileForKeywords(file, keywords, case_sensitive);
        if (matches.length > 0) {
          results.push({
            file: path.relative(docsPath, file).replace(/\\/g, "/"),
            matchCount: matches.length,
            matches,
          });
          totalMatches += matches.length;
          if (totalMatches >= MAX_RESULTS) break;
        }
      }
    
      if (results.length === 0) {
        return (
          `## Doc Search Results\n` +
          `**Query:** \`${keywords.join(" AND ")}\`  |  **Directory:** ${docsPath}\n\n` +
          `No matches found across ${files.length} files.`
        );
      }
    
      const sections: string[] = [
        `## Doc Search Results`,
        `**Query:** \`${keywords.join(" AND ")}\`  |  **Case Sensitive:** ${case_sensitive}`,
        `**Directory:** ${docsPath}`,
        `**Files searched:** ${files.length}  |  **Files with matches:** ${results.length}  |  **Total matches:** ${totalMatches}${totalMatches >= MAX_RESULTS ? " (capped)" : ""}`,
      ];
    
      for (const result of results) {
        sections.push(`\n### 📄 ${result.file}  *(${result.matchCount} match${result.matchCount !== 1 ? "es" : ""})*`);
    
        for (const match of result.matches) {
          const contextLines: string[] = [];
    
          if (match.contextBefore.length > 0) {
            match.contextBefore.forEach((line, i) => {
              const lineNum = match.lineNumber - match.contextBefore.length + i;
              contextLines.push(`  ${String(lineNum).padStart(4)} │ ${line}`);
            });
          }
    
          contextLines.push(`▶ ${String(match.lineNumber).padStart(4)} │ ${match.line}`);
    
          if (match.contextAfter.length > 0) {
            match.contextAfter.forEach((line, i) => {
              const lineNum = match.lineNumber + i + 1;
              contextLines.push(`  ${String(lineNum).padStart(4)} │ ${line}`);
            });
          }
    
          sections.push(`\`\`\`\n${contextLines.join("\n")}\n\`\`\``);
        }
      }
    
      return sections.join("\n");
    },
  • The JSON schema for the inputs required by the doc_search tool.
    inputSchema: {
      type: "object",
      properties: {
        docs_path: {
          type: "string",
          description:
            "Absolute path to the docs folder to search. " +
            "Windows example: C:\\Users\\YourName\\Projects\\my-repo\\docs",
        },
        keywords: {
          type: "array",
          items: { type: "string" },
          description:
            "List of keywords to search for. All keywords must appear on the same line (AND logic).",
        },
        case_sensitive: {
          type: "boolean",
          description: "Whether the search is case-sensitive. Default: false.",
        },
        file_extension_filter: {
          type: "string",
          description:
            "Optional: only search files with this extension (e.g., '.md', '.txt'). " +
            "Leave blank to search all supported file types.",
        },
      },
      required: ["docs_path", "keywords"],
    },
  • src/index.ts:34-34 (registration)
    Registration of the doc_search tool in the main index file.
    docSearchTool(),
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. It discloses some behavioral traits like case-insensitive search, multi-keyword AND logic, and supported file extensions, but misses critical details such as error handling (e.g., invalid paths), performance limits, output format specifics, or whether it's read-only/destructive. This leaves gaps for an agent to use it correctly.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose. It uses two sentences efficiently, though the second sentence is slightly dense with file extension details. Overall, it avoids unnecessary repetition and wastes little space.

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 no annotations and no output schema, the description is moderately complete for a search tool but has gaps. It covers what the tool does and some behavioral aspects, but lacks details on output format, error conditions, and performance constraints, which are important for an agent to invoke it effectively without structured output guidance.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema, mentioning 'case-insensitive' (covered by case_sensitive default) and 'searchable extensions' (implied by file_extension_filter), but does not provide additional syntax or format details. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose5/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 with specific verbs ('searches all documents') and resources ('local docs/ folder'), and distinguishes it from siblings by specifying it searches documents rather than executing code, reading repos, or running terminal commands. It provides concrete details about supported file types and search behavior.

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 implies usage for searching documents in a folder, but does not explicitly state when to use this tool versus alternatives like sibling tools (e.g., github_repo_reader for remote repos). It mentions the default directory ('docs/') but lacks explicit guidance on prerequisites or exclusions.

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/pathakkhhimanshu/MCP'

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