@cursor/july 0.1.26 → 0.1.28

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 (324) 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 +43 -12
  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/auth.d.ts +13 -13
  17. package/dist/channels/slack/auth.d.ts.map +1 -1
  18. package/dist/channels/slack/auth.js +19 -10
  19. package/dist/channels/slack/cursor-account.d.ts +2 -1
  20. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  21. package/dist/channels/slack/cursor-account.js +3 -1
  22. package/dist/channels/slack/defaults.d.ts +7 -4
  23. package/dist/channels/slack/defaults.d.ts.map +1 -1
  24. package/dist/channels/slack/defaults.js +14 -4
  25. package/dist/channels/slack/dispatch.d.ts +10 -1
  26. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  27. package/dist/channels/slack/dispatch.js +59 -21
  28. package/dist/channels/slack/external-policy.d.ts +27 -0
  29. package/dist/channels/slack/external-policy.d.ts.map +1 -0
  30. package/dist/channels/slack/external-policy.js +53 -0
  31. package/dist/channels/slack/index.d.ts +1 -0
  32. package/dist/channels/slack/index.d.ts.map +1 -1
  33. package/dist/channels/slack/index.js +1 -0
  34. package/dist/channels/slack/interactive.d.ts +8 -1
  35. package/dist/channels/slack/interactive.d.ts.map +1 -1
  36. package/dist/channels/slack/interactive.js +43 -15
  37. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  38. package/dist/channels/slack/slack-channel.js +22 -8
  39. package/dist/channels/slack/types.d.ts +16 -1
  40. package/dist/channels/slack/types.d.ts.map +1 -1
  41. package/dist/docs/404.html +2 -2
  42. package/dist/docs/ab.html +3 -3
  43. package/dist/docs/assets/{app.DYcC9FY-.js → app.CqjrYaT2.js} +1 -1
  44. package/dist/docs/assets/chunks/@localSearchIndexroot.VWQoPFJ1.js +1 -0
  45. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.ag-MwUel.js} +1 -1
  46. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.BS-DJWat.js} +2 -2
  47. package/dist/docs/assets/{guides_slack.md.D_xFKlnF.js → guides_slack.md.CjmJSvZS.js} +8 -4
  48. package/dist/docs/assets/guides_slack.md.CjmJSvZS.lean.js +1 -0
  49. package/dist/docs/assets/guides_webhooks.md.wSOYas3X.js +183 -0
  50. package/dist/docs/assets/{guides_webhooks.md.B1EswtUu.lean.js → guides_webhooks.md.wSOYas3X.lean.js} +1 -1
  51. package/dist/docs/assets/{index.md.Dfv5ic9t.js → index.md.CH_s5uZe.js} +1 -1
  52. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.js → reference_channels.md.CDhTRfUz.js} +2 -2
  53. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.lean.js → reference_channels.md.CDhTRfUz.lean.js} +1 -1
  54. package/dist/docs/building-with-agents.html +3 -3
  55. package/dist/docs/concepts.html +3 -3
  56. package/dist/docs/deployment.html +3 -3
  57. package/dist/docs/evals.html +3 -3
  58. package/dist/docs/example-agents/approval-buddy.html +3 -3
  59. package/dist/docs/example-agents/benny.html +3 -3
  60. package/dist/docs/example-agents/bugbot.html +3 -3
  61. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  62. package/dist/docs/example-agents/codeowners-review.html +3 -3
  63. package/dist/docs/example-agents/concierge.html +3 -3
  64. package/dist/docs/example-agents/fsd.html +3 -3
  65. package/dist/docs/example-agents/index.html +3 -3
  66. package/dist/docs/example-agents/knowledge-base.html +3 -3
  67. package/dist/docs/example-agents/oncall.html +3 -3
  68. package/dist/docs/example-agents/security-reviewer.html +3 -3
  69. package/dist/docs/example-agents/slack-agent.html +3 -3
  70. package/dist/docs/example-agents/weather-agent.html +3 -3
  71. package/dist/docs/guides/agent-to-agent.html +3 -3
  72. package/dist/docs/guides/cloud-runtime.html +3 -3
  73. package/dist/docs/guides/github.html +3 -3
  74. package/dist/docs/guides/human-in-the-loop.html +3 -3
  75. package/dist/docs/guides/mcp-oauth.html +3 -3
  76. package/dist/docs/guides/slack.html +11 -7
  77. package/dist/docs/guides/webhooks.html +138 -5
  78. package/dist/docs/hashmap.json +1 -1
  79. package/dist/docs/hillclimbing.html +3 -3
  80. package/dist/docs/index.html +5 -5
  81. package/dist/docs/quickstart.html +3 -3
  82. package/dist/docs/reference/agent-config.html +3 -3
  83. package/dist/docs/reference/channels.html +5 -5
  84. package/dist/docs/reference/cli.html +3 -3
  85. package/dist/docs/reference/connections.html +3 -3
  86. package/dist/docs/reference/hooks.html +3 -3
  87. package/dist/docs/reference/http-api.html +3 -3
  88. package/dist/docs/reference/instructions.html +3 -3
  89. package/dist/docs/reference/playground.html +3 -3
  90. package/dist/docs/reference/project-layout.html +3 -3
  91. package/dist/docs/reference/prompt.html +3 -3
  92. package/dist/docs/reference/schedules.html +3 -3
  93. package/dist/docs/reference/sessions.html +3 -3
  94. package/dist/docs/reference/skills.html +3 -3
  95. package/dist/docs/reference/subagents.html +3 -3
  96. package/dist/docs/reference/tools.html +3 -3
  97. package/dist/docs/scaffolding-agents.html +3 -3
  98. package/dist/docs/storage.html +3 -3
  99. package/dist/docs/troubleshooting.html +3 -3
  100. package/dist/evals/assertions.d.ts +10 -1
  101. package/dist/evals/assertions.d.ts.map +1 -1
  102. package/dist/evals/assertions.js +12 -0
  103. package/dist/evals.d.ts +1 -1
  104. package/dist/evals.d.ts.map +1 -1
  105. package/dist/index.d.ts +1 -0
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +1 -0
  108. package/dist/internal/ab-fold.d.ts.map +1 -1
  109. package/dist/internal/ab-fold.js +4 -0
  110. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  111. package/dist/internal/ab-snapshot.js +1 -0
  112. package/dist/internal/artifacts-store.d.ts +45 -0
  113. package/dist/internal/artifacts-store.d.ts.map +1 -0
  114. package/dist/internal/artifacts-store.js +250 -0
  115. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  116. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  117. package/dist/internal/builtin-tools/artifacts.js +73 -0
  118. package/dist/internal/builtin-tools/index.d.ts +8 -1
  119. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  120. package/dist/internal/builtin-tools/index.js +15 -0
  121. package/dist/internal/cli-ax.d.ts +19 -0
  122. package/dist/internal/cli-ax.d.ts.map +1 -1
  123. package/dist/internal/cli-ax.js +196 -57
  124. package/dist/internal/cli-slack.d.ts.map +1 -1
  125. package/dist/internal/cli-slack.js +14 -6
  126. package/dist/internal/cursor-slack-relay.d.ts +2 -0
  127. package/dist/internal/cursor-slack-relay.d.ts.map +1 -1
  128. package/dist/internal/cursor-slack-relay.js +1 -0
  129. package/dist/internal/deploy-client.d.ts +2 -0
  130. package/dist/internal/deploy-client.d.ts.map +1 -1
  131. package/dist/internal/deploy-client.js +1 -0
  132. package/dist/internal/discovery.d.ts.map +1 -1
  133. package/dist/internal/discovery.js +91 -3
  134. package/dist/internal/distribution.d.ts.map +1 -1
  135. package/dist/internal/distribution.js +1 -0
  136. package/dist/internal/model-pricing.d.ts +49 -0
  137. package/dist/internal/model-pricing.d.ts.map +1 -0
  138. package/dist/internal/model-pricing.js +377 -0
  139. package/dist/internal/reminder-runner.d.ts.map +1 -1
  140. package/dist/internal/reminder-runner.js +1 -0
  141. package/dist/internal/schedule-runner.d.ts.map +1 -1
  142. package/dist/internal/schedule-runner.js +1 -0
  143. package/dist/internal/sdk-runner.d.ts.map +1 -1
  144. package/dist/internal/sdk-runner.js +9 -1
  145. package/dist/internal/server.d.ts.map +1 -1
  146. package/dist/internal/server.js +49 -5
  147. package/dist/internal/session-cost.d.ts +49 -0
  148. package/dist/internal/session-cost.d.ts.map +1 -0
  149. package/dist/internal/session-cost.js +175 -0
  150. package/dist/internal/session-engine.d.ts +35 -1
  151. package/dist/internal/session-engine.d.ts.map +1 -1
  152. package/dist/internal/session-engine.js +128 -7
  153. package/dist/internal/storage-coordinator.d.ts +15 -0
  154. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  155. package/dist/internal/storage-coordinator.js +52 -0
  156. package/dist/internal/trajectory.d.ts +9 -1
  157. package/dist/internal/trajectory.d.ts.map +1 -1
  158. package/dist/internal/trajectory.js +32 -5
  159. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  160. package/dist/playground/assets/index-CkN74U_L.js +87 -0
  161. package/dist/playground/index.html +2 -2
  162. package/dist/storage.d.ts +4 -0
  163. package/dist/storage.d.ts.map +1 -1
  164. package/dist/storage.js +4 -0
  165. package/dist/types.d.ts +164 -1
  166. package/dist/types.d.ts.map +1 -1
  167. package/docs/README.md +1 -0
  168. package/docs/guides/slack.md +32 -7
  169. package/docs/guides/webhooks.md +183 -0
  170. package/docs/reference/channels.md +2 -1
  171. package/package.json +26 -26
  172. package/skills/setup-slack/SKILL.md +3 -0
  173. package/src/ab.ts +7 -0
  174. package/src/bin/agent-serve.ts +42 -5
  175. package/src/channels/slack/auth.ts +29 -22
  176. package/src/channels/slack/cursor-account.ts +2 -0
  177. package/src/channels/slack/defaults.ts +24 -4
  178. package/src/channels/slack/dispatch.ts +42 -1
  179. package/src/channels/slack/external-policy.ts +62 -0
  180. package/src/channels/slack/index.ts +1 -0
  181. package/src/channels/slack/interactive.ts +42 -10
  182. package/src/channels/slack/slack-channel.ts +20 -3
  183. package/src/channels/slack/types.ts +12 -0
  184. package/src/internal/ab-fold.ts +4 -0
  185. package/src/internal/ab-snapshot.ts +1 -0
  186. package/src/internal/cli-ax.ts +205 -34
  187. package/src/internal/cursor-slack-relay.ts +3 -0
  188. package/src/internal/deploy-client.ts +3 -0
  189. package/src/internal/discovery.ts +8 -1
  190. package/src/internal/model-pricing.ts +426 -0
  191. package/src/internal/sdk-runner.ts +10 -2
  192. package/src/internal/server.ts +9 -5
  193. package/src/internal/session-cost.ts +231 -0
  194. package/src/internal/session-engine.ts +28 -0
  195. package/src/internal/trajectory.ts +45 -3
  196. package/src/types.ts +24 -1
  197. package/dist/channels/github/instrument.d.ts +0 -20
  198. package/dist/channels/github/instrument.d.ts.map +0 -1
  199. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  200. package/dist/docs/assets/guides_slack.md.D_xFKlnF.lean.js +0 -1
  201. package/dist/docs/assets/guides_webhooks.md.B1EswtUu.js +0 -50
  202. package/dist/internal/json-dir-store.d.ts +0 -32
  203. package/dist/internal/json-dir-store.d.ts.map +0 -1
  204. package/dist/internal/json-dir-store.js +0 -100
  205. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  206. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  207. package/src/bin/agent-serve.version.test.ts +0 -64
  208. package/src/channels/github/api.test.ts +0 -64
  209. package/src/channels/github/auth.test.ts +0 -105
  210. package/src/channels/github/cursor-account.test.ts +0 -204
  211. package/src/channels/github/forward.test.ts +0 -457
  212. package/src/channels/github/github.test.ts +0 -985
  213. package/src/channels/github/replay.test.ts +0 -179
  214. package/src/channels/slack/api.post-message.test.ts +0 -148
  215. package/src/channels/slack/approvals.test.ts +0 -328
  216. package/src/channels/slack/block-actions.test.ts +0 -469
  217. package/src/channels/slack/bot-mentions.test.ts +0 -267
  218. package/src/channels/slack/channel-watch.test.ts +0 -363
  219. package/src/channels/slack/cursor-account.test.ts +0 -301
  220. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  221. package/src/channels/slack/dispatch.test.ts +0 -875
  222. package/src/channels/slack/eval-directive.test.ts +0 -273
  223. package/src/channels/slack/message-body.test.ts +0 -54
  224. package/src/channels/slack/nudge-store.test.ts +0 -143
  225. package/src/channels/slack/slack.test.ts +0 -391
  226. package/src/channels/slack/stop.test.ts +0 -23
  227. package/src/channels/slack/thread-context.test.ts +0 -202
  228. package/src/evals/assertions.test.ts +0 -617
  229. package/src/evals/expect.test.ts +0 -144
  230. package/src/evals/judge.test.ts +0 -181
  231. package/src/evals/loaders.test.ts +0 -132
  232. package/src/evals/matchers.test.ts +0 -95
  233. package/src/evals/reporters.test.ts +0 -303
  234. package/src/evals/run-facts.test.ts +0 -259
  235. package/src/internal/ab-snapshot.test.ts +0 -325
  236. package/src/internal/approval-gate.test.ts +0 -49
  237. package/src/internal/approvals.integration.test.ts +0 -383
  238. package/src/internal/artifacts-store.test.ts +0 -283
  239. package/src/internal/authored-loaders.test.ts +0 -31
  240. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  241. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  242. package/src/internal/channel-route-schema.test.ts +0 -294
  243. package/src/internal/chat-attach.test.ts +0 -262
  244. package/src/internal/cli-deploy.test.ts +0 -1991
  245. package/src/internal/cli-docs.test.ts +0 -161
  246. package/src/internal/cli-mcp.test.ts +0 -789
  247. package/src/internal/cli-skills.test.ts +0 -133
  248. package/src/internal/cli-slack.test.ts +0 -1654
  249. package/src/internal/cloud-merge.test.ts +0 -74
  250. package/src/internal/cron.test.ts +0 -22
  251. package/src/internal/cursor/account-mcp.test.ts +0 -807
  252. package/src/internal/cursor/backend-client.test.ts +0 -591
  253. package/src/internal/cursor/credentials.test.ts +0 -351
  254. package/src/internal/cursor/github-credentials.test.ts +0 -136
  255. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  256. package/src/internal/cursor-account.integration.test.ts +0 -441
  257. package/src/internal/cursor-event-relay.test.ts +0 -746
  258. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  259. package/src/internal/cursor-slack-relay.test.ts +0 -525
  260. package/src/internal/deploy-source.test.ts +0 -111
  261. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  262. package/src/internal/discovery.artifacts.test.ts +0 -119
  263. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  264. package/src/internal/discovery.concurrency.test.ts +0 -60
  265. package/src/internal/discovery.cursor-account.test.ts +0 -133
  266. package/src/internal/discovery.cwd.test.ts +0 -83
  267. package/src/internal/discovery.hosting.test.ts +0 -80
  268. package/src/internal/discovery.identity.test.ts +0 -44
  269. package/src/internal/docs-site.test.ts +0 -66
  270. package/src/internal/duration.test.ts +0 -29
  271. package/src/internal/eval-judge-model.test.ts +0 -187
  272. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  273. package/src/internal/eval-run-store.storage.test.ts +0 -211
  274. package/src/internal/eval-runner.http.test.ts +0 -403
  275. package/src/internal/eval-runner.run.test.ts +0 -928
  276. package/src/internal/evals-client.test.ts +0 -307
  277. package/src/internal/event-mapper.test.ts +0 -243
  278. package/src/internal/github-fanout.test.ts +0 -213
  279. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  280. package/src/internal/host-kv.test.ts +0 -82
  281. package/src/internal/host-platforms.test.ts +0 -126
  282. package/src/internal/http-channel.test.ts +0 -402
  283. package/src/internal/init-project.test.ts +0 -270
  284. package/src/internal/install-cursor-skills.test.ts +0 -262
  285. package/src/internal/local-env.test.ts +0 -120
  286. package/src/internal/log-ring.test.ts +0 -31
  287. package/src/internal/logs-client.test.ts +0 -350
  288. package/src/internal/mcp-endpoint.test.ts +0 -436
  289. package/src/internal/mcp-host.test.ts +0 -298
  290. package/src/internal/mcp-oauth.test.ts +0 -148
  291. package/src/internal/net.test.ts +0 -17
  292. package/src/internal/peer-connections.test.ts +0 -128
  293. package/src/internal/peer-mcp.integration.test.ts +0 -289
  294. package/src/internal/playground/toolchain.test.ts +0 -53
  295. package/src/internal/playground-cli.test.ts +0 -187
  296. package/src/internal/playground-proxy.test.ts +0 -376
  297. package/src/internal/prompt-context.integration.test.ts +0 -232
  298. package/src/internal/prompt-context.test.ts +0 -127
  299. package/src/internal/reminder-runner.test.ts +0 -432
  300. package/src/internal/reminder-store.test.ts +0 -53
  301. package/src/internal/request-headers.test.ts +0 -27
  302. package/src/internal/resolve-prod-target.test.ts +0 -787
  303. package/src/internal/resolved-connections.test.ts +0 -295
  304. package/src/internal/router.test.ts +0 -57
  305. package/src/internal/sdk-runner.test.ts +0 -290
  306. package/src/internal/server.artifacts.test.ts +0 -334
  307. package/src/internal/session-engine.artifacts.test.ts +0 -293
  308. package/src/internal/session-engine.coalesce.test.ts +0 -169
  309. package/src/internal/session-engine.concurrency.test.ts +0 -250
  310. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  311. package/src/internal/session-engine.interrupt.test.ts +0 -577
  312. package/src/internal/session-engine.storage.test.ts +0 -547
  313. package/src/internal/session-urls.test.ts +0 -28
  314. package/src/internal/sessions-client.test.ts +0 -518
  315. package/src/internal/storage-coordinator.test.ts +0 -517
  316. package/src/internal/tool-call.test.ts +0 -458
  317. package/src/internal/tool-result.test.ts +0 -52
  318. package/src/internal/trajectory.approvals.test.ts +0 -83
  319. package/src/internal/trajectory.subagents.test.ts +0 -198
  320. package/src/internal/turn-governor.test.ts +0 -137
  321. package/src/internal/update-check.test.ts +0 -485
  322. package/src/internal/workspace.test.ts +0 -207
  323. package/src/storage-backends/cursor-hosted.test.ts +0 -121
  324. /package/dist/docs/assets/{index.md.Dfv5ic9t.lean.js → index.md.CH_s5uZe.lean.js} +0 -0
@@ -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
- });