Skip to main content
Glama

cursor_agent_search_repo

Search repository code using include/exclude patterns with customizable output formats (text, JSON, markdown). Streamlines prompt-based repository analysis and reduces token usage for efficient code exploration.

Instructions

Search repository code with include/exclude patterns. Prompt-based wrapper.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNo
echo_promptNo
excludeNo
executableNo
extra_argsNo
forceNo
includeNo
modelNo
output_formatNotext
queryYes

Implementation Reference

  • server.js:339-359 (registration)
    Registration of the 'cursor_agent_search_repo' tool, including the handler function and schema reference.
    server.tool( 'cursor_agent_search_repo', 'Search repository code with include/exclude patterns. Prompt-based wrapper.', SEARCH_REPO_SCHEMA.shape, async (args) => { try { const { query, include, exclude, output_format, cwd, executable, model, force, extra_args } = args; const inc = include == null ? [] : (Array.isArray(include) ? include : [include]); const exc = exclude == null ? [] : (Array.isArray(exclude) ? exclude : [exclude]); const composedPrompt = `Search the repository for occurrences relevant to:\n` + `- Query: ${String(query)}\n` + (inc.length ? `- Include globs:\n${inc.map((p)=>` - ${String(p)}`).join('\n')}\n` : '') + (exc.length ? `- Exclude globs:\n${exc.map((p)=>` - ${String(p)}`).join('\n')}\n` : '') + `Return concise findings with file paths and line references.`; 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 schema defining input parameters for the search tool: query (required), include/exclude globs (optional), plus shared COMMON fields.
    const SEARCH_REPO_SCHEMA = z.object({ query: z.string().min(1, 'query is required'), include: z.union([z.string(), z.array(z.string())]).optional(), exclude: z.union([z.string(), z.array(z.string())]).optional(), ...COMMON, });
  • The handler function that destructures args, builds a composed prompt for repo search with query/include/exclude, and delegates to runCursorAgent helper.
    async (args) => { try { const { query, include, exclude, output_format, cwd, executable, model, force, extra_args } = args; const inc = include == null ? [] : (Array.isArray(include) ? include : [include]); const exc = exclude == null ? [] : (Array.isArray(exclude) ? exclude : [exclude]); const composedPrompt = `Search the repository for occurrences relevant to:\n` + `- Query: ${String(query)}\n` + (inc.length ? `- Include globs:\n${inc.map((p)=>` - ${String(p)}`).join('\n')}\n` : '') + (exc.length ? `- Exclude globs:\n${exc.map((p)=>` - ${String(p)}`).join('\n')}\n` : '') + `Return concise findings with file paths and line references.`; 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: normalizes input, prepares argv with prompt as positional arg, invokes CLI via invokeCursorAgent, handles echo.
    // 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; }

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