get_document
Retrieve detailed information about a specific document by providing its unique ID using the MCP Knowledge Base Server. Access indexed content from formats like PDF, DOCX, TXT, and HTML for efficient document handling.
Instructions
获取特定文档信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | 文档ID |
Input Schema (JSON Schema)
{
"properties": {
"document_id": {
"description": "文档ID",
"type": "string"
}
},
"required": [
"document_id"
],
"type": "object"
}
Implementation Reference
- src/mcp-server.ts:239-264 (handler)Handler for the 'get_document' tool. Extracts document_id from arguments, calls 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 ListTools response, defining name, description, and input schema requiring 'document_id'.{ name: 'get_document', description: '获取特定文档信息', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } },
- src/knowledge-base.ts:162-164 (helper)Core helper method in KnowledgeBase class that retrieves and returns the Document by ID from the internal documents Map.async getDocument(id: string): Promise<Document | undefined> { return this.documents.get(id); }