Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

get_file_contents

Read contents of specific files to access their data directly, supporting multiple file paths and configurable encoding options for file analysis.

Instructions

Read contents of specific files

Input Schema

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

Implementation Reference

  • The main execution function for the 'get_file_contents' tool. It reads contents from multiple specified files relative to the server's working directory using Node.js fs.readFile, handles encoding, manages errors per file, and returns a standardized MCP response with JSON-stringified 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), }, ], }; }
  • JSON Schema defining the input parameters for the tool: an object with 'files' (required array of relative file paths) and optional 'encoding' (string, defaults to 'utf8'). Used for validation in MCP tool calls.
    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:89-108 (registration)
    The tool definition object registered with the MCP server via setTools(), specifying name, description, and input schema for 'get_file_contents'.
    { 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)
    Dispatch logic in the CallToolRequest handler switch statement that maps the tool name to its handler method.
    case 'get_file_contents': return await this.handleGetFileContents(args);

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