UNPKG

@bucketeer/docs-local-mcp-server

Version:
40 lines (39 loc) 1.66 kB
import { z } from 'zod'; export function createGetDocumentTool(searchService) { return { name: 'get_document', description: 'Retrieve the full content of a specific document by its path.', inputSchema: z.object({ path: z.string().describe('The path of the document to retrieve.'), }), execute: async ({ path }) => { try { console.error(`[MCP Tool] Received get_document request for path: "${path}"`); const document = searchService.getDocument(path); if (!document) { const errorContent = { type: 'text', text: JSON.stringify({ error: `Document not found: ${path}` }), }; return { content: [errorContent], isError: true }; } const responseContent = { type: 'text', text: JSON.stringify(document, null, 2), }; return { content: [responseContent] }; } catch (error) { console.error(`[MCP Tool] Error processing get_document request for path "${path}":`, error); const errorMessage = error instanceof Error ? error.message : String(error); const errorContent = { type: 'text', text: JSON.stringify({ error: `Failed to get document: ${errorMessage}`, }), }; return { content: [errorContent], isError: true }; } }, }; }