get-markdown-file
Retrieve a Markdown file by specifying its absolute file path. This tool on the Markdownify MCP Server enables quick extraction of Markdown-formatted content for further use or conversion.
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/Markdownify.ts:126-157 (handler)Core handler function that reads and validates the markdown file content using fs.promises.readFilestatic 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:88-95 (handler)Dispatch handler in CallToolRequestSchema that calls Markdownify.get for the get-markdown-file toolcase 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/tools.ts:141-154 (schema)Tool schema defining input parameters for get-markdown-fileexport 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:33-37 (registration)Registration of all tools including get-markdown-file via Object.values(tools) in ListToolsRequest handlerserver.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(tools), }; });