Skip to main content
Glama

read_file

View existing code files by reading contents from the local file system. Access files using relative or absolute paths to examine project code.

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 readFile method implements the core logic of the 'read_file' tool. It resolves the file path using resolvePath, reads the file contents with fs.readFile, and returns the content formatted as MCP response.
    async readFile(filePath) { const resolvedPath = this.resolvePath(filePath); const content = await fs.readFile(resolvedPath, 'utf-8'); return { content: [ { type: 'text', text: content, }, ], }; }
  • The input schema for the 'read_file' tool, defining the required 'path' parameter as a 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 ListToolsRequest handler, providing name, description, and input 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'], }, },
  • index.js:163-164 (registration)
    Dispatch handler in the CallToolRequest switch statement that routes 'read_file' calls to the readFile method.
    case 'read_file': return await this.readFile(args.path);
  • Helper method resolvePath used by readFile to handle relative and absolute paths relative to PROJECTS_DIR.
    resolvePath(inputPath) { if (!inputPath || inputPath === '.') { return PROJECTS_DIR; } if (path.isAbsolute(inputPath)) { return inputPath; } return path.join(PROJECTS_DIR, inputPath); }

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