Skip to main content
Glama
little2512
by little2512

search_documents

Search Word documents using full-text indexing to find relevant content across multiple document types with support for both English and Chinese queries.

Instructions

全文索引搜索,支持中英文混合搜索

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes搜索关键词
documentTypeNo限制搜索的文档类型
limitNo返回结果数量限制

Implementation Reference

  • Handler for the 'search_documents' tool. Parses input arguments, invokes the DocumentIndexer.search method, applies filtering by documentType and limit, formats and returns search results or no-results message.
    case "search_documents": { const { query, documentType, limit = 10 } = args; const searchResults = documentIndexer.search(query); // 按文档类型过滤 const filteredResults = documentType ? searchResults.filter(result => result.document.documentType === documentType) : searchResults; const limitedResults = filteredResults.slice(0, limit); if (limitedResults.length === 0) { return { content: [ { type: "text", text: `未找到包含关键词 "${query}" 的文档` } ] }; } const resultsText = limitedResults.map((result, index) => { const doc = result.document; return `${index + 1}. 相关度: ${result.score}\n 内存键: ${doc.memoryKey}\n 文件: ${doc.filePath}\n 类型: ${doc.documentType}\n 表格数: ${doc.tablesCount}\n 图片数: ${doc.imagesCount}\n 最后索引: ${new Date(doc.lastIndexed).toLocaleString()}`; }).join('\n\n'); return { content: [ { type: "text", text: `搜索结果 "${query}" (找到 ${limitedResults.length} 个匹配,共 ${filteredResults.length} 个):\n\n${resultsText}` } ] }; }
  • server.js:518-541 (registration)
    Registration of the 'search_documents' tool within the ListToolsRequestHandler response. Defines the tool's name, description, and input schema.
    { name: "search_documents", description: "全文索引搜索,支持中英文混合搜索", inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索关键词" }, documentType: { type: "string", description: "限制搜索的文档类型", enum: ["ui-component", "api-doc", "common-doc", "other"] }, limit: { type: "number", description: "返回结果数量限制", default: 10 } }, required: ["query"] } },
  • Input schema definition for the 'search_documents' tool, specifying required 'query' parameter and optional filters.
    inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索关键词" }, documentType: { type: "string", description: "限制搜索的文档类型", enum: ["ui-component", "api-doc", "common-doc", "other"] }, limit: { type: "number", description: "返回结果数量限制", default: 10 } }, required: ["query"]
  • Core search logic in DocumentIndexer class: tokenizes query into words, uses inverted index to find matching documents, computes simple frequency-based relevance scores, sorts and returns results with metadata.
    search(query) { const queryWords = this.extractWords(query.toLowerCase()); const documentScores = new Map(); queryWords.forEach(word => { const docs = this.index.get(word); if (docs) { docs.forEach(docId => { const score = documentScores.get(docId) || 0; documentScores.set(docId, score + 1); }); } }); // 按相关性排序 const results = Array.from(documentScores.entries()) .sort((a, b) => b[1] - a[1]) .map(([docId, score]) => ({ documentId, score, document: this.documents.get(docId) })); return results; }

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/little2512/word-doc-mcp'

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