Skip to main content
Glama

read_file

View and access file contents from your local development projects directory to examine code, configuration files, and documentation.

Instructions

Read the contents of a file from the local file system. Use this to view existing code files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file (relative to projects directory or absolute)

Implementation Reference

  • The handler function that implements the core logic of the 'read_file' tool. It resolves the input path and reads the file contents using fs.promises.readFile, returning the content in the MCP format.
    async readFile(filePath) { const resolvedPath = this.resolvePath(filePath); const content = await fs.readFile(resolvedPath, 'utf-8'); return { content: [ { type: 'text', text: content, }, ], }; }
  • JSON schema defining the input parameters for the 'read_file' tool, specifying a required 'path' string.
    inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file (relative to projects directory or absolute)', }, }, required: ['path'], },
  • index.js:47-60 (registration)
    Registration of the 'read_file' tool in the ListToolsRequestSchema handler, including name, description, and schema.
    { name: 'read_file', description: 'Read the contents of a file from the local file system. Use this to view existing code files.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file (relative to projects directory or absolute)', }, }, required: ['path'], }, },
  • Helper method used by read_file (and other tools) to resolve relative paths to absolute paths based on the PROJECTS_DIR.
    resolvePath(inputPath) { if (!inputPath || inputPath === '.') { return PROJECTS_DIR; } if (path.isAbsolute(inputPath)) { return inputPath; } return path.join(PROJECTS_DIR, inputPath); }
  • Dispatch handler in the CallToolRequestSchema switch statement that routes 'read_file' calls to the readFile method.
    case 'read_file': return await this.readFile(args.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/talentedmrweb/local-dev-bridge-mcp'

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