@cursor/sdk local runtime: Claude-format hook output ignored, send({ mcpServers }) drops file-based MCP servers, MCP logins are per folder

Where does the bug appear (feature/product)?

Cursor SDK

Describe the Bug

Three places where the local runtime of @cursor/sdk (1.0.31 through 1.0.36, same code) differs from the docs and the CLI. Each comes down to a small change in the bundle, and we patch all three in-process with a preload that rewrites the SDK as it loads. Sites below are from 1.0.36 dist/cjs/867.js (689.js in 1.0.35). Two related SDK gaps already have staff-confirmed threads, and I’ve added the same kind of detail there: max mode in topic 172554 and sessionStart additional_context in topic 168441.

1. Claude Code-format hook output is ignored, so a Claude PreToolUse deny doesn’t block.
The SDK runs the hooks in ~/.claude/settings.json, but ignores their nested hookSpecificOutput (permissionDecision, permissionDecisionReason, additionalContext). The third-party hooks docs list nested hookSpecificOutput as supported, and the CLI honours it (Cursor-agent: imported Claude Code plugin hooks get a Cursor-shaped payload, so PreToolUse gates fail open).

  • Site: the hook executor is built without the flag its output parser checks (e?.enableClaudeNestedHookSpecificOutputCompatibility??!1):
    new wE(r,i,a,(t.createTerminalExecutor??kC)(),t.promptHookClient,void 0,void 0,{commandHookPayloadTransport:…})
  • Workaround: add enableClaudeNestedHookSpecificOutputCompatibility:!0 to that options object. With it, the same hook blocks the command.

2. send({ mcpServers }) also turns off the plugin, project and user MCP servers.
The docs say send-level mcpServers “Fully replaces creation-time servers for that run”, with local precedence “Send > create > plugins > project > user”. In practice a run started with send-level servers gets only those: everything from ~/.cursor/mcp.json, .cursor/mcp.json and plugins disappears for that run. The same servers passed to Agent.create() keep the file-based ones.

3. MCP OAuth logins are per folder, and can’t be done inside a run.
The docs say an OAuth MCP server works in local runs “if you’ve already signed in to that server from the Cursor app”. In practice the SDK reads tokens from ~/.cursor/projects/<folder>/mcp-auth.json, the file agent mcp login writes for that folder. A login made in the Cursor app isn’t seen (as confirmed in topic 159797), and a CLI login covers one folder, so every worktree or new folder needs its own (we have 48 of these files). The file is read once per process, so a new login needs a restart. Inside a run, the agent’s mcp_auth gets “MCP authentication is not supported in local SDK runs”, and the server stays hidden.

  • Site: four new Mm((0,n.join)(l,"mcp-auth.json")) calls, each given the per-folder directory.
  • Workaround: point those four at one shared file (an env var in our preload) and link the CLI’s per-folder file to it, so one login covers every folder.

Steps to Reproduce

  1. Hooks: in a scratch HOME, add a ~/.claude/settings.json PreToolUse hook with matcher Bash whose command prints {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"blocked by test hook"}}. Create a local agent with local: { cwd, settingSources: ["user"], sandboxOptions: { enabled: false } } and ask it to run echo hi > marker.txt. The hook runs, and marker.txt is still created. With the flag above turned on, the agent gets “Rejected: blocked by test hook” and no file is written.
  2. MCP: with a server in ~/.cursor/mcp.json and settingSources: ["user"], call agent.send(prompt, { mcpServers: { other: … } }) and ask the agent to list its MCP servers: only other is there. Without send-level mcpServers, both are.
  3. MCP OAuth: run agent mcp login <server> in folder A, then start local agents in folder A and in folder B: the server is ready only in A.

Expected Behavior

  1. Claude-format hook output is honoured in SDK runs, as the docs and the CLI do.
  2. Send-level mcpServers replace only the creation-time inline servers; plugin, project and user servers stay, as documented.
  3. One login works for every folder (a user-level token store, or the app’s), and the docs describe what the local SDK actually reads.

Operating System

Linux

Version Information

@cursor/sdk 1.0.36 (Node 24), also checked in 1.0.31 and 1.0.35 (in T3 Code nightlies 0.0.46-nightly.20261004.2648 and 0.0.46-nightly.20261006.2735). Cursor CLI 2026.10.01-e373342.

For AI issues: which model did you use?

composer-2.5 for the hook repro; the issues don’t depend on the model.

For AI issues: add Request ID with privacy disabled

Privacy mode was on for these (and the problems are client-side): hook repro on stock 1.0.36 a8e8c07d-1045-491d-9e32-a8df92bb8fbd (command ran), with the flag on f5561fc7-0721-4455-8a93-a064bd9101ed (blocked).

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey, thanks for the detailed report, and for pointing at the exact spots in the bundle with a repro for each item. I checked all three against the current SDK and the CLI, and the behavior matches what you described. I’ve passed this to the team. Summary and what works in the meantime:

  1. Claude-format hooks. The SDK doesn’t honor nested hookSpecificOutput the way the CLI does, so a PreToolUse deny doesn’t block. Note that exiting with code 2 won’t help here either: for imported Claude hooks the SDK treats a non-zero exit as a failed hook and continues, since those hooks aren’t fail-closed. What does work is emitting the flat Cursor fields next to hookSpecificOutput in the same JSON, e.g. "permission": "deny", "user_message": "blocked by test hook"; the SDK reads the flat shape without the flag, and Claude Code ignores the extra fields.

  2. send({ mcpServers }). The send-level map currently replaces all file-based and plugin servers for that run, not just the creation-time inline ones. Workaround: pass your servers into Agent.create() instead; file-based servers stay in place.

  3. MCP logins. The local SDK reads the per-folder token file written by agent mcp login, not the desktop app login, so right now each folder needs its own login. This came up in thread 159797 as well, and I’ve noted the docs wording about reusing the app’s saved login; that needs fixing too.

For points 1 and 3 it would be easier to track them in their own threads so nothing gets mixed together. If you’re up for it, open a separate topic for each, or let me know and I can help.

I can’t give a timeline yet, but I’ll post here when there’s an update. If a workaround doesn’t hold on your side, say so and we’ll take a look.

Hey, there’s an update on the first two points: both are fixed in @cursor/sdk 1.0.40, which is now the current version on npm and PyPI.

  1. Claude-format hooks: the local runtime now respects nested hookSpecificOutput. A PreToolUse hook with permissionDecision: "deny" blocks the tool call the same way it does in the CLI, and the denial reason is passed through too.
  2. send({ mcpServers }): servers from send replace only the inline servers for that run. User, project, and plugin MCP servers selected through settingSources still stay in place.

After updating, you can remove those two parts of the preload, and the flat permission / user_message fields next to hookSpecificOutput are no longer needed.

Point 3, MCP logins for each folder, has not changed in 1.0.40. For now, you still need to log in with agent mcp login separately in each folder.

If anything in the first two points still doesn’t behave as expected after updating, let me know.

Checked both on stock 1.0.40 with our preload off and a clean HOME, and both work now.

A Claude-format PreToolUse hook that returns only the nested hookSpecificOutput with permissionDecision: "deny" blocked the shell call. The model got “Rejected: blocked by test hook” and the file wasn’t created (6601ea52-86e2-4619-8f47-6c6865a7ab93).

With one server in the project’s .cursor/mcp.json and another passed through send({ mcpServers }), both servers’ tools were available and both got called in the same run (02d24112-d7dc-49f3-832a-26fd3c02900e).

Thanks! We’ll drop those two parts of the preload once T3 Code bundles 1.0.40.