doc_read
Read document content from a specified file path, enabling local LLMs to access and process text directly for analysis or further tasks.
Instructions
Alias of doc.read
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/tools/doc.ts:101-110 (handler)The actual handler function for doc_read. Resolves the path, enforces sandbox restriction, reads the file (supports text and PDF), and returns {path, text}.
export async function docRead(p: string) { const full = path.resolve(p); if (!full.startsWith(CONFIG.sandboxDir)) throw new Error('Access outside sandbox is not allowed'); const buf = await fs.readFile(full); let text = ''; if (/\.pdf$/i.test(full)) { try { const parsed = await pdfParseLazy(buf as unknown as Buffer); text = parsed.text || ''; } catch { text = ''; } } else { text = buf.toString('utf-8'); } return { path: full, text }; } - src/server.ts:124-139 (registration)Registers both 'doc.read' (primary) and 'doc_read' (alias) tools with the MCP server using the same shape and handler.
// ===== doc.read + alias ===== const docReadShape = { path: z.string() }; server.tool('doc.read', 'Read a file from sandbox directory (text or pdf).', docReadShape, OPEN, async ({ path }) => { const res = await docRead(path); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } ); server.tool('doc_read', 'Alias of doc.read', docReadShape, OPEN, async ({ path }) => { const res = await docRead(path); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } ); - src/server.ts:125-125 (schema)Input shape for doc_read: a single required string field 'path'.
const docReadShape = { path: z.string() }; - src/tools/doc.ts:9-21 (helper)Lazy-loaded PDF parser helper used by docRead when the file is a PDF.
let _pdfParse: any | null = null; async function pdfParseLazy(buf: Buffer): Promise<{ text: string }> { try { if (!_pdfParse) { const mod = await import('pdf-parse'); _pdfParse = (mod as any).default || (mod as any); } const out = await _pdfParse(buf); return { text: String(out.text || '') }; } catch { return { text: '' }; } }