Skip to main content
Glama

cursor_agent_raw

Process raw command-line arguments for cursor-agent CLI, enabling efficient repository analysis, code search, file editing, and task planning with configurable output formats to optimize token usage.

Instructions

Advanced: provide raw argv array to pass after common flags (e.g., ["search","--query","foo"]).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argvYes
cwdNo
echo_promptNo
executableNo
extra_argsNo
forceNo
modelNo
output_formatNotext
printNo

Implementation Reference

  • server.js:382-395 (registration)
    Registration of the 'cursor_agent_raw' MCP tool using server.tool(), including the name, description, input schema (RAW_SCHEMA.shape), and inline async handler function.
    server.tool( 'cursor_agent_raw', 'Advanced: provide raw argv array to pass after common flags (e.g., ["search","--query","foo"]).', RAW_SCHEMA.shape, async (args) => { try { const { argv, output_format, cwd, executable, model, force } = args; // For raw calls we disable implicit --print to allow commands like "--help" return await invokeCursorAgent({ argv, output_format, cwd, executable, model, force, print: false }); } catch (e) { return { content: [{ type: 'text', text: `Invalid params: ${e?.message || e}` }], isError: true }; } }, );
  • Inline handler function for cursor_agent_raw: extracts parameters from args, invokes the core invokeCursorAgent helper with print disabled for raw access, and handles errors by returning an error message.
    async (args) => { try { const { argv, output_format, cwd, executable, model, force } = args; // For raw calls we disable implicit --print to allow commands like "--help" return await invokeCursorAgent({ argv, output_format, cwd, executable, model, force, print: false }); } catch (e) { return { content: [{ type: 'text', text: `Invalid params: ${e?.message || e}` }], isError: true }; } },
  • Zod input schema (RAW_SCHEMA) for the cursor_agent_raw tool, defining required 'argv' array and optional 'print' flag, extending shared COMMON fields.
    const RAW_SCHEMA = z.object({ // raw argv to pass after common flags; e.g., ["--help"] or ["subcmd","--flag"] argv: z.array(z.string()).min(1, 'argv must contain at least one element'), print: z.boolean().optional(), ...COMMON, });
  • Core helper function invokeCursorAgent that spawns the cursor-agent CLI process with constructed argv, handles model/force flags, timeouts, idle kill, stdout/stderr capture, and returns MCP-formatted content or error.
    async function invokeCursorAgent({ argv, output_format = 'text', cwd, executable, model, force, print = true }) { const cmd = resolveExecutable(executable); // Compute model/force from args/env const userArgs = [...(argv ?? [])]; const hasModelFlag = userArgs.some((a) => a === '-m' || a === '--model' || /^(?:-m=|--model=)/.test(String(a))); const envModel = process.env.CURSOR_AGENT_MODEL && process.env.CURSOR_AGENT_MODEL.trim(); const effectiveModel = model?.trim?.() || envModel; const hasForceFlag = userArgs.some((a) => a === '-f' || a === '--force'); const envForce = (() => { const v = (process.env.CURSOR_AGENT_FORCE || '').toLowerCase(); return v === '1' || v === 'true' || v === 'yes' || v === 'on'; })(); const effectiveForce = typeof force === 'boolean' ? force : envForce; const finalArgv = [ ...(print ? ['--print', '--output-format', output_format] : []), ...userArgs, ...(hasForceFlag || !effectiveForce ? [] : ['-f']), ...(hasModelFlag || !effectiveModel ? [] : ['-m', effectiveModel]), ]; return new Promise((resolve) => { let settled = false; let out = ''; let err = ''; let idleTimer = null; let killedByIdle = false; const cleanup = () => { if (mainTimer) clearTimeout(mainTimer); if (idleTimer) clearTimeout(idleTimer); }; if (process.env.DEBUG_CURSOR_MCP === '1') { try { console.error('[cursor-mcp] spawn:', cmd, ...finalArgv); } catch {} } const child = spawn(cmd, finalArgv, { shell: false, // safer across platforms; rely on PATH/PATHEXT cwd: cwd || process.cwd(), env: process.env, }); try { child.stdin?.end(); } catch {} const idleMs = Number.parseInt(process.env.CURSOR_AGENT_IDLE_EXIT_MS || '0', 10); const scheduleIdleKill = () => { if (!Number.isFinite(idleMs) || idleMs <= 0) return; if (idleTimer) clearTimeout(idleTimer); idleTimer = setTimeout(() => { killedByIdle = true; try { child.kill('SIGKILL'); } catch {} }, idleMs); }; child.stdout.on('data', (d) => { out += d.toString(); scheduleIdleKill(); }); child.stderr.on('data', (d) => { err += d.toString(); }); child.on('error', (e) => { if (settled) return; settled = true; cleanup(); if (process.env.DEBUG_CURSOR_MCP === '1') { try { console.error('[cursor-mcp] error:', e); } catch {} } const msg = `Failed to start "${cmd}": ${e?.message || e}\n` + `Args: ${JSON.stringify(finalArgv)}\n` + (process.env.CURSOR_AGENT_PATH ? `CURSOR_AGENT_PATH=${process.env.CURSOR_AGENT_PATH}\n` : ''); resolve({ content: [{ type: 'text', text: msg }], isError: true }); }); const defaultTimeout = 30000; const timeoutMs = Number.parseInt(process.env.CURSOR_AGENT_TIMEOUT_MS || String(defaultTimeout), 10); const mainTimer = setTimeout(() => { try { child.kill('SIGKILL'); } catch {} if (settled) return; settled = true; cleanup(); resolve({ content: [{ type: 'text', text: `cursor-agent timed out after ${Number.isFinite(timeoutMs) ? timeoutMs : defaultTimeout}ms` }], isError: true, }); }, Number.isFinite(timeoutMs) ? timeoutMs : defaultTimeout); child.on('close', (code) => { if (settled) return; settled = true; cleanup(); if (process.env.DEBUG_CURSOR_MCP === '1') { try { console.error('[cursor-mcp] exit:', code, 'stdout bytes=', out.length, 'stderr bytes=', err.length); } catch {} } if (code === 0 || (killedByIdle && out)) { resolve({ content: [{ type: 'text', text: out || '(no output)' }] }); } else { resolve({ content: [{ type: 'text', text: `cursor-agent exited with code ${code}\n${err || out || '(no output)'}` }], isError: true, }); } }); }); }
  • Shared COMMON schema fields extended by RAW_SCHEMA and other tool schemas, defining optional output_format, cwd, executable, model, force, and echo_prompt.
    const COMMON = { output_format: z.enum(['text', 'json', 'markdown']).default('text'), extra_args: z.array(z.string()).optional(), cwd: z.string().optional(), executable: z.string().optional(), model: z.string().optional(), force: z.boolean().optional(), // When true, the server will prepend the effective prompt to the tool output (useful for Claude debugging) echo_prompt: z.boolean().optional(), };

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

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