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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Read contents' which implies a read-only operation, but doesn't mention potential limitations like file size constraints, permission requirements, error handling for missing files, or whether it returns raw text or structured data. This leaves significant gaps for a tool that interacts with file systems.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without any unnecessary words. It's front-loaded with the core action and resource, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of file operations and the lack of annotations and output schema, the description is insufficient. It doesn't cover behavioral aspects like what happens if files don't exist, how large files are handled, or the format of returned content. For a tool with no structured safety or output information, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear documentation for both parameters ('files' as an array of file paths and 'encoding' with a default). The description adds no additional parameter semantics beyond what the schema provides, such as examples of valid file paths or encoding options. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Read contents of specific files' clearly states the verb ('Read') and resource ('contents of specific files'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'search_files' or 'get_directory_structure' that might also involve file content access, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'search_files' (which might return file contents as part of results) or 'get_directory_structure' (which might include content summaries), there's no indication of when this specific read operation is preferred, leaving usage ambiguous.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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