Skip to main content
Glama

search_docs

Search through project documentation files with highlighted results to quickly locate relevant information and enhance accessibility. Simplify knowledge discovery within your project directory.

Instructions

Search across documentation files with highlighted results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesPath to the project root directory
queryYesSearch query to find in documentation

Implementation Reference

  • The handler for the 'search_docs' tool in the CallToolRequestSchema switch statement. Extracts arguments, calls the searchDocContent helper function, formats results as JSON with cache metadata, and handles errors.
    case "search_docs": {
      const { projectPath, query } = request.params.arguments as {
        projectPath: string;
        query: string;
      };
    
      try {
        const results = await searchDocContent(projectPath, query);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                query,
                results,
                cache: {
                  timestamp: state.contextCache.timestamp,
                  ttl: CACHE_TTL,
                  expires: state.contextCache.timestamp ?
                    new Date(state.contextCache.timestamp + CACHE_TTL).toISOString() :
                    null
                }
              }, null, 2)
            }
          ]
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new McpError(
          ErrorCode.InternalError,
          `Error searching documentation: ${errorMessage}`
        );
      }
    }
  • Input schema definition for the search_docs tool, specifying projectPath and query parameters.
    inputSchema: {
      type: "object",
      properties: {
        projectPath: {
          type: "string",
          description: "Path to the project root directory"
        },
        query: {
          type: "string",
          description: "Search query to find in documentation"
        }
      },
      required: ["projectPath", "query"]
    }
  • src/index.ts:512-529 (registration)
    Registration of the search_docs tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: "search_docs",
      description: "Search across documentation files with highlighted results",
      inputSchema: {
        type: "object",
        properties: {
          projectPath: {
            type: "string",
            description: "Path to the project root directory"
          },
          query: {
            type: "string",
            description: "Search query to find in documentation"
          }
        },
        required: ["projectPath", "query"]
      }
    },
  • Helper function implementing the core search logic: caches queries, performs regex search on lines of each doc file in .handoff_docs/, collects highlighted matches per file.
    const searchDocContent = async (projectPath: string, query: string): Promise<SearchResult[]> => {
      // Check cache first
      if (
        state.contextCache.lastQuery === query &&
        state.contextCache.results &&
        state.contextCache.timestamp &&
        Date.now() - state.contextCache.timestamp < CACHE_TTL
      ) {
        return state.contextCache.results;
      }
    
      const results: SearchResult[] = [];
      const docsPath = `${projectPath}/.handoff_docs`;
      const searchRegex = new RegExp(query, 'gi');
    
      for (const doc of DEFAULT_DOCS) {
        try {
          const content = await fs.readFile(`${docsPath}/${doc}`, 'utf8');
          const lines = content.split('\n');
          const matches = lines
            .map((line, index) => {
              const match = searchRegex.exec(line);
              if (match) {
                return {
                  line,
                  lineNumber: index + 1,
                  highlight: {
                    start: match.index,
                    end: match.index + match[0].length
                  }
                };
              }
              return null;
            })
            .filter((match): match is NonNullable<typeof match> => match !== null);
    
          if (matches.length > 0) {
            results.push({ file: doc, matches });
          }
        } catch (error) {
          console.error(`Error searching ${doc}:`, error);
        }
      }
    
      // Update cache
      state.contextCache = {
        lastQuery: query,
        results,
        timestamp: Date.now()
      };
    
      return results;
    };
  • Type definition for SearchResult, structuring the output of search results with file and per-line match highlights.
    interface SearchResult {
      file: string;
      matches: Array<{
        line: string;
        lineNumber: number;
        highlight: {
          start: number;
          end: number;
        };
      }>;
    }
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 of behavioral disclosure. It mentions 'highlighted results' which hints at output formatting, but doesn't cover critical aspects like whether this is a read-only operation, performance characteristics, error handling, or authentication needs. 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 a single, efficient sentence that communicates the core functionality without unnecessary words. It's appropriately sized for a straightforward search tool and front-loads the essential information.

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?

Given the lack of annotations and output schema, the description should do more to compensate. While the purpose is clear, it doesn't explain what the search returns (beyond 'highlighted results'), how results are structured, or any limitations. For a tool with 2 parameters and no structured output documentation, this is incomplete.

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 fully documents both parameters (projectPath and query). The description adds no additional parameter information beyond what's in the schema. This meets the baseline of 3 when the schema does the heavy lifting, but doesn't provide extra value like explaining search syntax or path requirements.

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 action ('Search') and target resource ('documentation files'), and mentions 'highlighted results' which adds specificity. However, it doesn't explicitly differentiate from sibling tools like 'get_related_docs' or 'analyze_existing_docs', which might also involve documentation searching or analysis.

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 siblings like 'get_related_docs' and 'analyze_existing_docs' that might overlap in functionality, there's no indication of when this search tool is preferred or what distinguishes it from other documentation-related tools.

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

Related 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/ryanjoachim/mcp-rtfm'

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