Skip to main content
Glama

search_docs

Search documentation with query strings, filter by document category, and paginate results to locate specific information.

Instructions

Search documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
max_resultsNoMaximum number of results
doc_nameNoFilter by document category
offsetNoNumber of results to skip

Implementation Reference

  • The handler for the search_docs tool. Extracts query, maxResults, docName, and offset from arguments, then calls searchEngine.search() and returns results with score, title, and excerpt.
    case "search_docs": {
      const query = String(request.params.arguments?.query);
      const maxResults = Number(request.params.arguments?.max_results) || 3;
      const docName = request.params.arguments?.doc_name ?
        String(request.params.arguments.doc_name) : undefined;
      const offset = Number(request.params.arguments?.offset) || 0;
      const results = await searchEngine.search(query, maxResults, docName, 0.2, offset);
      return {
        content: results.map(result => ({
          type: "text",
          text: `[${result.score.toFixed(2)}] ${result.title}\n${result.excerpt}\n---`
        }))
      };
    }
  • Schema/registration of the search_docs tool in the ListToolsRequestSchema handler. Defines input properties: query (required string), max_results (number, default 3), doc_name (string), offset (number, default 0).
    {
      name: "search_docs",
      description: "Search documentation",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query"
          },
          max_results: {
            type: "number",
            description: "Maximum number of results",
            default: 3
          },
          doc_name: {
            type: "string",
            description: "Filter by document category"
          },
          offset: {
            type: "number",
            description: "Number of results to skip",
            default: 0
          }
        },
        required: ["query"]
      }
    },
  • The SearchEngine.search() method that performs the actual search using lunr. Filters results by docName if provided, filters by minScore, applies pagination via offset and maxResults, and returns scored results with excerpts.
    async search(query: string, maxResults = 3, docName?: string, minScore = 0.2, offset = 0) {
      if (!this.index) {
        throw new Error('Index not initialized');
      }
    
      let results = this.index.search(query);
      
      // 按文档分类筛选
      if (docName) {
        results = results.filter(result => {
          const doc = this.docStore[result.ref];
          return doc.title.startsWith(`${docName}/`);
        });
      }
    
      // 按分数筛选
      results = results.filter(result => result.score >= minScore);
    
      return results.slice(offset, offset + maxResults).map(result => {
        const doc = this.docStore[result.ref];
        return {
          path: doc.path,
          score: result.score,
          title: doc.title,
          excerpt: this.createExcerpt(doc.content, query)
        };
      });
    }
  • The createExcerpt() helper method in SearchEngine used by search() to generate a text excerpt around the query match, highlighting the query term with ** markers.
    private createExcerpt(content: string, query: string): string {
      const pos = content.toLowerCase().indexOf(query.toLowerCase());
      const start = Math.max(0, pos - 400);
      const end = Math.min(content.length, pos + query.length + 400);
      let excerpt = content.slice(start, end);
      
      if (pos >= 0) {
        excerpt = excerpt.replace(
          new RegExp(query, 'gi'),
          match => `**${match}**`
        );
      }
      
      return excerpt;
    }
  • Initialization and import of SearchEngine which is used by the search_docs handler.
    const searchEngine = new SearchEngine(docDir);
    await searchEngine.initialize();
Behavior2/5

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

With no annotations provided, the description must convey behavioral traits. The phrase 'Search documentation' gives no indication of whether this is a read-only operation, what resources are accessed, or potential side effects. It is essentially a tautology of the tool name, so the score is 2 (tautology).

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 extremely concise (only two words), with no wasted text. It is front-loaded and efficient, but the brevity sacrifices meaningful content. A score of 4 reflects that it is concise without being verbose, though it could be improved with more substance.

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

Completeness1/5

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

Given the tool has 4 parameters, no annotations, and no output schema, the description is severely inadequate. It does not explain return values, pagination via offset, result limits via max_results, filtering via doc_name, or any behavioral aspects. This is completely inadequate for the agent to use the tool effectively, hence a score of 1.

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?

The input schema has 100% description coverage for all 4 parameters, so the baseline is 3. The description adds no additional parameter context beyond what is in the schema, so it does not exceed the baseline.

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

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search documentation' clearly states the verb and resource, making the basic purpose understandable. However, it does not differentiate from sibling tools like 'list_all_docs' or 'build_index', and it lacks specificity about the kind of search (e.g., full-text, fuzzy). It is not misleading but is minimal.

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?

No guidance is provided on when to use this tool versus alternatives. The agent receives no context about whether to prefer 'search_docs' over 'list_all_docs' or 'crawl_docs'. This omission leaves the agent with no decision support, resulting in a score of 2 (no guidance).

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/askme765cs/open-docs-mcp'

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