@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,298 +0,0 @@
1
- import { createServer, type IncomingMessage, type Server } from "node:http";
2
- import { fileURLToPath } from "node:url";
3
- import { afterEach, describe, expect, it } from "vitest";
4
- import { isStaleMcpSessionError, McpHost } from "./mcp-host.js";
5
-
6
- const unitsServer = fileURLToPath(
7
- new URL("../../examples/weather-agent/mcp/units-server.ts", import.meta.url)
8
- );
9
-
10
- describe("isStaleMcpSessionError", () => {
11
- it("detects anytool session_terminated payloads and HTTP 404 codes", () => {
12
- expect(
13
- isStaleMcpSessionError(
14
- new Error(
15
- 'Streamable HTTP error: Error POSTing to endpoint: {"error":"session_terminated"}'
16
- )
17
- )
18
- ).toBe(true);
19
-
20
- const http404 = new Error(
21
- "Streamable HTTP error: Error POSTing to endpoint: gone"
22
- );
23
- (http404 as { code?: number }).code = 404;
24
- expect(isStaleMcpSessionError(http404)).toBe(true);
25
-
26
- expect(isStaleMcpSessionError(new Error("unauthorized"))).toBe(false);
27
- expect(isStaleMcpSessionError("session_terminated")).toBe(false);
28
- });
29
- });
30
-
31
- describe("McpHost", () => {
32
- const servers: Server[] = [];
33
- afterEach(async () => {
34
- await Promise.all(
35
- servers.splice(0).map(
36
- (server) =>
37
- new Promise<void>((resolve, reject) => {
38
- server.close((error) => (error ? reject(error) : resolve()));
39
- })
40
- )
41
- );
42
- });
43
-
44
- it("lists and calls tools on a stdio connection", async () => {
45
- const host = new McpHost([
46
- {
47
- name: "units",
48
- transport: {
49
- type: "stdio",
50
- command: "npx",
51
- args: ["-y", "tsx", unitsServer],
52
- },
53
- },
54
- ]);
55
- try {
56
- expect(host.names()).toEqual(["units"]);
57
- const tools = await host.listTools("units");
58
- expect(tools.map((tool) => tool.name).sort()).toEqual([
59
- "celsius_to_fahrenheit",
60
- "fahrenheit_to_celsius",
61
- ]);
62
-
63
- const result = await host.callTool("units", "celsius_to_fahrenheit", {
64
- value: 0,
65
- });
66
- expect(result.isError).toBeFalsy();
67
- const text = result.content.find(
68
- (part): part is { type: "text"; text: string } => part.type === "text"
69
- )?.text;
70
- expect(text).toBeDefined();
71
- expect(JSON.parse(text as string)).toEqual({
72
- celsius: 0,
73
- fahrenheit: 32,
74
- });
75
- } finally {
76
- await host.close();
77
- }
78
- }, 30_000);
79
-
80
- it("rejects unknown MCP connection names", async () => {
81
- const host = new McpHost([]);
82
- await expect(host.callTool("missing", "noop", {})).rejects.toThrow(
83
- /Unknown MCP connection "missing"/
84
- );
85
- await host.close();
86
- });
87
-
88
- it("reconnects after the remote Streamable HTTP session is terminated", async () => {
89
- const mock = await startTerminatingMcpMock();
90
- servers.push(mock.server);
91
-
92
- const host = new McpHost([
93
- {
94
- name: "anytool",
95
- transport: {
96
- type: "http",
97
- url: mock.url,
98
- },
99
- },
100
- ]);
101
- try {
102
- const first = await host.callTool("anytool", "ping", {});
103
- expect(first.isError).toBeFalsy();
104
- expect(mock.initializeCount).toBe(1);
105
-
106
- mock.terminateAllSessions();
107
-
108
- const second = await host.callTool("anytool", "ping", {});
109
- expect(second.isError).toBeFalsy();
110
- expect(mock.initializeCount).toBe(2);
111
- } finally {
112
- await host.close();
113
- }
114
- }, 30_000);
115
- });
116
-
117
- async function startTerminatingMcpMock(): Promise<{
118
- server: Server;
119
- url: string;
120
- initializeCount: number;
121
- terminateAllSessions: () => void;
122
- }> {
123
- const sessions = new Set<string>();
124
- const state = { initializeCount: 0 };
125
-
126
- const server = createServer((req, res) => {
127
- void handleMcpRequest(req, res, sessions, state);
128
- });
129
-
130
- await new Promise<void>((resolve, reject) => {
131
- server.once("error", reject);
132
- server.listen(0, "127.0.0.1", () => resolve());
133
- });
134
- const address = server.address();
135
- if (address === null || typeof address === "string") {
136
- throw new Error("expected TCP listen address");
137
- }
138
-
139
- return {
140
- server,
141
- url: `http://127.0.0.1:${address.port}/mcp`,
142
- get initializeCount() {
143
- return state.initializeCount;
144
- },
145
- terminateAllSessions() {
146
- sessions.clear();
147
- },
148
- };
149
- }
150
-
151
- async function handleMcpRequest(
152
- req: IncomingMessage,
153
- res: import("node:http").ServerResponse,
154
- sessions: Set<string>,
155
- state: { initializeCount: number }
156
- ): Promise<void> {
157
- if (req.method === "GET") {
158
- // Optional SSE stream; idle keep-alive is enough for the SDK.
159
- const sessionId = headerValue(req.headers["mcp-session-id"]);
160
- if (sessionId === undefined || !sessions.has(sessionId)) {
161
- res.writeHead(404, { "Content-Type": "application/json" });
162
- res.end(JSON.stringify({ error: "session_terminated" }));
163
- return;
164
- }
165
- res.writeHead(200, {
166
- "Content-Type": "text/event-stream",
167
- "Cache-Control": "no-cache",
168
- Connection: "keep-alive",
169
- "mcp-session-id": sessionId,
170
- });
171
- res.write(": connected\n\n");
172
- return;
173
- }
174
-
175
- if (req.method === "DELETE") {
176
- const sessionId = headerValue(req.headers["mcp-session-id"]);
177
- if (sessionId !== undefined) {
178
- sessions.delete(sessionId);
179
- }
180
- res.writeHead(200).end();
181
- return;
182
- }
183
-
184
- if (req.method !== "POST") {
185
- res.writeHead(405).end();
186
- return;
187
- }
188
-
189
- const body = await readJsonBody(req);
190
- const sessionId = headerValue(req.headers["mcp-session-id"]);
191
- const method =
192
- typeof body === "object" &&
193
- body !== null &&
194
- "method" in body &&
195
- typeof body.method === "string"
196
- ? body.method
197
- : undefined;
198
- const id =
199
- typeof body === "object" && body !== null && "id" in body
200
- ? body.id
201
- : undefined;
202
-
203
- if (method === "initialize") {
204
- state.initializeCount += 1;
205
- const nextSessionId = `session-${state.initializeCount}`;
206
- sessions.add(nextSessionId);
207
- writeSseJson(res, nextSessionId, {
208
- jsonrpc: "2.0",
209
- id,
210
- result: {
211
- protocolVersion: "2025-03-26",
212
- capabilities: { tools: {} },
213
- serverInfo: { name: "mock-anytool", version: "0.0.0" },
214
- },
215
- });
216
- return;
217
- }
218
-
219
- if (sessionId === undefined || !sessions.has(sessionId)) {
220
- res.writeHead(404, { "Content-Type": "application/json" });
221
- res.end(JSON.stringify({ error: "session_terminated" }));
222
- return;
223
- }
224
-
225
- if (method === undefined || id === undefined) {
226
- // notifications/initialized and similar
227
- res.writeHead(202).end();
228
- return;
229
- }
230
-
231
- if (method === "tools/list") {
232
- writeSseJson(res, sessionId, {
233
- jsonrpc: "2.0",
234
- id,
235
- result: {
236
- tools: [
237
- {
238
- name: "ping",
239
- description: "ping",
240
- inputSchema: { type: "object", properties: {} },
241
- },
242
- ],
243
- },
244
- });
245
- return;
246
- }
247
-
248
- if (method === "tools/call") {
249
- writeSseJson(res, sessionId, {
250
- jsonrpc: "2.0",
251
- id,
252
- result: {
253
- content: [{ type: "text", text: "pong" }],
254
- },
255
- });
256
- return;
257
- }
258
-
259
- writeSseJson(res, sessionId, {
260
- jsonrpc: "2.0",
261
- id,
262
- error: { code: -32601, message: `Method not found: ${method}` },
263
- });
264
- }
265
-
266
- function writeSseJson(
267
- res: import("node:http").ServerResponse,
268
- sessionId: string,
269
- payload: unknown
270
- ): void {
271
- res.writeHead(200, {
272
- "Content-Type": "text/event-stream",
273
- "Cache-Control": "no-cache",
274
- "mcp-session-id": sessionId,
275
- });
276
- res.end(`event: message\ndata: ${JSON.stringify(payload)}\n\n`);
277
- }
278
-
279
- function headerValue(value: string | string[] | undefined): string | undefined {
280
- if (typeof value === "string") {
281
- return value;
282
- }
283
- if (Array.isArray(value) && value.length > 0) {
284
- return value[0];
285
- }
286
- return undefined;
287
- }
288
-
289
- async function readJsonBody(req: IncomingMessage): Promise<unknown> {
290
- const chunks: Buffer[] = [];
291
- for await (const chunk of req) {
292
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
293
- }
294
- if (chunks.length === 0) {
295
- return undefined;
296
- }
297
- return JSON.parse(Buffer.concat(chunks).toString("utf8")) as unknown;
298
- }
@@ -1,148 +0,0 @@
1
- import { mkdtemp, readFile, writeFile } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { describe, expect, it } from "vitest";
5
- import {
6
- createHostMcpOAuthProvider,
7
- FileMcpOAuthStore,
8
- HostMcpOAuthProvider,
9
- mcpOauthSecretNames,
10
- normalizeMcpResourceUrl,
11
- openBrowser,
12
- tokensFromEnv,
13
- } from "./mcp-oauth.js";
14
-
15
- const ANYTOOL_URL = "https://anytool.example/mcp";
16
-
17
- describe("FileMcpOAuthStore", () => {
18
- it("persists tokens and client info bound to resource URL", async () => {
19
- const dir = await mkdtemp(join(tmpdir(), "agentkit-mcp-oauth-"));
20
- const path = join(dir, "mcp-auth.json");
21
- const store = new FileMcpOAuthStore(path);
22
-
23
- await store.saveTokens("anytool", ANYTOOL_URL, {
24
- access_token: "access-1",
25
- refresh_token: "refresh-1",
26
- token_type: "Bearer",
27
- });
28
- await store.saveClientInformation("anytool", ANYTOOL_URL, {
29
- client_id: "client-1",
30
- redirect_uris: ["http://localhost:8787/callback"],
31
- });
32
-
33
- const reloaded = new FileMcpOAuthStore(path);
34
- expect(await reloaded.loadTokens("anytool", ANYTOOL_URL)).toMatchObject({
35
- access_token: "access-1",
36
- refresh_token: "refresh-1",
37
- });
38
- expect(
39
- await reloaded.loadClientInformation("anytool", ANYTOOL_URL)
40
- ).toMatchObject({
41
- client_id: "client-1",
42
- });
43
-
44
- const raw = JSON.parse(await readFile(path, "utf8")) as {
45
- anytool: { resourceUrl: string; tokens: { refresh_token: string } };
46
- };
47
- expect(raw.anytool.resourceUrl).toBe(normalizeMcpResourceUrl(ANYTOOL_URL));
48
- expect(raw.anytool.tokens.refresh_token).toBe("refresh-1");
49
- });
50
-
51
- it("ignores tokens when connection URL changes", async () => {
52
- const dir = await mkdtemp(join(tmpdir(), "agentkit-mcp-oauth-"));
53
- const store = new FileMcpOAuthStore(join(dir, "mcp-auth.json"));
54
- await store.saveTokens("anytool", ANYTOOL_URL, {
55
- access_token: "access-1",
56
- token_type: "Bearer",
57
- });
58
- expect(
59
- await store.loadTokens("anytool", "https://evil.example/mcp")
60
- ).toBeUndefined();
61
- expect(await store.loadTokens("anytool", ANYTOOL_URL)).toMatchObject({
62
- access_token: "access-1",
63
- });
64
- });
65
-
66
- it("ignores legacy entries without resourceUrl", async () => {
67
- const dir = await mkdtemp(join(tmpdir(), "agentkit-mcp-oauth-"));
68
- const path = join(dir, "mcp-auth.json");
69
- await writeFile(
70
- path,
71
- JSON.stringify({
72
- anytool: {
73
- tokens: { access_token: "legacy", token_type: "Bearer" },
74
- },
75
- })
76
- );
77
- const store = new FileMcpOAuthStore(path);
78
- expect(await store.loadTokens("anytool", ANYTOOL_URL)).toBeUndefined();
79
- });
80
- });
81
-
82
- describe("HostMcpOAuthProvider", () => {
83
- it("writes token updates back through the store", async () => {
84
- const dir = await mkdtemp(join(tmpdir(), "agentkit-mcp-oauth-"));
85
- const store = new FileMcpOAuthStore(join(dir, "mcp-auth.json"));
86
- const provider = await createHostMcpOAuthProvider({
87
- identifier: "anytool",
88
- resourceUrl: ANYTOOL_URL,
89
- store,
90
- });
91
-
92
- await provider.saveTokens({
93
- access_token: "access-2",
94
- refresh_token: "refresh-2",
95
- token_type: "Bearer",
96
- });
97
- expect(provider.tokens()?.refresh_token).toBe("refresh-2");
98
- expect(
99
- (await store.loadTokens("anytool", ANYTOOL_URL))?.refresh_token
100
- ).toBe("refresh-2");
101
- });
102
-
103
- it("records redirect URLs for the login CLI", () => {
104
- const redirects: string[] = [];
105
- const provider = new HostMcpOAuthProvider({
106
- identifier: "anytool",
107
- resourceUrl: ANYTOOL_URL,
108
- store: new FileMcpOAuthStore(join(tmpdir(), "unused.json")),
109
- onRedirect: (url) => redirects.push(url.toString()),
110
- });
111
- provider.redirectToAuthorization(
112
- new URL("https://anytool.example/oauth/authorize?x=1")
113
- );
114
- expect(provider.lastRedirectUrl?.toString()).toContain(
115
- "anytool.example/oauth/authorize"
116
- );
117
- expect(redirects).toHaveLength(1);
118
- });
119
- });
120
-
121
- describe("openBrowser", () => {
122
- it("refuses non-http(s) URLs", () => {
123
- expect(() => openBrowser("file:///etc/passwd")).toThrow(/non-http/);
124
- });
125
- });
126
-
127
- describe("mcp oauth deployment secrets", () => {
128
- it("names secrets from the connection id", () => {
129
- expect(mcpOauthSecretNames("anytool")).toEqual({
130
- accessToken: "MCP_OAUTH_ANYTOOL_ACCESS_TOKEN",
131
- refreshToken: "MCP_OAUTH_ANYTOOL_REFRESH_TOKEN",
132
- clientId: "MCP_OAUTH_ANYTOOL_CLIENT_ID",
133
- });
134
- });
135
-
136
- it("reads bearer tokens from env when local file is empty", () => {
137
- const names = mcpOauthSecretNames("anytool");
138
- expect(
139
- tokensFromEnv("anytool", {
140
- [names.accessToken]: "access-env",
141
- [names.refreshToken]: "refresh-env",
142
- })
143
- ).toMatchObject({
144
- access_token: "access-env",
145
- refresh_token: "refresh-env",
146
- });
147
- });
148
- });
@@ -1,17 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { isLoopbackHostname } from "./net.js";
3
-
4
- describe("isLoopbackHostname", () => {
5
- it("accepts localhost and loopback literals", () => {
6
- expect(isLoopbackHostname("localhost")).toBe(true);
7
- expect(isLoopbackHostname("127.0.0.1")).toBe(true);
8
- expect(isLoopbackHostname("::1")).toBe(true);
9
- });
10
-
11
- it("rejects remote hostnames used in DNS rebinding", () => {
12
- expect(isLoopbackHostname("attacker.example")).toBe(false);
13
- expect(isLoopbackHostname("localhost.evil.example")).toBe(false);
14
- expect(isLoopbackHostname("127.0.0.1.nip.io")).toBe(false);
15
- expect(isLoopbackHostname("127.0.0.1.attacker.example")).toBe(false);
16
- });
17
- });
@@ -1,128 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { httpChannel } from "../channels.js";
3
- import type { AgentProject, ConnectionTransport } from "../types.js";
4
- import {
5
- collectPeerConnections,
6
- resolvePeerConnections,
7
- } from "./peer-connections.js";
8
-
9
- function makeProject(
10
- name: string,
11
- connections: Array<{ name: string; transport: ConnectionTransport }> = []
12
- ): AgentProject {
13
- return {
14
- rootDir: `/tmp/${name}`,
15
- agentDir: `/tmp/${name}/agent`,
16
- name,
17
- agent: {
18
- name,
19
- runtime: "local",
20
- tools: [],
21
- skills: [],
22
- connections,
23
- subagents: [],
24
- seedFiles: [],
25
- },
26
- httpChannel: httpChannel(),
27
- channels: [],
28
- schedules: [],
29
- hooks: [],
30
- abs: [],
31
- diagnostics: [],
32
- };
33
- }
34
-
35
- describe("collectPeerConnections", () => {
36
- it("groups validated refs by the referencing mount slug", () => {
37
- const mounts = [
38
- {
39
- slug: "concierge",
40
- project: makeProject("concierge", [
41
- { name: "weather", transport: { agent: "weather-agent" } },
42
- { name: "linear", transport: { url: "https://mcp.linear.app/mcp" } },
43
- ]),
44
- },
45
- { slug: "weather-agent", project: makeProject("weather-agent") },
46
- ];
47
- const refs = collectPeerConnections(mounts);
48
- expect([...refs.keys()]).toEqual(["concierge"]);
49
- expect(refs.get("concierge")).toEqual([
50
- { name: "weather", targetSlug: "weather-agent" },
51
- ]);
52
- });
53
-
54
- it("throws on unknown peer slugs, listing the mounted agents", () => {
55
- const mounts = [
56
- {
57
- slug: "concierge",
58
- project: makeProject("concierge", [
59
- { name: "weather", transport: { agent: "nope" } },
60
- ]),
61
- },
62
- { slug: "weather-agent", project: makeProject("weather-agent") },
63
- ];
64
- expect(() => collectPeerConnections(mounts)).toThrow(
65
- /unknown peer agent "nope".*weather-agent/
66
- );
67
- });
68
-
69
- it("throws on self-references", () => {
70
- const mounts = [
71
- {
72
- slug: "concierge",
73
- project: makeProject("concierge", [
74
- { name: "me", transport: { agent: "concierge" } },
75
- ]),
76
- },
77
- ];
78
- expect(() => collectPeerConnections(mounts)).toThrow(/references itself/);
79
- });
80
-
81
- it("rejects peers in single-agent mode (empty slug set)", () => {
82
- const mounts = [
83
- {
84
- slug: "",
85
- project: makeProject("solo", [
86
- { name: "weather", transport: { agent: "weather-agent" } },
87
- ]),
88
- },
89
- ];
90
- expect(() => collectPeerConnections(mounts)).toThrow(
91
- /Mounted agents: \(none\)/
92
- );
93
- });
94
- });
95
-
96
- describe("resolvePeerConnections", () => {
97
- const refs = [{ name: "weather", targetSlug: "weather-agent" }];
98
-
99
- it("resolves loopback URLs and omits cloudUrl without a publicUrl", () => {
100
- const peers = resolvePeerConnections({
101
- refs,
102
- serverUrl: "http://127.0.0.1:4123",
103
- });
104
- expect(peers).toEqual([
105
- {
106
- name: "weather",
107
- localUrl: "http://127.0.0.1:4123/weather-agent/v1/mcp",
108
- },
109
- ]);
110
- });
111
-
112
- it("resolves cloudUrl from publicUrl and attaches the bearer token", () => {
113
- const peers = resolvePeerConnections({
114
- refs,
115
- serverUrl: "http://127.0.0.1:4123/",
116
- publicUrl: "https://agents.example.com/",
117
- authToken: "sekret",
118
- });
119
- expect(peers).toEqual([
120
- {
121
- name: "weather",
122
- localUrl: "http://127.0.0.1:4123/weather-agent/v1/mcp",
123
- cloudUrl: "https://agents.example.com/weather-agent/v1/mcp",
124
- headers: { authorization: "Bearer sekret" },
125
- },
126
- ]);
127
- });
128
- });