Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYes

Implementation Reference

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

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/alekspetrov/mcp-docs-service'

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