cursor 0.2.20: the MCP server the caller's tools go to Cursor under is "tools", not "magpie"

What goes to Cursor named magpie in four places: the dynamic tool catalog
in the system prompt ('The MCP namespace "magpie" has the tools below' and
each <call> entry's "namespace":"magpie"), every CallDynamicTool call in
the history (args.namespace), each McpToolDefinition's provider_identifier
(field 4), and the server answered for mcp_state_exec_args (name and
identifier). magpie's LESSONS.md rule: text added to a vendor's prompt
names neither magpie nor the vendor's limits, with the care a header
change gets (5d33f060b / 3c4f8f9ae).

cursor-agent names a user's MCP server by its mcp.json label
(providerIdentifier = serverName) and a call by "<label>-<tool>"; read in
cursor-agent 2026.10.01-e373342. The plugin now does the same with the
generic label "tools" (NS), in all four places. Calls are read back under
NAMESPACES = ["tools", "magpie"]: a "<ns>-<tool>" name without field 5 is
stripped of either prefix, and a native exec's provider/server is accepted
as either, so a native session begun on 0.2.19 still has its calls served.
The non-native history is rebuilt from the caller's messages each request,
so it carries the new name at once.

Siblings in other packages that still name magpie upstream, filed, not
changed here: commandcode User-Agent and x-project-slug (#352), kimi-work
User-Agent (#353), qoder business.name (#354), autoclaw device_id (#355),
kimi-desktop's instructions tag (#356), opendesign's host fallback (#357),
layerfs tool descriptions (#358). Left alone as not upstream: X-Magpie-*
response headers, the x-magpie-cursor-session hook header (never sent to
Cursor), magpie_native/magpie_deferred usage fields, sign-in messages.

Test: upstream-words.test.mjs builds a Run (buildRun) from a conversation
with tools and a tool call, and checks that the catalog, every transcript
blob, the request bytes and the mcp_state answer contain no /magpie/i, and
that a call is read back as both "tools-read" and "magpie-read". Red on
the old index.mjs (2 of 3 fail: catalog, mcp_state); green now.
conversation, reasoning and native-test-wire expectations moved to
"tools"; native-e2e still sends provider "magpie", so the old name is
covered on the native path.

Run at this tree:
- bun test in packages/cursor: 279 pass, 0 fail (17 files).
- bun scripts/check.mjs: every package ok.
- Live, owner's Cursor account, sandbox HOME (scratchpad), the plugin's
  loader.fetch with one read_file tool, http2 writes scanned for "magpie":
  auto: turn 1 called read_file {"path":"notes.txt"}, turn 2 with the
  result answered "Pelican"; 0 chunks named magpie (the old index.mjs
  under the same scan: 2). grok-4.7-fast: the same two turns, 0 chunks.
  claude-4.6-sonnet: 429, not in this plan's weekly usage.
Not tried: a native session resumed across the upgrade against real Cursor
(covered by native-e2e's "magpie" provider against the fake server only).
This commit is contained in:
yetone
2026-10-24 16:54:42 +08:00
parent 71021b8f72
commit a41a8d3a57
6 changed files with 98 additions and 14 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ test("the tool catalog writes each tool as its CallDynamicTool call", () => {
const s = _internal.catalog(tools)
expect(s).not.toContain("<tool name=")
for (const t of tools) {
expect(s).toContain(`<call>CallDynamicTool({"namespace":"magpie","toolName":"${t.name}","arguments":{...}})\n${t.description}\narguments schema: ${t.schemaText}\n</call>`)
expect(s).toContain(`<call>CallDynamicTool({"namespace":"tools","toolName":"${t.name}","arguments":{...}})\n${t.description}\narguments schema: ${t.schemaText}\n</call>`)
}
expect(_internal.catalog([])).toBe("")
})
+22 -9
View File
@@ -1179,6 +1179,19 @@ function toolsOf(chat) {
})
}
// NS is the MCP server the caller's tools are served as, the way Cursor's
// own client names a user's server by its mcp.json label (providerIdentifier,
// with "<label>-<tool>" as a call's name). It goes to Cursor in the prompt,
// each call and each tool definition, so it names nothing of the plugin or
// the app it runs in. Calls are read back under NAMESPACES: before 0.2.20
// the server was named "magpie", and a session begun then can still call it.
const NS = "tools"
const NAMESPACES = [NS, "magpie"]
const bareName = (s) => {
for (const ns of NAMESPACES) if (s.startsWith(ns + "-")) return s.slice(ns.length + 1)
return s
}
// catalog lists the caller's tools for the model. It sees MCP tools only
// through Cursor's GetDynamicTools and CallDynamicTool, and Cursor names
// them in a prompt of its own, which this conversation goes without:
@@ -1188,8 +1201,8 @@ function toolsOf(chat) {
// those calls went nowhere (#11).
function catalog(tools) {
if (!tools.length) return ""
let s = `\n\n<dynamic_tool_catalog>\nThe MCP namespace "magpie" has the tools below. They are reached only through \`${CALL}\`, never as tools of their own. Each entry is the exact call to make; its arguments must match the schema given. The schemas are complete, so there is no need to call \`GetDynamicTools\` first.\n`
for (const t of tools) s += `<call>${CALL}({"namespace":"magpie","toolName":"${t.name}","arguments":{...}})\n${t.description}\narguments schema: ${t.schemaText}\n</call>\n`
let s = `\n\n<dynamic_tool_catalog>\nThe MCP namespace "${NS}" has the tools below. They are reached only through \`${CALL}\`, never as tools of their own. Each entry is the exact call to make; its arguments must match the schema given. The schemas are complete, so there is no need to call \`GetDynamicTools\` first.\n`
for (const t of tools) s += `<call>${CALL}({"namespace":"${NS}","toolName":"${t.name}","arguments":{...}})\n${t.description}\narguments schema: ${t.schemaText}\n</call>\n`
return s + "</dynamic_tool_catalog>"
}
@@ -1263,7 +1276,7 @@ function conversation(chat, tools) {
if (c?.type && c.type !== "function") continue
const args = parseArgs(c.function?.arguments)
size += (c.function?.arguments ?? "").length + (c.function?.name ?? "").length
content.push({ type: "tool-call", toolCallId: callID(c.id), toolName: CALL, args: { namespace: "magpie", toolName: c.function?.name, arguments: args } })
content.push({ type: "tool-call", toolCallId: callID(c.id), toolName: CALL, args: { namespace: NS, toolName: c.function?.name, arguments: args } })
pending.push(c.id)
}
if (content.length) add({ role: "assistant", content })
@@ -1303,7 +1316,7 @@ function toolDef(t) {
const d = pb().str(1, t.name)
if (t.description) d.str(2, t.description)
d.bytes(3, pbValue(t.schema))
return d.str(4, "magpie").str(5, t.name).str(6, t.schemaText).done()
return d.str(4, NS).str(5, t.name).str(6, t.schemaText).done()
}
const env = () => pb().str(1, GOOS).str(2, tmpdir()).str(10, "UTC")
@@ -2527,13 +2540,13 @@ function exec(msg, tools, send, closeExec, refused, native = false) {
if (native) for (const e of es) if (e.num === 11) {
if (e.wire !== 2) throw new NativeSessionError(502, "invalid native MCP argument envelope")
const { fields: a, args } = nativeMcpArgs(e.data)
const name = pbStr(a, 5) || pbStr(a, 1).replace(/^magpie-/, "")
const name = pbStr(a, 5) || bareName(pbStr(a, 1))
const provider = pbStr(a, 4)
const server = pbStr(a, 9)
if (provider && provider !== "magpie" || server && server !== "magpie") nativeUnavailable = true
if (provider && !NAMESPACES.includes(provider) || server && !NAMESPACES.includes(server)) nativeUnavailable = true
if (pbNum(a, 7) || field(a, 6)) nativeUnavailable = true
if (!tools.some((t) => t.name === name)) nativeUnavailable = true
if (!pbStr(a, 5) && pbStr(a, 1) !== "magpie-" + name) nativeUnavailable = true
if (!pbStr(a, 5) && !NAMESPACES.some((ns) => pbStr(a, 1) === ns + "-" + name)) nativeUnavailable = true
const call = { requestID: id, execID, nativeID: pbStr(a, 3), name, args }
if (nativeCall && !isDeepStrictEqual(nativeCall, call)) throw new NativeSessionError(502, "ambiguous repeated native MCP argument envelopes")
nativeCall ??= call
@@ -2565,7 +2578,7 @@ function exec(msg, tools, send, closeExec, refused, native = false) {
const v = field(ef, 2)
args[pbStr(ef, 1)] = v ? pbAny(v.data) : null
}
const name = pbStr(a, 5) || pbStr(a, 1).replace(/^magpie-/, "")
const name = pbStr(a, 5) || bareName(pbStr(a, 1))
// an OpenAI model's id is its call's and its item's, a line apart,
// which no caller would take as an id: the line goes as __
const cid = pbStr(a, 3).replaceAll("\n", "__") || "call_" + randomBytes(12).toString("hex")
@@ -2573,7 +2586,7 @@ function exec(msg, tools, send, closeExec, refused, native = false) {
}
case 36: {
// mcp_state_exec_args: the tools there are
const srv = pb().str(1, "magpie").str(2, "magpie").str(7, "connected")
const srv = pb().str(1, NS).str(2, NS).str(7, "connected")
for (const t of tools) srv.bytes(5, toolDef(t))
answer(36, pb().bytes(1, pb().bytes(1, srv)))
return null
+2 -2
View File
@@ -62,9 +62,9 @@ export function envelope(body, flags = 0) {
}
export const update = (n, body) => envelope(bin(1, bin(n, body)))
export const end = () => envelope(Buffer.from("{}"), 2)
export function tool(id, rawID, value = "seed", { name = "audit_echo", provider = "magpie", server = "magpie", approval = false, omitID = false, argumentValue, omitArguments = false } = {}) {
export function tool(id, rawID, value = "seed", { name = "audit_echo", provider = "tools", server = "tools", approval = false, omitID = false, argumentValue, omitArguments = false } = {}) {
const args = omitArguments ? Buffer.alloc(0) : bin(2, message(text(1, "value"), bin(2, argumentValue ?? text(3, value))))
const a = message(text(1, "magpie-" + name), args, text(3, rawID), text(4, provider), text(5, name), text(9, server), ...(approval ? [uint(7, 1)] : []))
const a = message(text(1, "tools-" + name), args, text(3, rawID), text(4, provider), text(5, name), text(9, server), ...(approval ? [uint(7, 1)] : []))
return envelope(bin(2, message(...(omitID ? [] : [uint(1, id)]), text(15, "exec-" + id), bin(11, a))))
}
export const setBlob = (request, id, data) => envelope(bin(4, message(uint(1, request), bin(3, message(bin(1, id), bin(2, data))))))
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cursor-auth",
"version": "0.2.19",
"version": "0.2.20",
"description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to",
"type": "module",
"main": "./index.mjs",
+1 -1
View File
@@ -19,7 +19,7 @@ test("reasoning_content survives a tool continuation and the Run's transcript bl
expect(parts(conv)[0].content).toEqual([
{ type: "reasoning", text: "The branch needs a null check." },
{ type: "text", text: "Reading the source." },
{ type: "tool-call", toolCallId: "toolu_a", toolName: "CallDynamicTool", args: { namespace: "magpie", toolName: "read", arguments: { path: "a" } } },
{ type: "tool-call", toolCallId: "toolu_a", toolName: "CallDynamicTool", args: { namespace: "tools", toolName: "read", arguments: { path: "a" } } },
])
const run = _internal.buildRun(conv.msgs, conv.last, [], "grok-4.7-fast")
const transcript = [...run.blobs.values()].map((b) => b.toString())
+71
View File
@@ -0,0 +1,71 @@
// Nothing this plugin writes into what goes to Cursor names magpie: the
// prompt, the dynamic tool catalog in it, the calls in the history, the
// tool definitions and the MCP server it answers Cursor's mcp_state with.
// Text added to a vendor's prompt is a ban risk, as a header is (magpie's
// LESSONS.md, 5d33f060b / 3c4f8f9ae). A session begun before 0.2.20, when
// the server was named "magpie", still has its calls read back.
import "./nonet.mjs" // first: no request leaves this machine
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { conversation, toolsOf, buildRun, catalog, exec, pb } = _internal
const chat = {
model: "claude-4.6-sonnet",
messages: [
{ role: "system", content: "You are a coding agent." },
{ role: "user", content: "read a" },
{ role: "assistant", content: "Reading.", tool_calls: [{ id: "call_1", type: "function", function: { name: "read", arguments: '{"path":"a"}' } }] },
{ role: "tool", tool_call_id: "call_1", content: "A" },
{ role: "user", content: "and b" },
],
tools: [
{ type: "function", function: { name: "read", description: "Read a file", parameters: { type: "object", properties: { path: { type: "string" } } } } },
{ type: "function", function: { name: "bash", description: "Run a command", parameters: { type: "object", properties: { cmd: { type: "string" } } } } },
],
}
const named = (bytes) => /magpie/i.test(Buffer.from(bytes).toString("latin1"))
test("the prompt, the tool catalog, the calls and the tool definitions sent to Cursor never name magpie", () => {
const tools = toolsOf(chat)
expect(catalog(tools)).toContain("CallDynamicTool")
expect(catalog(tools)).not.toMatch(/magpie/i)
const conv = conversation(chat, tools)
for (const m of conv.msgs) expect(m.toString()).not.toMatch(/magpie/i)
const run = buildRun(conv.msgs, conv.last, tools, chat.model, "conv-1")
expect(named(run.first)).toBe(false)
for (const b of run.blobs.values()) expect(named(b)).toBe(false)
// what the catalog promises is what the definitions and calls say
const sys = JSON.parse(conv.msgs[0].toString()).content
const ns = /The MCP namespace "([^"]+)"/.exec(sys)[1]
expect(sys).toContain(`{"namespace":"${ns}","toolName":"read"`)
const call = conv.msgs.map((b) => JSON.parse(b.toString())).find((m) => m.role === "assistant").content.find((p) => p.type === "tool-call")
expect(call.args.namespace).toBe(ns)
expect(Buffer.from(run.first).toString("latin1")).toContain(ns)
})
test("the MCP server Cursor is told of never names magpie", () => {
const tools = toolsOf(chat)
const sent = []
const msg = pb().varint(1, 3).str(15, "x3").bytes(36, pb().done()).done()
expect(exec(msg, tools, (b) => sent.push(b), () => {})).toBe(null)
expect(sent.length).toBe(1)
expect(named(sent[0])).toBe(false)
})
// a call Cursor returns, by the server name now and by the old one
const callOf = (full, bare) => {
const a = pb().str(1, full).str(3, "call_9")
if (bare) a.str(5, bare)
return pb().varint(1, 7).str(15, "x1").bytes(11, a.done()).done()
}
test("a call is read back under the new server name and under magpie, from a session begun before", () => {
const tools = toolsOf(chat)
const ns = JSON.parse(conversation(chat, tools).msgs[0].toString()).content.match(/The MCP namespace "([^"]+)"/)[1]
for (const full of [ns + "-read", "magpie-read"]) {
expect(exec(callOf(full, "read"), tools, () => {}, () => {}).name).toBe("read")
expect(exec(callOf(full), tools, () => {}, () => {}).name).toBe("read")
}
})