Skip to main content
Glama
sailay1996

Cursor Agent MCP Server

by sailay1996

cursor_agent_edit_file

Edit files using natural language instructions to modify code or content without command-line commands. Specify file and edit direction to apply changes or preview modifications.

Instructions

Edit a file with an instruction. Prompt-based wrapper; no CLI subcommand required.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
instructionYes
applyNo
dry_runNo
promptNo
output_formatNotext
extra_argsNo
cwdNo
executableNo
modelNo
forceNo
echo_promptNo

Implementation Reference

  • Handler function for cursor_agent_edit_file tool. Composes a prompt using the file path and edit instruction, optionally including apply/dry_run/prompt flags, then invokes runCursorAgent.
      async (args) => {
        try {
          const { file, instruction, apply, dry_run, prompt, output_format, cwd, executable, model, force, extra_args } = args;
          const composedPrompt =
            `Edit the repository file:\n` +
            `- File: ${String(file)}\n` +
            `- Instruction: ${String(instruction)}\n` +
            (apply ? `- Apply changes if safe.\n` : `- Propose a patch/diff without applying.\n`) +
            (dry_run ? `- Treat as dry-run; do not write to disk.\n` : ``) +
            (prompt ? `- Additional context: ${String(prompt)}\n` : ``);
          return await runCursorAgent({ prompt: composedPrompt, output_format, extra_args, cwd, executable, model, force });
        } catch (e) {
          return { content: [{ type: 'text', text: `Invalid params: ${e?.message || e}` }], isError: true };
        }
      },
    );
  • Zod input schema for cursor_agent_edit_file tool, defining required file and instruction, optional apply, dry_run, prompt, and common fields.
    const EDIT_FILE_SCHEMA = z.object({
     file: z.string().min(1, 'file is required'),
     instruction: z.string().min(1, 'instruction is required'),
     apply: z.boolean().optional(),
     dry_run: z.boolean().optional(),
     // optional free-form prompt to pass if the CLI supports one
     prompt: z.string().optional(),
     ...COMMON,
    });
  • server.js:299-318 (registration)
    MCP server.tool registration for cursor_agent_edit_file, linking name, description, schema, and handler function.
    server.tool(
      'cursor_agent_edit_file',
      'Edit a file with an instruction. Prompt-based wrapper; no CLI subcommand required.',
      EDIT_FILE_SCHEMA.shape,
      async (args) => {
        try {
          const { file, instruction, apply, dry_run, prompt, output_format, cwd, executable, model, force, extra_args } = args;
          const composedPrompt =
            `Edit the repository file:\n` +
            `- File: ${String(file)}\n` +
            `- Instruction: ${String(instruction)}\n` +
            (apply ? `- Apply changes if safe.\n` : `- Propose a patch/diff without applying.\n`) +
            (dry_run ? `- Treat as dry-run; do not write to disk.\n` : ``) +
            (prompt ? `- Additional context: ${String(prompt)}\n` : ``);
          return await runCursorAgent({ prompt: composedPrompt, output_format, extra_args, cwd, executable, model, force });
        } catch (e) {
          return { content: [{ type: 'text', text: `Invalid params: ${e?.message || e}` }], isError: true };
        }
      },
    );
  • Shared helper invoked by the handler to execute cursor-agent CLI with the composed prompt.
    // Accepts either a flat args object or an object with an "arguments" field (some hosts).
    async function runCursorAgent(input) {
      const source = (input && typeof input === 'object' && input.arguments && typeof input.prompt === 'undefined')
        ? input.arguments
        : input;
    
      const {
        prompt,
        output_format = 'text',
        extra_args,
        cwd,
        executable,
        model,
        force,
      } = source || {};
    
      const argv = [...(extra_args ?? []), String(prompt)];
      const usedPrompt = argv.length ? String(argv[argv.length - 1]) : '';
     
      // Optional prompt echo and debug diagnostics
      if (process.env.DEBUG_CURSOR_MCP === '1') {
        try {
          const preview = usedPrompt.slice(0, 400).replace(/\n/g, '\\n');
          console.error('[cursor-mcp] prompt:', preview);
          if (extra_args?.length) console.error('[cursor-mcp] extra_args:', JSON.stringify(extra_args));
          if (model) console.error('[cursor-mcp] model:', model);
          if (typeof force === 'boolean') console.error('[cursor-mcp] force:', String(force));
        } catch {}
      }
     
      const result = await invokeCursorAgent({ argv, output_format, cwd, executable, model, force });
     
      // Echo prompt either when env is set or when caller provided echo_prompt: true (if host forwards unknown args it's fine)
      const echoEnabled = process.env.CURSOR_AGENT_ECHO_PROMPT === '1' || source?.echo_prompt === true;
      if (echoEnabled) {
        const text = `Prompt used:\n${usedPrompt}`;
        const content = Array.isArray(result?.content) ? result.content : [];
        return { ...result, content: [{ type: 'text', text }, ...content] };
      }
     
      return result;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions being a 'Prompt-based wrapper' which suggests AI-driven editing rather than direct manipulation, but fails to describe critical behaviors: whether edits are destructive, authentication needs, rate limits, error handling, or what 'edit' actually does to the file. The mention of 'no CLI subcommand required' is helpful but insufficient for a tool with 12 parameters.

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

Conciseness4/5

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

The description is appropriately brief with two concise sentences that each add value: the first states the core function, the second provides implementation context. No wasted words, though it could be more front-loaded with clearer purpose.

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 (12 parameters, 0% schema coverage, no annotations, no output schema), the description is severely incomplete. It doesn't explain what 'editing' means operationally, how parameters interact, what the tool returns, or error conditions. For a file manipulation tool with many configuration options, this leaves critical gaps for agent understanding.

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

Parameters1/5

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

Schema description coverage is 0% for all 12 parameters, and the description provides no information about any parameters beyond implying that 'instruction' is involved in editing. Parameters like 'apply', 'dry_run', 'model', 'force', and 'extra_args' remain completely unexplained, leaving the agent with no semantic understanding of what these inputs control.

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

Purpose3/5

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

The description states the tool 'Edit a file with an instruction' which provides a basic verb+resource combination, but it's vague about what 'edit' entails and doesn't distinguish from siblings like cursor_agent_analyze_files or cursor_agent_raw. The additional note about being a 'Prompt-based wrapper' adds some context but doesn't fully clarify the specific editing mechanism.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description mentions 'no CLI subcommand required' which hints at convenience over raw execution, but doesn't specify scenarios where this wrapper is preferable to sibling tools like cursor_agent_run or cursor_agent_raw for file editing tasks.

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/sailay1996/cursor-agent-mcp'

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