Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

get_file_contents

Read and retrieve contents of specified files with custom encoding support for efficient file management and analysis in the Enhanced Directory Context MCP Server.

Instructions

Read contents of specific files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encodingNoFile encoding (default: utf8)utf8
filesYesArray of file paths to read

Implementation Reference

  • The handler function that implements the get_file_contents tool logic. It reads the contents of the specified files relative to the working directory using fs.readFile, handles errors per file, and returns a JSON object with results.
    async handleGetFileContents(args) { const { files, encoding = 'utf8' } = args; const results = {}; for (const file of files) { try { const fullPath = path.resolve(this.workingDirectory, file); const content = await fs.readFile(fullPath, encoding); results[file] = content; } catch (error) { results[file] = { error: error.message }; } } return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; }
  • The tool definition including name, description, and input schema for get_file_contents, returned by the ListTools handler.
    { name: 'get_file_contents', description: 'Read contents of specific files', inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'Array of file paths to read', items: { type: 'string' }, }, encoding: { type: 'string', description: 'File encoding (default: utf8)', default: 'utf8', }, }, required: ['files'], }, },
  • server.js:460-461 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes calls to the get_file_contents tool to its handler function.
    case 'get_file_contents': return await this.handleGetFileContents(args);

Other Tools

Related 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/PWalaGov/File-Control-MCP'

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