Skip to main content
Glama
th3w1zard1

Cedardiff MCP Server

by th3w1zard1

edit_file

Modify file content using CEDARScript commands. Specify working directory and script to execute precise code changes for efficient file manipulation.

Instructions

Edit a file using CEDARScript syntax

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesCEDARScript commands to execute
workingDirYesWorking directory for resolving file paths

Implementation Reference

  • Main handler for the 'edit_file' tool within the CallToolRequestSchema. Validates the tool name, parses arguments, reads the target file, executes the CEDARScript, writes changes back, and returns success/error content.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== 'edit_file') {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    
      if (!request.params.arguments || 
          typeof request.params.arguments.script !== 'string' ||
          typeof request.params.arguments.workingDir !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Missing or invalid file/script arguments'
        );
      }
    
      const { script, workingDir } = request.params.arguments;
      
      try {
        // Extract file path from script
        const fileMatch = script.match(/FILE\s+['"]([^'"]+)['"]/i);
        if (!fileMatch) {
          throw new Error('Script must specify a file using FILE "path"');
        }
        const filePath = path.resolve(workingDir, fileMatch[1]);
    
        // Read the file
        const content = fs.readFileSync(filePath, 'utf8');
    
        // Parse and execute the CEDARScript
        const newContent = this.executeCedarScript(content, script);
    
        // Write back to file
        fs.writeFileSync(filePath, newContent);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully edited ${filePath}`,
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: `Error editing file: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    });
  • Input schema definition for the 'edit_file' tool, specifying required 'script' and 'workingDir' parameters.
    inputSchema: {
      type: 'object',
      properties: {
        script: {
          type: 'string',
          description: 'CEDARScript commands to execute'
        },
        workingDir: {
          type: 'string',
          description: 'Working directory for resolving file paths'
        }
      },
      required: ['script', 'workingDir'],
    },
  • src/index.ts:65-86 (registration)
    Registers the 'edit_file' tool in the ListToolsRequestSchema handler, providing name, description, and schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'edit_file',
          description: 'Edit a file using CEDARScript syntax',
          inputSchema: {
            type: 'object',
            properties: {
              script: {
                type: 'string',
                description: 'CEDARScript commands to execute'
              },
              workingDir: {
                type: 'string',
                description: 'Working directory for resolving file paths'
              }
            },
            required: ['script', 'workingDir'],
          },
        },
      ],
    }));
  • Helper function that splits file content into lines, parses the CEDARScript into commands, executes them, and rejoins the lines.
    private executeCedarScript(content: string, script: string): string {
      const lines = content.split('\n');
      let result = [...lines];
    
      // Parse the script into commands
      const commands = this.parseScript(script);
    
      // Execute each command
      for (const command of commands) {
        result = this.executeCommand(command, result);
      }
    
      return result.join('\n');
    }
  • Helper function that parses the CEDARScript string into an array of command objects by splitting on semicolons and dispatching to specific parsers.
    private parseScript(script: string): Array<{
      type: 'update' | 'create' | 'rm_file' | 'mv_file';
      caseStatement?: CaseStatement;
      filePath?: string;
      content?: string;
      targetPath?: string;
    }> {
      const commands: Array<{
        type: 'update' | 'create' | 'rm_file' | 'mv_file';
        targetPath?: string;
      }> = [];
      
      // Split into individual commands (separated by semicolons)
      const commandStrings = script.split(';').map(cmd => cmd.trim()).filter(Boolean);
    
      for (const cmdStr of commandStrings) {
        if (cmdStr.startsWith('UPDATE')) {
          commands.push(this.parseUpdateCommand(cmdStr));
        } else if (cmdStr.startsWith('CREATE')) {
          commands.push(this.parseCreateCommand(cmdStr));
        } else if (cmdStr.startsWith('RM')) {
          commands.push(this.parseRmCommand(cmdStr));
        } else if (cmdStr.startsWith('MV')) {
          commands.push(this.parseMvCommand(cmdStr));
        }
      }
    
      return commands;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'Edit a file' which implies mutation, but fails to describe critical behaviors like permissions required, whether edits are reversible, error handling, or side effects. This leaves significant gaps for a mutation tool.

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 with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration, 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 that this is a mutation tool with no annotations and no output schema, the description is insufficiently complete. It lacks details on behavioral traits, error conditions, return values, or practical usage context, which are critical for safe and effective tool invocation.

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?

The schema description coverage is 100%, so the schema already fully documents both parameters ('script' and 'workingDir'). The description adds no additional parameter semantics beyond what's in the schema, such as examples of CEDARScript commands or working directory conventions, meeting 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 clearly states the action ('Edit a file') and specifies the method ('using CEDARScript syntax'), providing a specific verb+resource combination. However, without sibling tools for comparison, it cannot demonstrate differentiation from alternatives, 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 other file editing methods or alternatives. It lacks context about prerequisites, constraints, or typical use cases, offering only the basic functionality without usage context.

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

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/th3w1zard1/cedarscript-mcp'

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