get_document
Retrieve specific document information from a knowledge base by providing its document ID. This tool accesses indexed documents in formats like PDF, DOCX, TXT, and HTML for content reference and analysis.
Instructions
获取特定文档信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | 文档ID |
Implementation Reference
- src/mcp-server.ts:239-264 (handler)The main handler for the 'get_document' tool. It extracts document_id from arguments, retrieves the document using knowledgeBase.getDocument, handles not found case, and returns formatted document information including title, ID, type, path, dates, and content preview.
case 'get_document': { const { document_id } = args as { document_id: string }; const document = await this.knowledgeBase.getDocument(document_id); if (!document) { return { content: [ { type: 'text', text: `未找到ID为 "${document_id}" 的文档` } ] }; } const resultText = `文档信息:\n\n标题: ${document.title}\nID: ${document.id}\n类型: ${document.fileType}\n路径: ${document.filePath}\n创建时间: ${document.createdAt.toLocaleString()}\n更新时间: ${document.updatedAt.toLocaleString()}\n\n内容预览:\n${document.content.substring(0, 500)}...`; return { content: [ { type: 'text', text: resultText } ] }; } - src/mcp-server.ts:106-119 (registration)Registration of the 'get_document' tool in the list of tools returned by ListToolsRequestHandler, including name, description, and input schema.
{ name: 'get_document', description: '获取特定文档信息', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } }, - src/mcp-server.ts:109-118 (schema)Input schema definition for the 'get_document' tool, specifying document_id as required string.
inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } - src/knowledge-base.ts:162-164 (helper)Core helper function in KnowledgeBase class that retrieves a Document by ID from the internal documents Map.
async getDocument(id: string): Promise<Document | undefined> { return this.documents.get(id); }