cursor-relay-mcp
Delegate bounded Cursor Agent tasks from MCP clients with persistent, restart-safe run state and explicit workspace permissions.
Check relay configuration, authentication, and persistence directories without calling Cursor (
doctor).Discover available Cursor models, aliases, and parameters before starting a run (
list_models).Issue a short-lived, one-time read-only workspace authorization when the user explicitly authorizes it in the current conversation (
authorize_workspace).Start a durable Cursor Agent run in an allowed local workspace with explicit model, task scope, permission, timeout, and idempotency key (
start_run).Continue an ended Cursor Agent session with a follow-up run while preserving the same
agentId(reply_run).Read current run status and reconnect to the Cursor SDK run after process restarts (
get_run).Wait up to 30 seconds for progress, then keep polling while
terminal=false(wait_run).Cancel an executing Cursor SDK run, with stable idempotent results (
cancel_run).List persisted Relay runs by creation time (
list_runs).Read persisted Cursor SDK stream events by increasing sequence, with limits and truncation (
read_events).Rely on fail-closed defaults: read-only by default, workspace allowlists, sandbox/permission controls, and dangerous-permission opt-ins.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@cursor-relay-mcp start a run to review the recent code changes and suggest improvements"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
cursor-relay-mcp
A local MCP server built on the official @cursor/sdk. It lets MCP clients delegate a bounded task to an explicitly selected Cursor model while keeping durable, restart-safe run state.
@cursor/sdk is public beta. This package pins exactly 1.0.30 and includes an SDK export contract test. See README.zh-CN.md for the full guide.
For a tested Codex Desktop installation workflow on Windows, including personal marketplace layout, CLI fallback, sandbox compatibility, cache refresh, and a Grok 4.6 smoke test, see CODEX_INSTALL.zh-CN.md.
Updating another computer: Pull, build, reinstall, then verify native tools and a real read/write task in a new Codex task. Preserve active runs and local state. See the upgrade checklist.
Codex built-in MCP contract
The Codex plugin manifest references the packaged MCP declaration with
"mcpServers": "./.mcp.json". The packaged .mcp.json must start
node ./dist/index.js with cwd: ".". Codex resolves that working directory
against the installed plugin version root. Do not hard-code a development checkout
or a versioned Codex cache path, duplicate the same server in user config.toml, or
put CURSOR_API_KEY in the MCP declaration.
After installing or reinstalling the plugin, create a new Codex task. Codex loads
the bundled Skill and starts the built-in MCP automatically. It sends only the
workspace path, targetLocations (files, directories, or line locations), a
bounded task scope, model, permission, and idempotency data. The Cursor Agent
reads the authorized workspace itself. Both read-only and workspace-write
reject source text, code fences, file contents, and diffs in MCP arguments. An
explicit request for Cursor to review a current or named
workspace authorizes in-scope reading, not secrets, unrelated paths, or edits. An
explicit request to modify or fix must map to workspace-write, not be silently
downgraded to analysis. Outside the static allowlist, authorize_workspace
issues a reusable capability bound to the current Codex conversation and exact
workspace; it supports both read-only and workspace-write.
The plugin ships its Codex Skill inside the original package at
skills/delegate-to-cursor-agent/SKILL.md. The manifest declares
"skills": "./skills/", and the npm package includes skills/, so installing
or reinstalling the plugin makes Codex load the Skill automatically in newly
created tasks; no install-time Skill generation is needed.
Related MCP server: Agent Bus MCP
Quick start
Requirements: Git, Node.js >=22.13, and a Cursor account. The recommended
authentication method is the official Cursor.auth.login() stored login.
git clone https://github.com/tonytanglab/cursor-relay-mcp.git
cd cursor-relay-mcp
npm install
# Opens the system default browser and stores an official SDK login for this OS user.
node --input-type=module --eval 'import { Cursor } from "@cursor/sdk"; await Cursor.auth.login({ apiKeyName: "cursor-relay-mcp" })'
npm run build
$env:CURSOR_RELAY_WORKSPACE_ROOTS = "D:\app\git"
node .\dist\index.jsRun the login once on each computer and OS user account that starts the MCP server. The official SDK opens the system default browser, mints a named, expiring and revocable API key, and stores it in its official credential store; the relay never reads or returns the key value. Check the login without exposing credentials:
node --input-type=module --eval 'import { Cursor } from "@cursor/sdk"; console.log((await Cursor.auth.status()).status)'logged-in means the MCP process can use stored login. CURSOR_API_KEY remains
an optional alternative for automation, but do not put it in .mcp.json, shell
history, logs, or the repository. When using stored login, omit
CURSOR_API_KEY entirely instead of setting it to an empty string.
The normal tool flow is doctor → list_models → start_run → repeated wait_run calls until terminal=true. The SDK stored login is independent of the Cursor desktop login; after explicit user confirmation, reauthenticate_cursor can replace a mismatched SDK login without exposing its API key. Runs are idempotent and persisted; the owning executor enforces its total timeout. New runs use workspace-scoped SQLite, while legacy JSONL remains read-only. Reattaching after a restart observes persisted events; it does not restart execution. Stop unconditional polling when needsAttention=true, and do not automatically cancel or resubmit an unknown run.
For start_run and reply_run, task means review/implementation scope and
acceptance requirements, never file contents. Use targetLocations for
workspace-relative files, directories, or line locations. If a reply omits them,
it inherits the parent locations. The Relay builds the Cursor instruction so the
agent reads the authorized workspace directly; authorization does not relax this
contract for either read-only or read/write runs.
doctor reports the effective defaultTimeoutMs and maxTimeoutMs. Ordinary
repository work should normally omit timeoutMs and use the configured default
(24 hours by default and also the hard maximum). Callers may request a shorter
explicit budget when appropriate, but cannot raise a run above 24 hours. A
wait_run timeout is only a polling slice. Retryable SDK reconnects are returned as
connection.state=reconnecting and remain non-terminal.
While status and events show healthy progress, callers should keep waiting within
the run budget instead of cancelling or creating short continuation runs.
If no event is persisted for 10 minutes, wait_run returns needsAttention=true
and mustCallAgain=false; the run remains non-terminal. The response includes
run.activity with the last event time and silence duration. Check the original
run and any external process before taking action. Silence alone does not prove
that the SDK executor stopped, and must not trigger automatic cancellation or
a replacement paid run. The progress page shows the warning while continuing
to refresh snapshots so later activity or a terminal result remains visible.
After start_run or reply_run, call open_run and share its clickable
progressUrl. This read-only loopback page bypasses MCP App sandbox failures.
Links are bound to one run, expire after 24 hours, and stop working when their
MCP process exits; call open_run again with the original run ID, never resubmit
the task to fix a display error. Do not share these capability links externally.
view_run remains an optional embedded panel. Data tools no longer attach a
widget, avoiding redundant sandbox frames. Both viewers use read_run_progress
for persisted snapshots and the latest 200 incremental events; viewing never
attaches to the SDK, settles a timeout, or mutates a run. A persisted running
status is not proof of liveness: callers must still monitor with wait_run.
The panel retries read failures, shows recovery errors, and releases timers
and old events. No network fonts, scripts, or external services are used.
The pinned public Cursor SDK has no operation for injecting a new instruction
into an active local Agent run. The relay therefore reports
doctor.capabilities.activeRunSteering=false and never treats an internal event
append as successful steering. A caller must not cancel merely to redirect: it
should keep observing and use reply_run after terminal state. Cancellation is
reserved for an explicit stop request or a concrete safety boundary.
Security defaults are fail-closed: unattended runs require the static workspace
allowlist. When a user explicitly authorizes Cursor Relay for a workspace in the
current conversation, authorize_workspace can issue a reusable read-only or
workspace-write capability. The token is never persisted and is bound to the
real path, granted permission ceiling, and MCP task/session when available. A
workspace-write capability can also run read-only tasks; a read-only capability
cannot be elevated. It expires when that conversation scope or MCP process ends.
Permissions otherwise default to read-only, the Cursor sandbox is enabled by
default on supported non-Windows hosts, and only project settings are loaded.
Windows defaults the SDK sandbox off because the current local runtime reports
it as unsupported; the read-only tool allowlist remains enforced. Both normal
presets expose Cursor's official webSearch and webFetch tools so Cursor can
decide whether network research is relevant.
danger-full-access still requires the static allowlist plus both
CURSOR_RELAY_ENABLE_DANGER_FULL_ACCESS=true at server startup and
confirmedDangerousPermission=true on the request. Leave the server switch off
for normal use.
CURSOR_RELAY_READ_ONLY_SANDBOX_ENABLED can explicitly disable the sandbox on
supported non-Windows hosts. Windows always clamps this setting off because the
current Cursor SDK local runtime does not support that sandbox path. This switch
applies only to the read-only preset; its public tool allowlist remains
restricted to read, grep, glob, ls, webSearch, and webFetch by
default.
The workspace-write sandbox follows the same platform compatibility rule: it is
enabled by default on supported non-Windows hosts and clamped off on Windows,
while the exact workspace authorization and disallowed-tool list remain enforced.
delete, task, mcp, and generateImage are controlled by the Codex main
process rather than being permanently unavailable. start_run and reply_run
accept codexAllowedTools; omitted reply values inherit the parent policy and
an empty array revokes it. Read-only runs may additionally allow only
generateImage; the other controlled tools require workspace-write. Ordinary,
reversible actions already covered by the user's request need no separate prompt.
Human confirmation is reserved for materially destructive, broad, irreversible,
out-of-scope, externally consequential, or danger-full-access actions.
CURSOR_RELAY_SETTING_SOURCES is an optional comma-separated list restricted
to the public project, team, and mdm setting layers. It defaults to
project; user, plugins, and all are deliberately rejected to avoid
ambient or recursive MCP behavior.
Run summaries omit streamed events and report eventCount; use read_events
for event pages. Event data larger than 8 KiB is replaced with explicit
truncation metadata. Redaction is based on sensitive field names and is not a
general secret scanner, so use a private state directory and avoid secrets in
prompts.
The relay uses only public exports from the pinned SDK: model discovery,
Agent.create/resume/listRuns/getRun, Run.stream/wait/cancel, and
official authentication status. It does not inspect Cursor IDE state or private
endpoints. Restarting the Cursor IDE is not required for local SDK runs.
Verification
npm run format:check
npm run lint
npm run typecheck
npm test
npm run build
npm run test:mcp
npm run check:package
npm run test:sdk-contractThe default tests do not call the real Cursor API or modify a real workspace.
Available Tools
14 toolsauthorize_workspaceA
仅当用户在当前对话明确要求 Cursor Relay 读取或修改该工作区时调用。签发绑定当前 MCP 对话与精确工作区的可复用授权;read-only 与 workspace-write 均只传位置和范围,禁止传源码正文,由 Cursor 自行读取;不授予危险权限,进程结束即失效。
Inputs: workspace (required), permission.
cancel_runCDestructiveIdempotent
取消仍在执行的 Cursor SDK 运行;重复取消具有稳定结果。
Inputs: relayRunId (required).
doctorARead-onlyIdempotent
检查 Cursor Relay 配置、认证与持久目录;不调用 Cursor 模型。
Inputs: no named parameters.
get_runBRead-onlyIdempotent
读取持久运行并重新附加事件观察;本地执行器退出后不会自动重启模型,execution.state=unknown 时需诊断。
Inputs: relayRunId (required).
list_modelsARead-onlyIdempotent
从当前 Cursor 账户发现可用模型、别名与参数;start_run 前应调用。
Inputs: no named parameters.
list_runsBRead-onlyIdempotent
按创建时间倒序列出 Relay 持久运行。
Inputs: limit.
open_runARead-onlyIdempotent
获取现有任务的本机只读进度链接,向用户展示可点击链接;不依赖 Codex MCP 沙箱。start_run/reply_run 成功后调用;沙箱报错时也用它查看原任务,禁止因此重复提交。
Inputs: relayRunId (required).
read_eventsCRead-onlyIdempotent
按递增序号读取已持久化的 Cursor SDK 流事件。事件数量有上限。
Inputs: relayRunId (required), limit, afterSequence.
read_run_progressARead-onlyIdempotent
只读指定任务的持久状态与最近最多 200 条增量事件;不调用 SDK、不重连、不收敛超时。快照不是任务存活证明,实际监控仍用 wait_run。
Inputs: relayRunId (required), afterSequence.
reauthenticate_cursorADestructiveIdempotent
当 Cursor SDK stored login 与用户确认的 Cursor 账户或套餐不一致时,打开系统浏览器重新登录并替换 SDK 本地凭据。不会读取或返回 API key;完成后必须重新调用 list_models 验证权限。
Inputs: confirmed (required).
reply_runBDestructiveIdempotent
在已结束的 Cursor Agent 会话中续接运行并保留 agentId;只传目标位置与任务范围,禁止源码正文,由 Cursor 自行读取。
Inputs: task (required), parentRunId (required), idempotencyKey (required), model, +6 more.
start_runBDestructiveIdempotent
在允许的本地工作区启动持久 Cursor Agent 运行。read-only 与 workspace-write 均只接受工作区、目标位置和任务范围,禁止嵌入源码正文;Cursor 自行读取所需文件。必须显式选择模型和幂等键。
Inputs: task (required), model (required), workspace (required), idempotencyKey (required), +6 more.
view_runARead-onlyIdempotent
打开一个只读实时面板,展示指定 Cursor Relay 运行的状态、事件时间线与最终输出;不启动、续接、取消或修改运行。
Inputs: relayRunId (required).
wait_runARead-onlyIdempotent
最多等待 30 秒。mustCallAgain=true 时继续轮询;needsAttention=true 时停止无条件轮询并诊断,不能把未知执行状态当作失败或完成。
Inputs: relayRunId (required), waitMs.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Several tools target run observation and reading state (open_run, get_run, read_events, read_run_progress, view_run, wait_run), and their boundaries are subtle despite descriptions clarifying snapshot vs. streaming vs. live panel. Core run-control and auth tools are distinct, but the monitoring cluster invites misselection.
Almost all tools use snake_case verb_noun-style names such as list_models, start_run, and wait_run, with only doctor as a noun exception. The convention is predictable and readable.
14 tools is reasonable for auth, model discovery, workspace authorization, run lifecycle, and monitoring. The monitoring surface is somewhat heavy, but each tool maps to a defined operation.
The surface covers configuration/auth, model discovery, run creation, continuation, cancellation, listing, event reading, and progress monitoring. Explicit cleanup/prune/delete for persisted runs is missing, but the core lifecycle is otherwise covered.
Maintenance
Related MCP Connectors
Governed data discovery, exact queries, decisions, simulations, and runtime utilities over MCP.
Reliable async execution for agent tool calls: schema gating, retries, idempotency, audit trail.
Hosted TikTok ads MCP with OAuth, bounded reads, and prepare/confirm writes.
Scoped agent execution. Server-side credentials, policy, budgets and verifiable receipts.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables MCP clients to run declarative agents and DAG workflows as plain tools, with parallel nodes, review loops, and per-run least-privilege sandboxing.5 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables durable, least-privilege handoff of bounded tasks from a local producer to a configured MCP worker, with atomic claim, complete, and fail operations under expiring leases.MIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to access upstream MCP capabilities and OpenAI-compatible model routes through one invariant-preserving, policy-bounded endpoint with deterministic routing, leases, durable Tasks/Runs, and verifiable outcomes.Apache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables AI workers to run local, evidence-driven pull workflows with a shared task/run/event history, lease fencing, bounded permissions, and source-bound machine proof, while callers supply the authorized running worker.MIT