doc_read
Reads and extracts content from documents to provide information for local LLMs. Use this tool to access file contents without requiring API keys.
Instructions
Alias of doc.read
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/tools/doc.ts:101-110 (handler)The core handler function that reads the content of a file (text or PDF) from the sandbox directory, resolves the path, checks access permissions, parses PDF if necessary, and returns the path and text content.
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:125-125 (schema)Zod schema defining the input for the doc_read tool: a string path parameter.
const docReadShape = { path: z.string() }; - src/server.ts:133-139 (registration)Registration of the 'doc_read' tool on the MCP server, which is an alias calling the docRead handler with the provided path and formatting the response.
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) }] }; } );