Skip to main content
Glama

read_file

Read complete file contents from the file system to examine text before editing. Handles various text encodings and returns full file content.

Instructions

Read the complete contents of a file from the file system. Handles various text encodings and returns the full file content. Use this to examine file contents before editing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe path to the file to read (absolute or relative)

Implementation Reference

  • The handler function for the 'read_file' tool. It extracts the file path from arguments, reads the file content asynchronously using Node.js fs.promises.readFile, and returns the content wrapped in the MCP ToolResult format with type 'text'.
    case "read_file": { const filePath = args.path as string; const content = await fs.readFile(filePath, "utf-8"); return { content: [ { type: "text", text: content, }, ], }; }
  • The input schema for the 'read_file' tool, defining an object with a required 'path' string property.
    inputSchema: { type: "object", properties: { path: { type: "string", description: "The path to the file to read (absolute or relative)", }, }, required: ["path"], },
  • src/index.ts:20-33 (registration)
    The Tool object registration for 'read_file' in the TOOLS array, which is returned by the listTools handler. Includes name, description, and inputSchema.
    { name: "read_file", description: "Read the complete contents of a file from the file system. Handles various text encodings and returns the full file content. Use this to examine file contents before editing.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The path to the file to read (absolute or relative)", }, }, required: ["path"], }, },
  • src/index.ts:261-263 (registration)
    The server request handler for ListToolsRequestSchema that returns the TOOLS array, effectively registering all tools including 'read_file'.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: 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/koopatroopa787/first_mcp'

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