@cursor/july 0.1.25 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/dist/ab.d.ts +6 -0
  2. package/dist/ab.d.ts.map +1 -1
  3. package/dist/ab.js +1 -0
  4. package/dist/artifacts.d.ts +34 -0
  5. package/dist/artifacts.d.ts.map +1 -0
  6. package/dist/artifacts.js +57 -0
  7. package/dist/bin/agent-serve.js +31 -9
  8. package/dist/channels/github/github-channel.d.ts +1 -1
  9. package/dist/channels/github/github-channel.d.ts.map +1 -1
  10. package/dist/channels/github/github-channel.js +14 -1
  11. package/dist/channels/github/types.d.ts +6 -1
  12. package/dist/channels/github/types.d.ts.map +1 -1
  13. package/dist/channels/slack/api.d.ts +2 -1
  14. package/dist/channels/slack/api.d.ts.map +1 -1
  15. package/dist/channels/slack/api.js +1 -0
  16. package/dist/channels/slack/cursor-account.d.ts +2 -1
  17. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  18. package/dist/channels/slack/cursor-account.js +1 -1
  19. package/dist/channels/slack/dispatch.d.ts +4 -1
  20. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  21. package/dist/channels/slack/dispatch.js +3 -3
  22. package/dist/channels/slack/interactive.d.ts +2 -1
  23. package/dist/channels/slack/interactive.d.ts.map +1 -1
  24. package/dist/channels/slack/interactive.js +1 -0
  25. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  26. package/dist/channels/slack/slack-channel.js +4 -3
  27. package/dist/channels/slack/types.d.ts +6 -1
  28. package/dist/channels/slack/types.d.ts.map +1 -1
  29. package/dist/docs/404.html +1 -1
  30. package/dist/docs/ab.html +2 -2
  31. package/dist/docs/assets/{app.DYcC9FY-.js → app.BICLoJYF.js} +1 -1
  32. package/dist/docs/assets/chunks/@localSearchIndexroot.CQJytDwU.js +1 -0
  33. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.wN4Ko9dT.js} +1 -1
  34. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.dnnTE-Co.js} +2 -2
  35. package/dist/docs/building-with-agents.html +2 -2
  36. package/dist/docs/concepts.html +2 -2
  37. package/dist/docs/deployment.html +2 -2
  38. package/dist/docs/evals.html +2 -2
  39. package/dist/docs/example-agents/approval-buddy.html +2 -2
  40. package/dist/docs/example-agents/benny.html +2 -2
  41. package/dist/docs/example-agents/bugbot.html +2 -2
  42. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  43. package/dist/docs/example-agents/codeowners-review.html +2 -2
  44. package/dist/docs/example-agents/concierge.html +2 -2
  45. package/dist/docs/example-agents/fsd.html +2 -2
  46. package/dist/docs/example-agents/index.html +2 -2
  47. package/dist/docs/example-agents/knowledge-base.html +2 -2
  48. package/dist/docs/example-agents/oncall.html +2 -2
  49. package/dist/docs/example-agents/security-reviewer.html +2 -2
  50. package/dist/docs/example-agents/slack-agent.html +2 -2
  51. package/dist/docs/example-agents/weather-agent.html +2 -2
  52. package/dist/docs/guides/agent-to-agent.html +2 -2
  53. package/dist/docs/guides/cloud-runtime.html +2 -2
  54. package/dist/docs/guides/github.html +2 -2
  55. package/dist/docs/guides/human-in-the-loop.html +2 -2
  56. package/dist/docs/guides/mcp-oauth.html +2 -2
  57. package/dist/docs/guides/slack.html +2 -2
  58. package/dist/docs/guides/webhooks.html +2 -2
  59. package/dist/docs/hillclimbing.html +2 -2
  60. package/dist/docs/index.html +2 -2
  61. package/dist/docs/quickstart.html +2 -2
  62. package/dist/docs/reference/agent-config.html +2 -2
  63. package/dist/docs/reference/channels.html +2 -2
  64. package/dist/docs/reference/cli.html +2 -2
  65. package/dist/docs/reference/connections.html +2 -2
  66. package/dist/docs/reference/hooks.html +2 -2
  67. package/dist/docs/reference/http-api.html +2 -2
  68. package/dist/docs/reference/instructions.html +2 -2
  69. package/dist/docs/reference/playground.html +2 -2
  70. package/dist/docs/reference/project-layout.html +2 -2
  71. package/dist/docs/reference/prompt.html +2 -2
  72. package/dist/docs/reference/schedules.html +2 -2
  73. package/dist/docs/reference/sessions.html +2 -2
  74. package/dist/docs/reference/skills.html +2 -2
  75. package/dist/docs/reference/subagents.html +2 -2
  76. package/dist/docs/reference/tools.html +2 -2
  77. package/dist/docs/scaffolding-agents.html +2 -2
  78. package/dist/docs/storage.html +2 -2
  79. package/dist/docs/troubleshooting.html +2 -2
  80. package/dist/evals/assertions.d.ts +10 -1
  81. package/dist/evals/assertions.d.ts.map +1 -1
  82. package/dist/evals/assertions.js +12 -0
  83. package/dist/evals.d.ts +1 -1
  84. package/dist/evals.d.ts.map +1 -1
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +1 -0
  88. package/dist/internal/ab-fold.d.ts.map +1 -1
  89. package/dist/internal/ab-fold.js +4 -0
  90. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  91. package/dist/internal/ab-snapshot.js +1 -0
  92. package/dist/internal/artifacts-store.d.ts +45 -0
  93. package/dist/internal/artifacts-store.d.ts.map +1 -0
  94. package/dist/internal/artifacts-store.js +250 -0
  95. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  96. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  97. package/dist/internal/builtin-tools/artifacts.js +73 -0
  98. package/dist/internal/builtin-tools/index.d.ts +8 -1
  99. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  100. package/dist/internal/builtin-tools/index.js +15 -0
  101. package/dist/internal/cli-ax.d.ts +11 -0
  102. package/dist/internal/cli-ax.d.ts.map +1 -1
  103. package/dist/internal/cli-ax.js +80 -0
  104. package/dist/internal/cli-slack.d.ts.map +1 -1
  105. package/dist/internal/cli-slack.js +14 -6
  106. package/dist/internal/discovery.d.ts.map +1 -1
  107. package/dist/internal/discovery.js +83 -2
  108. package/dist/internal/distribution.d.ts.map +1 -1
  109. package/dist/internal/distribution.js +1 -0
  110. package/dist/internal/model-pricing.d.ts +49 -0
  111. package/dist/internal/model-pricing.d.ts.map +1 -0
  112. package/dist/internal/model-pricing.js +377 -0
  113. package/dist/internal/reminder-runner.d.ts.map +1 -1
  114. package/dist/internal/reminder-runner.js +1 -0
  115. package/dist/internal/schedule-runner.d.ts.map +1 -1
  116. package/dist/internal/schedule-runner.js +1 -0
  117. package/dist/internal/sdk-runner.d.ts.map +1 -1
  118. package/dist/internal/sdk-runner.js +9 -1
  119. package/dist/internal/server.d.ts.map +1 -1
  120. package/dist/internal/server.js +39 -0
  121. package/dist/internal/session-cost.d.ts +49 -0
  122. package/dist/internal/session-cost.d.ts.map +1 -0
  123. package/dist/internal/session-cost.js +175 -0
  124. package/dist/internal/session-engine.d.ts +35 -1
  125. package/dist/internal/session-engine.d.ts.map +1 -1
  126. package/dist/internal/session-engine.js +128 -7
  127. package/dist/internal/storage-coordinator.d.ts +15 -0
  128. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  129. package/dist/internal/storage-coordinator.js +52 -0
  130. package/dist/internal/trajectory.d.ts +9 -1
  131. package/dist/internal/trajectory.d.ts.map +1 -1
  132. package/dist/internal/trajectory.js +32 -5
  133. package/dist/playground/assets/index-BDCeW4uc.js +86 -0
  134. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  135. package/dist/playground/index.html +2 -2
  136. package/dist/storage.d.ts +4 -0
  137. package/dist/storage.d.ts.map +1 -1
  138. package/dist/storage.js +4 -0
  139. package/dist/types.d.ts +164 -1
  140. package/dist/types.d.ts.map +1 -1
  141. package/package.json +26 -26
  142. package/src/ab.ts +7 -0
  143. package/src/bin/agent-serve.ts +30 -2
  144. package/src/channels/github/github-channel.ts +19 -2
  145. package/src/channels/github/types.ts +6 -0
  146. package/src/channels/slack/api.ts +3 -1
  147. package/src/channels/slack/cursor-account.ts +3 -1
  148. package/src/channels/slack/dispatch.ts +12 -1
  149. package/src/channels/slack/interactive.ts +3 -0
  150. package/src/channels/slack/slack-channel.ts +6 -0
  151. package/src/channels/slack/types.ts +6 -0
  152. package/src/internal/ab-fold.ts +4 -0
  153. package/src/internal/ab-snapshot.ts +1 -0
  154. package/src/internal/cli-ax.ts +95 -0
  155. package/src/internal/model-pricing.ts +426 -0
  156. package/src/internal/reminder-runner.ts +1 -0
  157. package/src/internal/schedule-runner.ts +1 -0
  158. package/src/internal/sdk-runner.ts +10 -2
  159. package/src/internal/server.ts +2 -0
  160. package/src/internal/session-cost.ts +231 -0
  161. package/src/internal/session-engine.ts +32 -1
  162. package/src/internal/trajectory.ts +45 -3
  163. package/src/types.ts +42 -2
  164. package/dist/channels/github/instrument.d.ts +0 -20
  165. package/dist/channels/github/instrument.d.ts.map +0 -1
  166. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  167. package/dist/internal/json-dir-store.d.ts +0 -32
  168. package/dist/internal/json-dir-store.d.ts.map +0 -1
  169. package/dist/internal/json-dir-store.js +0 -100
  170. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  171. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  172. package/src/bin/agent-serve.version.test.ts +0 -64
  173. package/src/channels/github/api.test.ts +0 -64
  174. package/src/channels/github/auth.test.ts +0 -105
  175. package/src/channels/github/cursor-account.test.ts +0 -204
  176. package/src/channels/github/forward.test.ts +0 -457
  177. package/src/channels/github/github.test.ts +0 -943
  178. package/src/channels/github/replay.test.ts +0 -179
  179. package/src/channels/slack/api.post-message.test.ts +0 -148
  180. package/src/channels/slack/approvals.test.ts +0 -328
  181. package/src/channels/slack/block-actions.test.ts +0 -452
  182. package/src/channels/slack/bot-mentions.test.ts +0 -267
  183. package/src/channels/slack/channel-watch.test.ts +0 -363
  184. package/src/channels/slack/cursor-account.test.ts +0 -253
  185. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  186. package/src/channels/slack/dispatch.test.ts +0 -795
  187. package/src/channels/slack/eval-directive.test.ts +0 -273
  188. package/src/channels/slack/message-body.test.ts +0 -54
  189. package/src/channels/slack/nudge-store.test.ts +0 -143
  190. package/src/channels/slack/slack.test.ts +0 -391
  191. package/src/channels/slack/stop.test.ts +0 -23
  192. package/src/channels/slack/thread-context.test.ts +0 -202
  193. package/src/evals/assertions.test.ts +0 -617
  194. package/src/evals/expect.test.ts +0 -144
  195. package/src/evals/judge.test.ts +0 -181
  196. package/src/evals/loaders.test.ts +0 -132
  197. package/src/evals/matchers.test.ts +0 -95
  198. package/src/evals/reporters.test.ts +0 -303
  199. package/src/evals/run-facts.test.ts +0 -259
  200. package/src/internal/ab-snapshot.test.ts +0 -325
  201. package/src/internal/approval-gate.test.ts +0 -49
  202. package/src/internal/approvals.integration.test.ts +0 -383
  203. package/src/internal/artifacts-store.test.ts +0 -283
  204. package/src/internal/authored-loaders.test.ts +0 -31
  205. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  206. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  207. package/src/internal/channel-route-schema.test.ts +0 -294
  208. package/src/internal/chat-attach.test.ts +0 -262
  209. package/src/internal/cli-deploy.test.ts +0 -1991
  210. package/src/internal/cli-docs.test.ts +0 -161
  211. package/src/internal/cli-mcp.test.ts +0 -789
  212. package/src/internal/cli-skills.test.ts +0 -133
  213. package/src/internal/cli-slack.test.ts +0 -1654
  214. package/src/internal/cloud-merge.test.ts +0 -74
  215. package/src/internal/cron.test.ts +0 -22
  216. package/src/internal/cursor/account-mcp.test.ts +0 -807
  217. package/src/internal/cursor/backend-client.test.ts +0 -591
  218. package/src/internal/cursor/credentials.test.ts +0 -351
  219. package/src/internal/cursor/github-credentials.test.ts +0 -136
  220. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  221. package/src/internal/cursor-account.integration.test.ts +0 -441
  222. package/src/internal/cursor-event-relay.test.ts +0 -746
  223. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  224. package/src/internal/cursor-slack-relay.test.ts +0 -525
  225. package/src/internal/deploy-source.test.ts +0 -111
  226. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  227. package/src/internal/discovery.artifacts.test.ts +0 -119
  228. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  229. package/src/internal/discovery.concurrency.test.ts +0 -60
  230. package/src/internal/discovery.cursor-account.test.ts +0 -133
  231. package/src/internal/discovery.cwd.test.ts +0 -83
  232. package/src/internal/discovery.hosting.test.ts +0 -80
  233. package/src/internal/discovery.identity.test.ts +0 -44
  234. package/src/internal/docs-site.test.ts +0 -66
  235. package/src/internal/duration.test.ts +0 -29
  236. package/src/internal/eval-judge-model.test.ts +0 -187
  237. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  238. package/src/internal/eval-run-store.storage.test.ts +0 -211
  239. package/src/internal/eval-runner.http.test.ts +0 -403
  240. package/src/internal/eval-runner.run.test.ts +0 -928
  241. package/src/internal/evals-client.test.ts +0 -307
  242. package/src/internal/event-mapper.test.ts +0 -243
  243. package/src/internal/github-fanout.test.ts +0 -213
  244. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  245. package/src/internal/host-kv.test.ts +0 -82
  246. package/src/internal/host-platforms.test.ts +0 -126
  247. package/src/internal/http-channel.test.ts +0 -402
  248. package/src/internal/init-project.test.ts +0 -270
  249. package/src/internal/install-cursor-skills.test.ts +0 -262
  250. package/src/internal/local-env.test.ts +0 -120
  251. package/src/internal/log-ring.test.ts +0 -31
  252. package/src/internal/logs-client.test.ts +0 -350
  253. package/src/internal/mcp-endpoint.test.ts +0 -436
  254. package/src/internal/mcp-host.test.ts +0 -298
  255. package/src/internal/mcp-oauth.test.ts +0 -148
  256. package/src/internal/net.test.ts +0 -17
  257. package/src/internal/peer-connections.test.ts +0 -128
  258. package/src/internal/peer-mcp.integration.test.ts +0 -289
  259. package/src/internal/playground/toolchain.test.ts +0 -53
  260. package/src/internal/playground-cli.test.ts +0 -187
  261. package/src/internal/playground-proxy.test.ts +0 -376
  262. package/src/internal/prompt-context.integration.test.ts +0 -232
  263. package/src/internal/prompt-context.test.ts +0 -127
  264. package/src/internal/reminder-runner.test.ts +0 -390
  265. package/src/internal/reminder-store.test.ts +0 -53
  266. package/src/internal/request-headers.test.ts +0 -27
  267. package/src/internal/resolve-prod-target.test.ts +0 -787
  268. package/src/internal/resolved-connections.test.ts +0 -295
  269. package/src/internal/router.test.ts +0 -57
  270. package/src/internal/sdk-runner.test.ts +0 -290
  271. package/src/internal/server.artifacts.test.ts +0 -303
  272. package/src/internal/session-engine.artifacts.test.ts +0 -243
  273. package/src/internal/session-engine.coalesce.test.ts +0 -169
  274. package/src/internal/session-engine.concurrency.test.ts +0 -250
  275. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  276. package/src/internal/session-engine.interrupt.test.ts +0 -577
  277. package/src/internal/session-engine.storage.test.ts +0 -547
  278. package/src/internal/session-urls.test.ts +0 -28
  279. package/src/internal/sessions-client.test.ts +0 -518
  280. package/src/internal/storage-coordinator.test.ts +0 -517
  281. package/src/internal/tool-call.test.ts +0 -458
  282. package/src/internal/tool-result.test.ts +0 -52
  283. package/src/internal/trajectory.approvals.test.ts +0 -83
  284. package/src/internal/trajectory.subagents.test.ts +0 -198
  285. package/src/internal/turn-governor.test.ts +0 -137
  286. package/src/internal/update-check.test.ts +0 -485
  287. package/src/internal/workspace.test.ts +0 -207
  288. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,807 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import { httpChannel } from "../../channels.js";
