read_document
Retrieve and examine the content of a single markdown document from the documentation directory, including frontmatter metadata.
Instructions
Read a markdown document from the docs directory. Returns the document content including frontmatter. Use this tool when you need to examine the contents of a single document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/handlers/documents.ts:116-138 (handler)The core handler function for the read_document tool. It validates the document path, reads the file content using fs.readFile, extracts frontmatter metadata, and returns a ToolResponse object.async readDocument(docPath: string): Promise<ToolResponse> { try { const validPath = await this.validatePath(docPath); const content = await fs.readFile(validPath, "utf-8"); return { content: [{ type: "text", text: content }], metadata: { path: docPath, ...parseFrontmatter(content).frontmatter, }, }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error reading document: ${errorMessage}` }, ], isError: true, }; } }
- src/schemas/tools.ts:9-11 (schema)Zod schema for validating input to the read_document tool. Requires a 'path' parameter specifying the document to read.export const ReadDocumentSchema = ToolInputSchema.extend({ path: z.string(), });
- src/index.ts:199-205 (registration)Tool registration in the listToolsRequestSchema handler, defining the tool's name, description, and input schema for MCP protocol.name: "read_document", description: "Read a markdown document from the docs directory. Returns the document content " + "including frontmatter. Use this tool when you need to examine the contents of a " + "single document.", inputSchema: zodToJsonSchema(ReadDocumentSchema) as any, },
- src/index.ts:311-319 (registration)Dispatch logic in the callToolRequestSchema handler that validates arguments using the schema and calls the documentHandler.readDocument method.case "read_document": { const parsed = ReadDocumentSchema.safeParse(args); if (!parsed.success) { throw new Error( `Invalid arguments for read_document: ${parsed.error}` ); } return await documentHandler.readDocument(parsed.data.path); }