Files
plugins/packages/cursor/native-test-wire.mjs
T
yetone a41a8d3a57 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).
2026-10-24 16:54:42 +08:00

91 lines
3.6 KiB
JavaScript

// Synthetic wire fixtures, independent of the implementation's PB/fields codec.
// Field numbers follow agent.v1: no installed CLI or remote endpoint is needed.
export const vi = (value) => {
let v = BigInt(value)
const b = []
do {
const n = Number(v & 127n)
v >>= 7n
b.push(v ? n | 128 : n)
} while (v)
return Buffer.from(b)
}
export const uint = (field, value) => Buffer.concat([vi(field * 8), vi(value)])
export const bin = (field, value) => {
const b = Buffer.from(value)
return Buffer.concat([vi(field * 8 + 2), vi(b.length), b])
}
export const text = (field, value) => bin(field, Buffer.from(value))
export const message = (...parts) => Buffer.concat(parts)
export function readWire(input) {
const buffer = Buffer.from(input)
let at = 0
const varint = () => {
let result = 0n
let shift = 0n
while (at < buffer.length) {
const b = buffer[at++]
result |= BigInt(b & 127) << shift
if (!(b & 128)) return Number(result)
shift += 7n
}
throw new Error("fixture truncated varint")
}
const out = []
while (at < buffer.length) {
const tag = varint()
const no = tag >> 3
const kind = tag & 7
if (kind === 0) out.push({ no, value: varint() })
else if (kind === 2) {
const n = varint()
if (at + n > buffer.length) throw new Error("fixture truncated bytes")
out.push({ no, data: buffer.subarray(at, at + n) })
at += n
} else throw new Error("fixture unsupported wire")
}
return out
}
export const item = (b, n) => readWire(b).find((f) => f.no === n)
export const nest = (b, n) => {
const f = item(b, n)
if (!f?.data) throw new Error("fixture missing message " + n)
return f.data
}
export const string = (b, n) => item(b, n)?.data?.toString() ?? ""
export const number = (b, n) => item(b, n)?.value ?? 0
export function envelope(body, flags = 0) {
const h = Buffer.alloc(5)
h[0] = flags
h.writeUInt32BE(body.length, 1)
return Buffer.concat([h, body])
}
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 = "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, "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))))))
export const getBlob = (request, id) => envelope(bin(4, message(uint(1, request), bin(2, bin(1, id)))))
export const checkpoint = (state) => envelope(bin(3, state))
export const abortExec = (id) => envelope(bin(5, bin(1, uint(1, id))))
export function readResult(b) {
const exec = nest(b, 2)
const result = nest(exec, 11)
const success = nest(result, 1)
if (readWire(result).some((f) => f.no !== 1)) throw new Error("fixture expected McpResult.success")
return {
id: number(exec, 1),
execID: string(exec, 15),
content: readWire(success).filter((f) => f.no === 1).map((f) => {
const txt = item(f.data, 1)
if (txt) return { type: "text", text: string(txt.data, 1) }
const image = nest(f.data, 2)
return { type: "image", data: nest(image, 1), mimeType: string(image, 2) }
}),
isError: !!number(success, 2),
}
}