get-markdown-file
Retrieve Markdown content from files using absolute file paths to access and work with formatted text documents.
Instructions
Get a markdown file by absolute file path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Absolute path to file of markdown'd text |
Implementation Reference
- src/tools.ts:141-154 (schema)Defines the ToolSchema for 'get-markdown-file', including name, description, and input schema requiring 'filepath'.export const GetMarkdownFileTool = ToolSchema.parse({ name: "get-markdown-file", description: "Get a markdown file by absolute file path", inputSchema: { type: "object", properties: { filepath: { type: "string", description: "Absolute path to file of markdown'd text", }, }, required: ["filepath"], }, });
- src/server.ts:88-95 (handler)Dispatches the tool call to Markdownify.get with the provided filepath, handling validation and error.case tools.GetMarkdownFileTool.name: if (!validatedArgs.filepath) { throw new Error("File path is required for this tool"); } result = await Markdownify.get({ filePath: validatedArgs.filepath, }); break;
- src/Markdownify.ts:126-157 (handler)Core implementation that validates the markdown file path (extension, existence, share dir), reads the file content using fs.promises.readFile, and returns path and text.static async get({ filePath, }: { filePath: string; }): Promise<MarkdownResult> { // Check file type is *.md or *.markdown const normPath = this.normalizePath(path.resolve(expandHome(filePath))); const markdownExt = [".md", ".markdown"]; if (!markdownExt.includes(path.extname(normPath))) { throw new Error("Required file is not a Markdown file."); } if (process.env?.MD_SHARE_DIR) { const allowedShareDir = this.normalizePath( path.resolve(expandHome(process.env.MD_SHARE_DIR)), ); if (!normPath.startsWith(allowedShareDir)) { throw new Error(`Only files in ${allowedShareDir} are allowed.`); } } if (!fs.existsSync(filePath)) { throw new Error("File does not exist"); } const text = await fs.promises.readFile(filePath, "utf-8"); return { path: filePath, text: text, }; }
- src/server.ts:33-37 (registration)Registers all tools from tools.ts (including GetMarkdownFileTool) for the listTools capability.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(tools), }; });