Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYesAbsolute path to file of markdown'd text

Implementation Reference

  • 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"],
      },
    });
  • 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;
  • 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),
      };
    });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zcaceres/markdownify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server