Skip to main content
Glama
cskwork

Knowledge Retrieval Server

by cskwork

search-documents

Search document chunks using BM25 algorithm with keywords and optional domain filtering to retrieve relevant information from knowledge bases.

Instructions

Search documents using BM25 algorithm. Takes keyword arrays and returns relevant document chunks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordsYesArray of keywords to search for (e.g., ["payment", "API", "authentication"])
domainNoDomain to search in (optional, e.g., "company", "customer")
topNNoMaximum number of results to return (default: 10)

Implementation Reference

  • Handler for 'search-documents' tool call. Extracts keywords, domain, topN from args, calls DocumentRepository.searchDocuments, and returns results as MCP TextContent.
    case 'search-documents': {
      const { keywords, domain, topN } = args as {
        keywords: string[];
        domain?: string;
        topN?: number;
      };
    
      const results = await repository.searchDocuments(keywords, {
        domain,
        topN,
        contextWindow: config.chunk.contextWindowSize
      });
    
      const content: TextContent[] = [{
        type: 'text',
        text: results
      }];
      
      return { content };
    }
  • src/index.ts:215-238 (registration)
    Registration of 'search-documents' tool in ListTools handler, including description and input schema definition.
    {
      name: 'search-documents',
      description: 'Search documents using BM25 algorithm. Takes keyword arrays and returns relevant document chunks.',
      inputSchema: {
        type: 'object',
        properties: {
          keywords: {
            type: 'array',
            items: { type: 'string' },
            description: 'Array of keywords to search for (e.g., ["payment", "API", "authentication"])'
          },
          domain: {
            type: 'string',
            description: 'Domain to search in (optional, e.g., "company", "customer")'
          },
          topN: {
            type: 'number',
            description: 'Maximum number of results to return (default: 10)',
            default: 10
          }
        },
        required: ['keywords']
      }
    },
  • Core implementation of document search using BM25. Selects appropriate calculator (domain-specific or global), constructs regex pattern from keywords, calls BM25.calculate, slices topN results, and formats output with context.
    async searchDocuments(
      keywords: string[],
      options: {
        domain?: string;
        topN?: number;
        contextWindow?: number;
      } = {}
    ): Promise<string> {
      this.ensureInitialized();
      const { domain, topN = 10, contextWindow = 1 } = options;
    
      // 검색할 계산기 선택
      let calculator: BM25Calculator | null;
      if (domain && this.domainCalculators.has(domain)) {
        calculator = this.domainCalculators.get(domain)!;
      } else {
        calculator = this.globalCalculator;
      }
    
      if (!calculator) {
        return "검색 가능한 문서가 없습니다.";
      }
    
      // 키워드를 정규식 패턴으로 변환
      const pattern = keywords
        .map(keyword => escapeRegExp(keyword.trim()))
        .filter(keyword => keyword.length > 0)
        .join("|");
    
      if (!pattern) {
        return "유효한 검색 키워드가 없습니다.";
      }
    
      // BM25 검색 수행
      const results = calculator.calculate(pattern);
      const topResults = results.slice(0, topN);
    
      return this.formatSearchResults(topResults, contextWindow);
    }
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 the BM25 algorithm and that it returns document chunks, but lacks critical details: it doesn't specify if this is a read-only operation (implied but not stated), whether it has rate limits, authentication needs, or how results are ranked/ordered. For a search tool with no annotations, this leaves significant gaps in understanding its behavior.

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 highly concise and front-loaded: two sentences that directly state the action ('Search documents using BM25 algorithm'), inputs ('Takes keyword arrays'), and outputs ('returns relevant document chunks'). Every word earns its place with no redundancy or fluff, making it easy for an agent to parse quickly.

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 complexity of a search tool with 3 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain the return format (e.g., structure of document chunks), error handling, or performance characteristics. While the purpose is clear, the lack of behavioral details and output information makes it inadequate for full contextual understanding, especially without annotations to compensate.

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 ('keywords', 'domain', 'topN') with descriptions and defaults. The description adds minimal value beyond the schema—it mentions 'keyword arrays' and 'returns relevant document chunks', but doesn't explain parameter interactions or provide additional context like format examples beyond what's in the schema. This meets the baseline of 3 for high schema coverage.

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 documents using BM25 algorithm' specifies the verb (search) and resource (documents), and 'returns relevant document chunks' clarifies the output. It distinguishes from siblings like 'get-document-by-id' (retrieval by ID) and 'list-domains' (listing domains), though not explicitly. However, it doesn't fully differentiate from 'get-chunk-with-context' (which might retrieve specific chunks), keeping it at 4 rather than 5.

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. It doesn't mention when to choose this over 'get-chunk-with-context' for contextual retrieval or 'list-domains' for domain exploration. There's no context about prerequisites, exclusions, or typical use cases, leaving the agent to infer usage from the purpose alone.

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/cskwork/keyword-rag-mcp'

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