3
- import type { AgentProject, ConnectionTransport } from "../../types.js";
4
- import {
5
- CursorAccountMcpBridge,
6
- collectCursorAccountConnections,
7
- cursorAccountMcpPath,
8
- diagnoseConnectorError,
9
- formatServerStatusSummary,
10
- resolveCursorAccountConnections,
11
- } from "./account-mcp.js";
12
- import { CursorBackendClient } from "./backend-client.js";
13
-
14
- function makeProject(
15
- name: string,
16
- connections: Array<{ name: string; transport: ConnectionTransport }> = []
17
- ): AgentProject {
18
- return {
19
- rootDir: `/tmp/account-fixture-${name}`,
20
- agentDir: `/tmp/account-fixture-${name}/agent`,
21
- name,
22
- agent: {
23
- name,
24
- runtime: "local",
25
- tools: [],
26
- skills: [],
27
- connections,
28
- subagents: [],
29
- seedFiles: [],
30
- },
31
- httpChannel: httpChannel(),
32
- channels: [],
33
- schedules: [],
34
- hooks: [],
35
- abs: [],
36
- diagnostics: [],
37
- };
38
- }
39
-
40
- function fakeJwt(): string {
41
- const claims = Buffer.from(
42
- JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 3600 })
43
- ).toString("base64url");
44
- return `header.${claims}.signature`;
45
- }
46
-
47
- /** A stubbed backend client whose listings/executions come from `handlers`. */
48
- function stubClient(handlers: {
49
- list?: (serverIdentifiers: readonly string[]) => unknown;
50
- execute?: (body: {
51
- serverIdentifier: string;
52
- toolName: string;
53
- args: Record<string, unknown>;
54
- }) => unknown;
55
- onList?: () => void;
56
- }): CursorBackendClient {
57
- const fetchImpl = (async (input: RequestInfo | URL, init?: RequestInit) => {
58
- const url = String(input);
59
- if (url.endsWith("/auth/exchange_user_api_key")) {
60
- return Response.json({ accessToken: fakeJwt(), refreshToken: "r" });
61
- }
62
- const body = JSON.parse(String(init?.body ?? "{}")) as Record<
63
- string,
64
- unknown
65
- >;
66
- if (url.endsWith("/ListSandMcpTools")) {
67
- handlers.onList?.();
68
- return Response.json(
69
- handlers.list?.((body.serverIdentifiers as string[]) ?? []) ?? {
70
- servers: [],
71
- }
72
- );
73
- }
74
- if (url.endsWith("/ExecuteSandMcpTool")) {
75
- return Response.json(
76
- handlers.execute?.(
77
- body as {
78
- serverIdentifier: string;
79
- toolName: string;
80
- args: Record<string, unknown>;
81
- }
82
- ) ?? { result: { error: { error: "no execute stub" } } }
83
- );
84
- }
85
- return new Response("{}", { status: 404 });
86
- }) as typeof fetch;
87
- return new CursorBackendClient({
88
- backendUrl: "https://backend.example",
89
- apiKey: "crsr_key",
90
- fetchImpl,
91
- });
92
- }
93
-
94
- const CONNECTED_LINEAR = {
95
- servers: [
96
- {
97
- serverIdentifier: "Linear",
98
- status: "connected",
99
- tools: [
100
- {
101
- name: "Linear-list_issues",
102
- description: "List issues.",
103
- inputSchema: { type: "object" },
104
- },
105
- ],
106
- },
107
- ],
108
- };
109
-
110
- function rpcRequest(secret: string, body: unknown): Request {
111
- return new Request("http://127.0.0.1:3000/v1/cursor-account/cursor/mcp", {
112
- method: "POST",
113
- headers: {
114
- "content-type": "application/json",
115
- accept: "application/json, text/event-stream",
116
- authorization: `Bearer ${secret}`,
117
- },
118
- body: JSON.stringify(body),
119
- });
120
- }
121
-
122
- describe("collectCursorAccountConnections", () => {
123
- it("groups account MCP connections by mount slug and keeps filters", () => {
124
- const mounts = [
125
- {
126
- slug: "bugbot",
127
- project: makeProject("bugbot", [
128
- {
129
- name: "cursor",
130
- transport: { cursorAccount: true, servers: ["Linear"] },
131
- },
132
- { name: "linear", transport: { url: "https://mcp.example/mcp" } },
133
- ]),
134
- },
135
- { slug: "plain", project: makeProject("plain") },
136
- ];
137
- const collected = collectCursorAccountConnections(mounts);
138
- expect([...collected.keys()]).toEqual(["bugbot"]);
139
- expect(collected.get("bugbot")).toEqual([
140
- { name: "cursor", servers: ["Linear"] },
141
- ]);
142
- });
143
- });
144
-
145
- describe("resolveCursorAccountConnections", () => {
146
- it("resolves loopback bridge URLs with the boot secret and no cloudUrl", () => {
147
- const resolved = resolveCursorAccountConnections({
148
- refs: [{ name: "cursor" }],
149
- serverUrl: "http://127.0.0.1:4100",
150
- basePath: "/bugbot",
151
- bridgeSecret: "s3cret",
152
- });
153
- expect(resolved).toEqual([
154
- {
155
- name: "cursor",
156
- localUrl: `http://127.0.0.1:4100/bugbot${cursorAccountMcpPath("cursor")}`,
157
- headers: { authorization: "Bearer s3cret" },
158
- },
159
- ]);
160
- expect(resolved[0]).not.toHaveProperty("cloudUrl");
161
- });
162
-
163
- it("resolves cloudUrl from publicUrl so cloud turns use the filtered bridge", () => {
164
- const resolved = resolveCursorAccountConnections({
165
- refs: [{ name: "cursor", servers: ["Linear"] }],
166
- serverUrl: "http://127.0.0.1:4100",
167
- basePath: "/bugbot",
168
- bridgeSecret: "s3cret",
169
- publicUrl: "https://agents.example.com",
170
- });
171
- expect(resolved[0]?.cloudUrl).toBe(
172
- `https://agents.example.com/bugbot${cursorAccountMcpPath("cursor")}`
173
- );
174
- });
175
-
176
- it("uses the serve bind host for localUrl when not loopback", () => {
177
- const resolved = resolveCursorAccountConnections({
178
- refs: [{ name: "cursor" }],
179
- serverUrl: "http://192.168.1.50:4100",
180
- basePath: "",
181
- bridgeSecret: "s3cret",
182
- });
183
- expect(resolved[0]?.localUrl).toBe(
184
- `http://192.168.1.50:4100${cursorAccountMcpPath("cursor")}`
185
- );
186
- });
187
- });
188
-
189
- describe("CursorAccountMcpBridge auth", () => {
190
- const request = (secret?: string): Request =>
191
- new Request("http://127.0.0.1:3000/v1/cursor-account/cursor/mcp", {
192
- method: "POST",
193
- ...(secret === undefined
194
- ? {}
195
- : { headers: { authorization: `Bearer ${secret}` } }),
196
- });
197
-
198
- it("admits only loopback callers presenting the boot secret by default", async () => {
199
- const bridge = new CursorAccountMcpBridge({ client: stubClient({}) });
200
- const policy = bridge.authPolicy();
201
-
202
- expect(
203
- await policy(request(bridge.secret), { requestIp: "127.0.0.1" })
204
- ).toMatchObject({ principalType: "runtime" });
205
- // Without a publicUrl the bridge is never remotely reachable — even
206
- // with the secret.
207
- expect(
208
- await policy(request(bridge.secret), { requestIp: "203.0.113.9" })
209
- ).toBeNull();
210
- expect(
211
- await policy(request("wrong-secret"), { requestIp: "127.0.0.1" })
212
- ).toBeNull();
213
- expect(await policy(request(), { requestIp: "127.0.0.1" })).toBeNull();
214
- });
215
-
216
- it("admits remote callers with the secret when publicUrl exposure is on", async () => {
217
- const bridge = new CursorAccountMcpBridge({
218
- client: stubClient({}),
219
- allowRemoteCallers: true,
220
- });
221
- const policy = bridge.authPolicy();
222
-
223
- expect(
224
- await policy(request(bridge.secret), { requestIp: "203.0.113.9" })
225
- ).toMatchObject({ principalType: "runtime" });
226
- expect(
227
- await policy(request("wrong-secret"), { requestIp: "203.0.113.9" })
228
- ).toBeNull();
229
- });
230
- });
231
-
232
- describe("CursorAccountMcpBridge MCP surface", () => {
233
- it("forwards every account connector when servers is omitted", async () => {
234
- const requested: string[][] = [];
235
- const bridge = new CursorAccountMcpBridge({
236
- client: stubClient({
237
- list: (serverIdentifiers) => {
238
- requested.push([...serverIdentifiers]);
239
- return {
240
- servers: [
241
- {
242
- serverIdentifier: "Linear",
243
- status: "connected",
244
- tools: [
245
- {
246
- name: "Linear-list_issues",
247
- description: "List issues.",
248
- inputSchema: { type: "object" },
249
- },
250
- ],
251
- },
252
- {
253
- serverIdentifier: "Notion",
254
- status: "connected",
255
- tools: [
256
- {
257
- name: "Notion-search",
258
- description: "Search pages.",
259
- inputSchema: { type: "object" },
260
- },
261
- ],
262
- },
263
- ],
264
- };
265
- },
266
- }),
267
- });
268
- const ref = { name: "cursor" };
269
-
270
- const listResponse = await bridge.handle(
271
- rpcRequest(bridge.secret, {
272
- jsonrpc: "2.0",
273
- id: 1,
274
- method: "tools/list",
275
- params: {},
276
- }),
277
- ref
278
- );
279
- expect(listResponse.status).toBe(200);
280
- expect(requested).toEqual([[]]);
281
- const listBody = (await listResponse.json()) as {
282
- result: { tools: Array<{ name: string }> };
283
- };
284
- expect(listBody.result.tools.map((tool) => tool.name).sort()).toEqual([
285
- "Linear-list_issues",
286
- "Notion-search",
287
- ]);
288
- });
289
-
290
- it("lists connector tools and executes them on the backend", async () => {
291
- const executions: Array<{ serverIdentifier: string; toolName: string }> =
292
- [];
293
- const bridge = new CursorAccountMcpBridge({
294
- client: stubClient({
295
- list: (serverIdentifiers) => {
296
- expect(serverIdentifiers).toEqual(["Linear"]);
297
- return CONNECTED_LINEAR;
298
- },
299
- execute: (body) => {
300
- executions.push(body);
301
- return {
302
- result: {
303
- success: {
304
- content: [{ text: { text: "2 open issues" } }],
305
- isError: false,
306
- },
307
- },
308
- };
309
- },
310
- }),
311
- });
312
- const ref = { name: "cursor", servers: ["Linear"] };
313
-
314
- const listResponse = await bridge.handle(
315
- rpcRequest(bridge.secret, {
316
- jsonrpc: "2.0",
317
- id: 1,
318
- method: "tools/list",
319
- params: {},
320
- }),
321
- ref
322
- );
323
- expect(listResponse.status).toBe(200);
324
- const listBody = (await listResponse.json()) as {
325
- result: { tools: Array<{ name: string; inputSchema: unknown }> };
326
- };
327
- expect(listBody.result.tools).toEqual([
328
- {
329
- name: "Linear-list_issues",
330
- description: "List issues.",
331
- inputSchema: { type: "object" },
332
- },
333
- ]);
334
-
335
- const callResponse = await bridge.handle(
336
- rpcRequest(bridge.secret, {
337
- jsonrpc: "2.0",
338
- id: 2,
339
- method: "tools/call",
340
- params: { name: "Linear-list_issues", arguments: { query: "open" } },
341
- }),
342
- ref
343
- );
344
- expect(callResponse.status).toBe(200);
345
- const callBody = (await callResponse.json()) as {
346
- result: { content: Array<{ type: string; text: string }> };
347
- };
348
- expect(callBody.result.content).toEqual([
349
- { type: "text", text: "2 open issues" },
350
- ]);
351
- expect(executions).toHaveLength(1);
352
- expect(executions[0]).toMatchObject({
353
- serverIdentifier: "Linear",
354
- toolName: "Linear-list_issues",
355
- args: { query: "open" },
356
- });
357
- });
358
-
359
- it("sanitizes exotic connector tool names and maps them back for execution", async () => {
360
- const executed: string[] = [];
361
- const bridge = new CursorAccountMcpBridge({
362
- client: stubClient({
363
- list: () => ({
364
- servers: [
365
- {
366
- serverIdentifier: "My Wiki",
367
- status: "connected",
368
- tools: [
369
- { name: "My Wiki-search pages" },
370
- { name: "My Wiki-search_pages" },
371
- ],
372
- },
373
- ],
374
- }),
375
- execute: (body) => {
376
- executed.push(body.toolName);
377
- return {
378
- result: { success: { content: [{ text: { text: "ok" } }] } },
379
- };
380
- },
381
- }),
382
- });
383
- const ref = { name: "cursor" };
384
-
385
- const listResponse = await bridge.handle(
386
- rpcRequest(bridge.secret, {
387
- jsonrpc: "2.0",
388
- id: 1,
389
- method: "tools/list",
390
- params: {},
391
- }),
392
- ref
393
- );
394
- const listBody = (await listResponse.json()) as {
395
- result: { tools: Array<{ name: string }> };
396
- };
397
- // Both sanitize to the same base; the collision gets a suffix.
398
- expect(listBody.result.tools.map((tool) => tool.name)).toEqual([
399
- "My_Wiki-search_pages",
400
- "My_Wiki-search_pages_2",
401
- ]);
402
-
403
- await bridge.handle(
404
- rpcRequest(bridge.secret, {
405
- jsonrpc: "2.0",
406
- id: 2,
407
- method: "tools/call",
408
- params: { name: "My_Wiki-search_pages_2", arguments: {} },
409
- }),
410
- ref
411
- );
412
- // The backend receives the original fully-qualified name.
413
- expect(executed).toEqual(["My Wiki-search_pages"]);
414
- });
415
-
416
- it("returns a tool error (not a crash) for unknown tools", async () => {
417
- let listCalls = 0;
418
- const bridge = new CursorAccountMcpBridge({
419
- client: stubClient({
420
- list: () => CONNECTED_LINEAR,
421
- onList: () => {
422
- listCalls++;
423
- },
424
- }),
425
- });
426
- const ref = { name: "cursor" };
427
- const response = await bridge.handle(
428
- rpcRequest(bridge.secret, {
429
- jsonrpc: "2.0",
430
- id: 1,
431
- method: "tools/call",
432
- params: { name: "does_not_exist", arguments: {} },
433
- }),
434
- ref
435
- );
436
- const body = (await response.json()) as {
437
- result: { isError?: boolean; content: Array<{ text: string }> };
438
- };
439
- expect(body.result.isError).toBe(true);
440
- expect(body.result.content[0]?.text).toContain(
441
- 'Unknown tool "does_not_exist"'
442
- );
443
- expect(body.result.content[0]?.text).toContain("Linear-list_issues");
444
- // The catalog is fresh; the unknown name does not force a re-fetch.
445
- expect(listCalls).toBe(1);
446
- });
447
-
448
- it("returns a tool error when backend execution throws", async () => {
449
- const bridge = new CursorAccountMcpBridge({
450
- client: stubClient({
451
- list: () => CONNECTED_LINEAR,
452
- execute: () => {
453
- throw new Error("network down");
454
- },
455
- }),
456
- });
457
- const ref = { name: "cursor", servers: ["Linear"] };
458
- const response = await bridge.handle(
459
- rpcRequest(bridge.secret, {
460
- jsonrpc: "2.0",
461
- id: 1,
462
- method: "tools/call",
463
- params: { name: "Linear-list_issues", arguments: {} },
464
- }),
465
- ref
466
- );
467
- expect(response.status).toBe(200);
468
- const body = (await response.json()) as {
469
- result: { isError?: boolean; content: Array<{ text: string }> };
470
- };
471
- expect(body.result.isError).toBe(true);
472
- expect(body.result.content[0]?.text).toContain("network down");
473
- });
474
-
475
- it("rejects non-POST requests per the stateless MCP contract", async () => {
476
- const bridge = new CursorAccountMcpBridge({ client: stubClient({}) });
477
- const response = await bridge.handle(
478
- new Request("http://127.0.0.1:3000/v1/cursor-account/cursor/mcp", {
479
- method: "GET",
480
- }),
481
- { name: "cursor" }
482
- );
483
- expect(response.status).toBe(405);
484
- });
485
- });
486
-
487
- describe("CursorAccountMcpBridge catalog cache", () => {
488
- afterEach(() => {
489
- vi.useRealTimers();
490
- });
491
-
492
- it("coalesces concurrent readers and refreshes once after the TTL", async () => {
493
- vi.useFakeTimers();
494
- let listCalls = 0;
495
- const bridge = new CursorAccountMcpBridge({
496
- client: stubClient({
497
- list: () => CONNECTED_LINEAR,
498
- onList: () => {
499
- listCalls++;
500
- },
501
- }),
502
- });
503
- const ref = { name: "cursor" };
504
- const listRequest = (id: number): Request =>
505
- rpcRequest(bridge.secret, {
506
- jsonrpc: "2.0",
507
- id,
508
- method: "tools/list",
509
- params: {},
510
- });
511
-
512
- // Concurrent cold readers share one backend fetch.
513
- await Promise.all([
514
- bridge.handle(listRequest(1), ref),
515
- bridge.handle(listRequest(2), ref),
516
- ]);
517
- expect(listCalls).toBe(1);
518
-
519
- // Within the TTL: served from cache.
520
- await bridge.handle(listRequest(3), ref);
521
- expect(listCalls).toBe(1);
522
-
523
- // Past the TTL: concurrent stale readers coalesce onto ONE refresh.
524
- vi.advanceTimersByTime(61_000);
525
- await Promise.all([
526
- bridge.handle(listRequest(4), ref),
527
- bridge.handle(listRequest(5), ref),
528
- ]);
529
- expect(listCalls).toBe(2);
530
- });
531
-
532
- it("force-refreshes on unknown tools, throttled to the refresh floor", async () => {
533
- vi.useFakeTimers();
534
- let listCalls = 0;
535
- const bridge = new CursorAccountMcpBridge({
536
- client: stubClient({
537
- list: () => CONNECTED_LINEAR,
538
- onList: () => {
539
- listCalls++;
540
- },
541
- }),
542
- });
543
- const ref = { name: "cursor" };
544
- const unknownCall = (id: number): Request =>
545
- rpcRequest(bridge.secret, {
546
- jsonrpc: "2.0",
547
- id,
548
- method: "tools/call",
549
- params: { name: "still_not_a_tool", arguments: {} },
550
- });
551
-
552
- // Fresh catalog: the unknown name joins it instead of re-fetching.
553
- await bridge.handle(unknownCall(1), ref);
554
- expect(listCalls).toBe(1);
555
-
556
- // Past the force-refresh floor (but inside the TTL): the unknown name
557
- // triggers exactly one re-fetch; an immediate repeat joins it.
558
- vi.advanceTimersByTime(6_000);
559
- await bridge.handle(unknownCall(2), ref);
560
- expect(listCalls).toBe(2);
561
- await bridge.handle(unknownCall(3), ref);
562
- expect(listCalls).toBe(2);
563
- });
564
-
565
- it("assigns collision suffixes stably regardless of backend ordering", async () => {
566
- const serverA = {
567
- serverIdentifier: "A Wiki",
568
- status: "connected",
569
- tools: [{ name: "A Wiki-search", description: "from A" }],
570
- };
571
- const serverB = {
572
- serverIdentifier: "A_Wiki",
573
- status: "connected",
574
- tools: [{ name: "A_Wiki-search", description: "from B" }],
575
- };
576
-
577
- const mappingFor = async (
578
- servers: unknown[]
579
- ): Promise<Map<string, string>> => {
580
- const bridge = new CursorAccountMcpBridge({
581
- client: stubClient({ list: () => ({ servers }) }),
582
- });
583
- const response = await bridge.handle(
584
- rpcRequest(bridge.secret, {
585
- jsonrpc: "2.0",
586
- id: 1,
587
- method: "tools/list",
588
- params: {},
589
- }),
590
- { name: "cursor" }
591
- );
592
- const body = (await response.json()) as {
593
- result: { tools: Array<{ name: string; description: string }> };
594
- };
595
- return new Map(
596
- body.result.tools.map((tool) => [tool.name, tool.description])
597
- );
598
- };
599
-
600
- // Both tools sanitize to "A_Wiki-search"; the exposed-name → backend-tool
601
- // mapping must not depend on which server the backend lists first.
602
- const forward = await mappingFor([serverA, serverB]);
603
- const reversed = await mappingFor([serverB, serverA]);
604
- expect(forward).toEqual(reversed);
605
- expect([...forward.keys()].sort()).toEqual([
606
- "A_Wiki-search",
607
- "A_Wiki-search_2",
608
- ]);
609
- });
610
-
611
- it("assigns cross-group exposed names stably regardless of backend ordering", async () => {
612
- const serverAlpha = {
613
- serverIdentifier: "Alpha",
614
- status: "connected",
615
- tools: [
616
- { name: "dup", description: "alpha-first" },
617
- { name: "dup", description: "alpha-second" },
618
- ],
619
- };
620
- const serverBeta = {
621
- serverIdentifier: "Beta",
622
- status: "connected",
623
- tools: [{ name: "dup_2", description: "beta" }],
624
- };
625
-
626
- const mappingFor = async (
627
- servers: unknown[]
628
- ): Promise<Map<string, string>> => {
629
- const bridge = new CursorAccountMcpBridge({
630
- client: stubClient({ list: () => ({ servers }) }),
631
- });
632
- const response = await bridge.handle(
633
- rpcRequest(bridge.secret, {
634
- jsonrpc: "2.0",
635
- id: 1,
636
- method: "tools/list",
637
- params: {},
638
- }),
639
- { name: "cursor" }
640
- );
641
- const body = (await response.json()) as {
642
- result: { tools: Array<{ name: string; description: string }> };
643
- };
644
- return new Map(
645
- body.result.tools.map((tool) => [tool.description, tool.name])
646
- );
647
- };
648
-
649
- const forward = await mappingFor([serverAlpha, serverBeta]);
650
- const reversed = await mappingFor([serverBeta, serverAlpha]);
651
- expect(forward).toEqual(reversed);
652
- expect([...forward.values()].sort()).toEqual(["dup", "dup_2", "dup_2_2"]);
653
- });
654
-
655
- it("avoids global exposed-name collisions across sanitize groups", async () => {
656
- const bridge = new CursorAccountMcpBridge({
657
- client: stubClient({
658
- list: () => ({
659
- servers: [
660
- {
661
- serverIdentifier: "Linear",
662
- status: "connected",
663
- tools: [{ name: "search", description: "linear search" }],
664
- },
665
- {
666
- serverIdentifier: "Other",
667
- status: "connected",
668
- tools: [{ name: "search_2", description: "other search" }],
669
- },
670
- ],
671
- }),
672
- }),
673
- });
674
- const response = await bridge.handle(
675
- rpcRequest(bridge.secret, {
676
- jsonrpc: "2.0",
677
- id: 1,
678
- method: "tools/list",
679
- params: {},
680
- }),
681
- { name: "cursor" }
682
- );
683
- const body = (await response.json()) as {
684
- result: { tools: Array<{ name: string }> };
685
- };
686
- const names = body.result.tools.map((tool) => tool.name);
687
- expect(new Set(names).size).toBe(names.length);
688
- expect(names.sort()).toEqual(["search", "search_2"]);
689
- });
690
- });
691
-
692
- describe("formatServerStatusSummary", () => {
693
- it("describes connected / needsAuth / error statuses", () => {
694
- expect(
695
- formatServerStatusSummary({
696
- serverIdentifier: "Linear",
697
- status: "connected",
698
- tools: [{ name: "a", description: "", inputSchema: {} }],
699
- })
700
- ).toBe("Linear (1 tools)");
701
- expect(
702
- formatServerStatusSummary({
703
- serverIdentifier: "Notion",
704
- status: "needsAuth",
705
- tools: [],
706
- })
707
- ).toBe("Notion (needsAuth — re-authorize in Cursor)");
708
- expect(
709
- formatServerStatusSummary(
710
- { serverIdentifier: "anytool", status: "error", tools: [] },
711
- "HTTP MCP tool execution failed: fetch failed"
712
- )
713
- ).toBe("anytool (error: HTTP MCP tool execution failed: fetch failed)");
714
- expect(
715
- formatServerStatusSummary({
716
- serverIdentifier: "anytool",
717
- status: "error",
718
- tools: [],
719
- })
720
- ).toBe("anytool (error: backend could not reach connector)");
721
- });
722
- });
723
-
724
- describe("diagnoseConnectorError", () => {
725
- it("returns the backend execute failure text", async () => {
726
- const detail = await diagnoseConnectorError(
727
- {
728
- executeAccountMcpTool: async () => ({
729
- content: [
730
- {
731
- type: "text",
732
- text: "HTTP MCP tool execution failed: fetch failed",
733
- },
734
- ],
735
- isError: true,
736
- }),
737
- },
738
- "anytool"
739
- );
740
- expect(detail).toBe("HTTP MCP tool execution failed: fetch failed");
741
- });
742
- });
743
-
744
- describe("CursorAccountMcpBridge.logPreflight", () => {
745
- it("logs connector error detail from a backend probe", async () => {
746
- const lines: string[] = [];
747
- const bridge = new CursorAccountMcpBridge({
748
- client: stubClient({
749
- list: () => ({
750
- servers: [
751
- { serverIdentifier: "anytool", status: "error", tools: [] },
752
- {
753
- serverIdentifier: "Linear",
754
- status: "connected",
755
- tools: [{ name: "Linear-list_issues" }],
756
- },
757
- ],
758
- }),
759
- execute: () => ({
760
- result: {
761
- error: {
762
- error: "HTTP MCP tool execution failed: fetch failed",
763
- },
764
- },
765
- }),
766
- }),
767
- logger: (line) => lines.push(line),
768
- });
769
-
770
- await bridge.logPreflight([{ name: "anytool", servers: ["anytool"] }]);
771
-
772
- expect(lines[0]).toContain(
773
- 'Cursor account MCP connection "anytool": anytool (error: HTTP MCP tool execution failed: fetch failed), Linear (1 tools)'
774
- );
775
- expect(
776
- lines.some((line) => line.includes("could not use this connector"))
777
- ).toBe(true);
778
- });
779
-
780
- it("mentions unhealthy connectors when a tool is missing", async () => {
781
- const bridge = new CursorAccountMcpBridge({
782
- client: stubClient({
783
- list: () => ({
784
- servers: [
785
- { serverIdentifier: "anytool", status: "error", tools: [] },
786
- ],
787
- }),
788
- }),
789
- });
790
- const response = await bridge.handle(
791
- rpcRequest(bridge.secret, {
792
- jsonrpc: "2.0",
793
- id: 1,
794
- method: "tools/call",
795
- params: { name: "create_anyship_deployment", arguments: {} },
796
- }),
797
- { name: "anytool", servers: ["anytool"] }
798
- );
799
- const body = (await response.json()) as {
800
- result: { content: Array<{ text: string }>; isError?: boolean };
801
- };
802
- expect(body.result.isError).toBe(true);
803
- expect(body.result.content[0]?.text).toContain(
804
- "Unhealthy connectors: anytool=error"
805
- );
806
- });
807
- });