Skip to main content
Glama
StrawHatAI

Claude Desktop Commander MCP

by StrawHatAI

read_file

Retrieve file contents from your computer's file system. This tool reads text files within permitted directories and handles various encodings while providing clear error feedback.

Instructions

Read the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Handler for the read_file tool in the main server request handler. Parses args using the schema, calls the readFile helper, and returns the file content.
    case "read_file": { const parsed = ReadFileArgsSchema.parse(args); const content = await readFile(parsed.path); return { content: [{ type: "text", text: content }], }; }
  • Zod schema defining the input for read_file tool: requires a 'path' string.
    export const ReadFileArgsSchema = z.object({ path: z.string(), });
  • src/server.ts:126-132 (registration)
    Registration of the read_file tool in the ListToolsRequestHandler, including name, description, and input schema reference.
    name: "read_file", description: "Read the complete contents of a file from the file system. " + "Handles various text encodings and provides detailed error messages " + "if the file cannot be read. Only works within allowed directories.", inputSchema: zodToJsonSchema(ReadFileArgsSchema), },
  • Core implementation of file reading: validates the path for security and reads the file content using fs.readFile.
    export async function readFile(filePath: string): Promise<string> { const validPath = await validatePath(filePath); return fs.readFile(validPath, "utf-8"); }

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/StrawHatAI/claude-dev-tools'

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