@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
package/dist/mcp-probe.js CHANGED
@@ -107,6 +107,38 @@ export function pricesOf(value, issues) {
107
107
  // Keyed by tool names, which may be an object's own properties (`__proto__`): no prototype to fall into.
108
108
  return bad.length ? undefined : Object.assign(Object.create(null), value);
109
109
  }
110
+ /** Query parameter names that look like a credential, compared lowercase with every "-" and "_" gone: an MCP server's url
111
+ * is kept and shown in plain text (its row's url, every read, the console), so a credential belongs in a header. Only
112
+ * names that say they hold one: a bare `key`, `session` or `sessionid` names a server's own lookup or routing value as
113
+ * often (?key=docs, ?session=eu-1), so those stay the server's. */
114
+ export const CREDENTIAL_QUERY_NAMES = [
115
+ "token", "accesstoken", "authtoken", "idtoken", "refreshtoken", "sessiontoken", "bearer", "jwt",
116
+ "apikey", "xapikey", "accesskey", "secretkey", "privatekey",
117
+ "secret", "clientsecret", "auth", "authorization", "credential", "credentials",
118
+ "password", "passwd", "pass", "pwd", "sig", "signature",
119
+ ];
120
+ const credentialQueryName = (name) => CREDENTIAL_QUERY_NAMES.includes(name.toLowerCase().replace(/[-_]/g, ""));
121
+ /** The first query parameter of `url` whose name looks like a credential, if any: a saved row's URL is held to it at each
122
+ * use (the server's preview, refresh and sign-in, the runner's claim) as a new one is at its save. */
123
+ export function credentialInQuery(url) {
124
+ const parsed = typeof url === "string" ? URL.parse(url) : url;
125
+ return parsed ? [...parsed.searchParams.keys()].find(credentialQueryName) : undefined;
126
+ }
127
+ /** An MCP server's URL as every read shows it: its origin, and "/…" for a path or query, which is held as a secret (a
128
+ * provider may put a key in either: Zapier's /mcp/<key>/sse, a ?token= no list names). The whole URL is used only to call
129
+ * the server. A body that sends this back unchanged for a saved server means its saved URL (savedOrGiven). */
130
+ export function shownUrl(url) {
131
+ const parsed = URL.parse(url);
132
+ if (!parsed)
133
+ return "(not a URL)";
134
+ return `${parsed.origin}/${parsed.pathname !== "/" || parsed.search ? "…" : ""}`;
135
+ }
136
+ /** A body's URL for saved server `saved`: its saved URL when the body sent back the shown one (shownUrl), else as given. */
137
+ export function savedOrGiven(given, saved) {
138
+ return saved !== undefined && typeof given === "string" && given === shownUrl(saved) ? saved : given;
139
+ }
140
+ /** What a URL with a credential in its query says, wherever it is refused. */
141
+ export const credentialInQueryWords = (name) => `${name} in the URL's query looks like a credential; send it as a header instead (Headers).`;
110
142
  export function urlOf(value, issues) {
111
143
  if (typeof value !== "string" || value === "")
112
144
  return void issues.push({ field: "url", reason: value === undefined ? "missing" : "wrong_type", message: "url is the MCP server's Streamable HTTP endpoint, as text." });
@@ -121,6 +153,8 @@ export function urlOf(value, issues) {
121
153
  issues.push({ field: "url", reason: "too_long", message: `url is at most ${MAX_URL} characters.` });
122
154
  else if (url.username || url.password)
123
155
  issues.push({ field: "url", reason: "invalid", message: "url holds a user or password: send a credential as auth instead." });
156
+ else if (credentialInQuery(url))
157
+ issues.push({ field: "url", reason: "invalid", message: credentialInQueryWords(credentialInQuery(url)) });
124
158
  else if (url.protocol === "http:" && !LOOPBACK(url.hostname))
125
159
  issues.push({ field: "url", reason: "not_https", message: `url is http://${url.host}, which is not this machine's loopback: use https, or http only on loopback.` });
126
160
  else if (url.protocol !== "https:" && url.protocol !== "http:")
@@ -230,15 +264,16 @@ export const MAX_OAUTH_VALUE_BYTES = MAX_VALUE_BYTES;
230
264
  export const oauthValueValid = (text) => typeof text === "string" && text !== "" && !CONTROL.test(text) && Buffer.byteLength(text) <= MAX_VALUE_BYTES;
231
265
  /** Connect to `url`, agree a protocol revision, and list every tool (all pages), each request held to REQUEST_MS and
232
266
  * MAX_RESPONSE_BYTES and the whole to PREVIEW_MS. A failure is an ApiError: 422 auth_required (with the auth the
233
- * server asks for), 422 not_mcp, 422 input_invalid for a redirect, else 424 upstream_failed. */
234
- export async function listServer(url, headers, version, stop) {
267
+ * server asks for), 422 not_mcp, 422 input_invalid for a redirect, else 424 upstream_failed. `send`: how each request
268
+ * goes, the store-backed registry's dialled at the address its check let through (mcp-oauth.ts mcpServerAt, dialAt). */
269
+ export async function listServer(url, headers, version, stop, send = fetch) {
235
270
  const sdk = await import("@modelcontextprotocol/client");
236
271
  const deadline = AbortSignal.any([AbortSignal.timeout(PREVIEW_MS), ...(stop ? [stop] : [])]);
237
272
  const seen = [];
238
273
  let overflow = false;
239
274
  const watched = async (input, init) => {
240
275
  const signal = AbortSignal.any([deadline, AbortSignal.timeout(REQUEST_MS), ...(init?.signal ? [init.signal] : [])]);
241
- const res = await fetch(input, { ...init, redirect: "manual", signal });
276
+ const res = await send(input, { ...init, redirect: "manual", signal });
242
277
  const type = res.headers.get("content-type") ?? "";
243
278
  seen.push({ status: res.status, headers: res.headers, rpc: type.startsWith("text/event-stream") ? Promise.resolve(true) : type.includes("json") ? speaksJsonRpc(res.clone()) : Promise.resolve(false) });
244
279
  return capped(res, () => (overflow = true));
@@ -288,13 +323,13 @@ export async function listServer(url, headers, version, stop) {
288
323
  catch (error) {
289
324
  if (error instanceof ApiError)
290
325
  throw error;
291
- throw await refusal(error, seen, overflow, url, headers, deadline, sdk);
326
+ throw await refusal(error, seen, overflow, url, headers, deadline, sdk, send);
292
327
  }
293
328
  finally {
294
329
  await client.close().catch(() => { });
295
330
  }
296
331
  }
297
- async function refusal(error, seen, overflow, url, headers, deadline, sdk) {
332
+ async function refusal(error, seen, overflow, url, headers, deadline, sdk, send) {
298
333
  const upstream = (message, status) => new ApiError("upstream_failed", message, status ? { details: { status } } : {});
299
334
  if (overflow)
300
335
  return upstream(`The MCP server answered more than ${MAX_RESPONSE_BYTES / 2 ** 20} MiB in one response.`);
@@ -311,7 +346,7 @@ async function refusal(error, seen, overflow, url, headers, deadline, sdk) {
311
346
  }
312
347
  const denied = seen.find((one) => one.status === 401 || one.status === 403);
313
348
  if (denied) {
314
- const auth = await authAsked(url, denied.headers, deadline, sdk);
349
+ const auth = await authAsked(url, denied.headers, deadline, sdk, send);
315
350
  const sent = Object.keys(headers).length > 0;
316
351
  const asks = auth === "oauth" ? `It signs in with OAuth: ${sent ? `${SIGN_IN_AGAIN}, or ` : ""}sign in with POST /v2/settings/mcp-servers/{name}/oauth/start and its url.` : "Send a bearer token or the headers it takes.";
317
352
  return new ApiError("auth_required", `The MCP server ${sent ? "refused the credential sent" : "asks for a credential"} (HTTP ${denied.status}). ${asks}`, { details: { auth, status: denied.status } });
@@ -325,7 +360,7 @@ async function refusal(error, seen, overflow, url, headers, deadline, sdk) {
325
360
  return upstream(`Could not reach the MCP server at ${url.origin}${causeCode(error) ? ` (${causeCode(error)})` : ""}.`);
326
361
  }
327
362
  if (!(await Promise.all(seen.map((one) => one.rpc))).some(Boolean))
328
- return new ApiError("not_mcp", `${url.href} does not speak MCP over Streamable HTTP: it answered HTTP ${seen.at(-1).status} with no JSON-RPC reply.`);
363
+ return new ApiError("not_mcp", `${shownUrl(url.href)} does not speak MCP over Streamable HTTP: it answered HTTP ${seen.at(-1).status} with no JSON-RPC reply.`);
329
364
  // The listing's own limit when it was the one that ran out, else one request's.
330
365
  if (deadline.aborted || timedOut(error))
331
366
  return upstream(deadline.aborted ? `The MCP server did not finish listing its tools within ${PREVIEW_MS / 1000} s.` : `The MCP server did not answer a request within ${REQUEST_MS / 1000} s.`);
@@ -335,11 +370,11 @@ async function refusal(error, seen, overflow, url, headers, deadline, sdk) {
335
370
  }
336
371
  /** What a 401 or 403 asks for: `oauth` when the server names protected-resource metadata (its WWW-Authenticate, or a
337
372
  * well-known document naming an authorization server), else `bearer`. The probe sends no credential. */
338
- async function authAsked(url, headers, deadline, sdk) {
373
+ async function authAsked(url, headers, deadline, sdk, send) {
339
374
  if (sdk.extractWWWAuthenticateParams(new Response(null, { headers })).resourceMetadataUrl)
340
375
  return "oauth";
341
376
  try {
342
- const probe = async (input, init) => capped(await fetch(input, { ...init, redirect: "manual", signal: AbortSignal.any([deadline, AbortSignal.timeout(5_000)]) }), () => { });
377
+ const probe = async (input, init) => capped(await send(input, { ...init, redirect: "manual", signal: AbortSignal.any([deadline, AbortSignal.timeout(5_000)]) }), () => { });
343
378
  const metadata = await sdk.discoverOAuthProtectedResourceMetadata(url, undefined, probe);
344
379
  return metadata.authorization_servers?.length ? "oauth" : "bearer";
345
380
  }
@@ -61,4 +61,8 @@ for (const operation of MCP_SECRET_OPERATIONS)
61
61
  // A preview keeps nothing, so it is never a secret write; its body's fields are marked secret in the document, so it is
62
62
  // registered all the same.
63
63
  registerSecretWrite("previewMcpServer", () => false);
64
+ // The Composio preset takes the owner's API key and seals it as an MCP header: both routes are the owner's session alone,
65
+ // whatever the body (the listing sends the key too, and only the session may type one).
66
+ registerSecretWrite("listComposioTools", () => true);
67
+ registerSecretWrite("saveComposioServer", () => true);
64
68
  registerNotSecretWrite("refreshMcpServer", "A refresh lists the saved server's tools again with its sealed credential, and writes no credential.");
@@ -13,6 +13,7 @@ type McpServersStore = {
13
13
  export declare class McpServersOverStore {
14
14
  private readonly store;
15
15
  private readonly version;
16
+ private readonly network;
16
17
  /** The connected GitHub App's installation token for listing a `github_app` server's tools as it is previewed, saved
17
18
  * or refreshed (github-connection.ts tokenForListing); a run's own is minted at its claim (runner/mcp-claim.ts). Set by
18
19
  * the server; absent, such a server's tools can't be listed (github_not_connected). */
@@ -31,9 +32,14 @@ export declare class McpServersOverStore {
31
32
  /** The callbacks under way, which close() waits out before the server lets its data go. */
32
33
  private readonly inflight;
33
34
  private readonly stopped;
35
+ /** Whether this server is a local install (attach): only then may an MCP server's URL be on loopback. */
36
+ private loopback;
34
37
  constructor(store: McpServersStore, env: NodeJS.ProcessEnv, version: string, network?: OAuthNetwork);
35
- /** This server's address as a browser reaches it and where it listens. */
36
- attach(base: string, listening: string): void;
38
+ /** This server's address as a browser reaches it and where it listens (McpServers.attach). `local`: whether its
39
+ * operator said this is a local install (ServeOptions.mcpLoopback, the CLI's AGENTRUN_MCP_ALLOW_LOOPBACK=1), the one kind
40
+ * of server an MCP server's URL may be on loopback for. Never inferred from where it listens: a hosted container
41
+ * listens on loopback behind its proxy too. Omitted, or never attached, it is not one. */
42
+ attach(base: string, listening: string, local?: boolean): void;
37
43
  clientDocument(): {
38
44
  redirect_uris: string[];
39
45
  token_endpoint_auth_method?: string | undefined;
@@ -86,9 +92,9 @@ export declare class McpServersOverStore {
86
92
  credential: "unreadable" | "sealed" | "expired" | null;
87
93
  not_metered?: string[] | undefined;
88
94
  tools: {
89
- permission: "deny" | "allow" | "ask";
90
- default_permission: "deny" | "allow" | "ask";
91
- permissions: ("deny" | "allow" | "ask")[];
95
+ permission: "deny" | "ask" | "allow";
96
+ default_permission: "deny" | "ask" | "allow";
97
+ permissions: ("deny" | "ask" | "allow")[];
92
98
  name: string;
93
99
  title?: string;
94
100
  description?: string;
@@ -121,9 +127,9 @@ export declare class McpServersOverStore {
121
127
  credential: "unreadable" | "sealed" | "expired" | null;
122
128
  not_metered?: string[] | undefined;
123
129
  tools: {
124
- permission: "deny" | "allow" | "ask";
125
- default_permission: "deny" | "allow" | "ask";
126
- permissions: ("deny" | "allow" | "ask")[];
130
+ permission: "deny" | "ask" | "allow";
131
+ default_permission: "deny" | "ask" | "allow";
132
+ permissions: ("deny" | "ask" | "allow")[];
127
133
  name: string;
128
134
  title?: string;
129
135
  description?: string;
@@ -140,6 +146,10 @@ export declare class McpServersOverStore {
140
146
  }>;
141
147
  /** POST preview: `{url, auth}`, or `{name}` for a saved server with its sealed credential. Stores nothing. */
142
148
  preview(body: Record<string, unknown>, stop?: AbortSignal): Promise<Listed>;
149
+ /** `listing`, and when it is refused as a server that signs in with OAuth (auth_required, `auth: oauth`), whether that
150
+ * sign-in can start with no Client ID entered (`details.oauth.registration`, McpSignIns.registration), so the console
151
+ * asks for one up front. `stop`: the preview's, which cuts that discovery too. */
152
+ private signInNoted;
143
153
  /** PUT: preview, then keep the server with the tools listed. A body with no credential keeps the sealed one, while the
144
154
  * auth type and the URL's origin stay the same. */
145
155
  save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark): Promise<{
@@ -159,9 +169,9 @@ export declare class McpServersOverStore {
159
169
  credential: "unreadable" | "sealed" | "expired" | null;
160
170
  not_metered?: string[] | undefined;
161
171
  tools: {
162
- permission: "deny" | "allow" | "ask";
163
- default_permission: "deny" | "allow" | "ask";
164
- permissions: ("deny" | "allow" | "ask")[];
172
+ permission: "deny" | "ask" | "allow";
173
+ default_permission: "deny" | "ask" | "allow";
174
+ permissions: ("deny" | "ask" | "allow")[];
165
175
  name: string;
166
176
  title?: string;
167
177
  description?: string;
@@ -198,9 +208,9 @@ export declare class McpServersOverStore {
198
208
  credential: "unreadable" | "sealed" | "expired" | null;
199
209
  not_metered?: string[] | undefined;
200
210
  tools: {
201
- permission: "deny" | "allow" | "ask";
202
- default_permission: "deny" | "allow" | "ask";
203
- permissions: ("deny" | "allow" | "ask")[];
211
+ permission: "deny" | "ask" | "allow";
212
+ default_permission: "deny" | "ask" | "allow";
213
+ permissions: ("deny" | "ask" | "allow")[];
204
214
  name: string;
205
215
  title?: string;
206
216
  description?: string;
@@ -222,7 +232,9 @@ export declare class McpServersOverStore {
222
232
  private rewriteKeeping;
223
233
  /** DELETE. `checkedAgainst`: the credential the secret-write gate let a token's removal through against (one with
224
234
  * none: removing it drops no secret); the row goes only while it is still that, in the store's one statement, so a
225
- * credential saved meanwhile is never dropped by it. */
235
+ * credential saved meanwhile is never dropped by it. An OAuth one's sign-in is then let go at its authorization server
236
+ * (its refresh token revoked, RFC 7009, where its metadata names a revocation_endpoint), behind the answer: best effort,
237
+ * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check). */
226
238
  remove(name: string, checkedAgainst?: McpCredentialMark): Promise<void>;
227
239
  /** POST .../{name}/oauth/start: `{url, scopes?, client_id?, client_secret?}`; answers the URL the owner opens. */
228
240
  oauthStart(name: string, body: Record<string, unknown>): Promise<{
@@ -233,6 +245,13 @@ export declare class McpServersOverStore {
233
245
  oauthCallback(query: URLSearchParams, stop?: AbortSignal): Promise<string>;
234
246
  private callback;
235
247
  private listServer;
248
+ /** How a request to the MCP server at `url` goes, or a 422 on url before anything is sent to it (or a token minted for
249
+ * it): a github_app server anywhere but GitHub's hosted MCP (GITHUB_MCP_ONLY, as withAppToken says), and at it, as it
250
+ * is, since that one origin is this server's to name, never the owner's; any other server held to the address rule
251
+ * (mcp-oauth.ts mcpServerAt, the one an authorization server's endpoint is held to), with the private-network hosts the
252
+ * owner allows read now, loopback only for a local install. The fetch it answers dials the address checked. A name
253
+ * that does not resolve is the unreachable server it always was (424). */
254
+ private reached;
236
255
  private need;
237
256
  /** The saved credential opened, or the refusal that asks for it again. */
238
257
  private opened;
@@ -245,6 +264,10 @@ export declare class McpServersOverStore {
245
264
  * is checked first (githubMcpUrl), so a row saved at another address never gets a token minted or sent. */
246
265
  private withAppToken;
247
266
  }
267
+ /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
268
+ export declare const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
269
+ /** What a URL on loopback says on a server that is not one, with how to make it one. */
270
+ export declare const loopbackWords: (host: string) => string;
248
271
  /** The owner's MCP registry over the one store. No load() is needed: every read goes to the store (the runner also writes
249
272
  * the OAuth state), so a read is always current. */
250
273
  export declare function mcpServersOverStore(store: McpServersStore, env: NodeJS.ProcessEnv, version: string, network?: OAuthNetwork): McpServersOverStore;
@@ -8,13 +8,13 @@
8
8
  // and does NO token refresh: it is the owner's create/preview/save/refresh(tools)/remove and the OAuth sign-in, and nothing
9
9
  // a run's launch calls.
10
10
  import { ApiError, invalid } from "./errors.js";
11
- import { authOf, canonical, credentialMissing, listServer, marked, MAX_OAUTH_VALUE_BYTES, nameOf, notFound, oauthValueValid, pricesListed, pricesOf, scopesValid, urlOf, } from "./mcp-probe.js";
11
+ import { authOf, canonical, credentialInQuery, credentialInQueryWords, credentialMissing, savedOrGiven, shownUrl, listServer, marked, MAX_OAUTH_VALUE_BYTES, nameOf, notFound, oauthValueValid, pricesListed, pricesOf, scopesValid, urlOf, } from "./mcp-probe.js";
12
12
  import { listMcpServers, openServerCredential, putPendingSignIn, removeMcpServer, removeMcpServerIfCredential, rewriteMcpServer, saveMcpServerIfCredential, takePendingSignIn } from "./mcp-store.js";
13
13
  import { checkPrivateHosts, privateOAuthHosts, savePrivateOAuthHosts } from "./mcp-private-hosts.js";
14
14
  // MCP's secret writes, registered with the one gate as the registry loads (the server's dispatch reads them).
15
15
  import { credentialMark } from "./mcp-secret-writes.js";
16
16
  import { secretMeta, secretName } from "./secret-writes.js";
17
- import { issuerOf, MAX_PENDING, MCP_SETTINGS_PAGE, McpSignIns, reasonOf, SIGN_IN_AGAIN, systemNetwork } from "./mcp-oauth.js";
17
+ import { dialAt, issuerOf, LOOPBACK, MAX_PENDING, MCP_SETTINGS_PAGE, mcpServerAt, McpSignIns, reasonOf, SIGN_IN_AGAIN, systemNetwork } from "./mcp-oauth.js";
18
18
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
19
19
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "./github.js";
20
20
  import { serverGate } from "./tool-plane.js";
@@ -23,6 +23,8 @@ import { unknownFields } from "./validate.js";
23
23
  * each re-applied onto the row read again, before it is refused in words. */
24
24
  const REWRITE_TRIES = 3;
25
25
  const SCOPE_LIST = "scopes is a list of 1 to 32 OAuth scopes.";
26
+ /** The longest an MCP server's address check (its name's lookup) may take before a door answers. */
27
+ const ADDRESS_CHECK_MS = 15_000;
26
28
  const MAX_VALUE_BYTES = MAX_OAUTH_VALUE_BYTES;
27
29
  /** The row a conditional save wrote, or the refusal when it wrote nothing: the server's credential changed while the save
28
30
  * listed its tools (another save, a sign-in or a removal landed), and writing would drop or undo it. */
@@ -71,6 +73,7 @@ function pendingOverStore(store, sealKey) {
71
73
  export class McpServersOverStore {
72
74
  store;
73
75
  version;
76
+ network;
74
77
  /** The connected GitHub App's installation token for listing a `github_app` server's tools as it is previewed, saved
75
78
  * or refreshed (github-connection.ts tokenForListing); a run's own is minted at its claim (runner/mcp-claim.ts). Set by
76
79
  * the server; absent, such a server's tools can't be listed (github_not_connected). */
@@ -83,9 +86,12 @@ export class McpServersOverStore {
83
86
  /** The callbacks under way, which close() waits out before the server lets its data go. */
84
87
  inflight = new Set();
85
88
  stopped = new AbortController();
89
+ /** Whether this server is a local install (attach): only then may an MCP server's URL be on loopback. */
90
+ loopback = false;
86
91
  constructor(store, env, version, network = systemNetwork) {
87
92
  this.store = store;
88
93
  this.version = version;
94
+ this.network = network;
89
95
  // The server never starts without a seal key (seal-key.ts bootSealKey), so there is no keyless registry: every
90
96
  // credential is kept sealed under it.
91
97
  const sealKey = sealKeyOf(env[SEAL_KEY_ENV]);
@@ -94,10 +100,15 @@ export class McpServersOverStore {
94
100
  this.sealKey = sealKey;
95
101
  this.signIns = new McpSignIns(network, pendingOverStore(store, sealKey), () => privateOAuthHosts(store));
96
102
  }
97
- /** This server's address as a browser reaches it and where it listens. */
98
- attach(base, listening) {
103
+ /** This server's address as a browser reaches it and where it listens (McpServers.attach). `local`: whether its
104
+ * operator said this is a local install (ServeOptions.mcpLoopback, the CLI's AGENTRUN_MCP_ALLOW_LOOPBACK=1), the one kind
105
+ * of server an MCP server's URL may be on loopback for. Never inferred from where it listens: a hosted container
106
+ * listens on loopback behind its proxy too. Omitted, or never attached, it is not one. */
107
+ attach(base, listening, local) {
99
108
  this.signIns.base = base.replace(/\/+$/, "");
100
109
  this.signIns.listening = listening.replace(/\/+$/, "");
110
+ this.loopback = local === true;
111
+ this.signIns.loopback = this.loopback;
101
112
  }
102
113
  clientDocument() {
103
114
  return this.signIns.clientDocument();
@@ -144,21 +155,46 @@ export class McpServersOverStore {
144
155
  const name = String(body.name);
145
156
  const kept = await this.need(name);
146
157
  const url = new URL(kept.url);
147
- return marked(kept.url, await this.listServer(url, await this.withAppToken(kept.auth, url, (await this.opened(name, kept, "name")).headers, stop), stop));
158
+ const send = await this.reached(kept.auth, url, stop);
159
+ return marked(kept.url, await this.signInNoted(url, this.listServer(url, await this.withAppToken(kept.auth, url, (await this.opened(name, kept, "name")).headers, stop), send, stop), stop));
148
160
  }
149
- const { url, auth } = this.admit(body);
161
+ // `name` with a url: the saved server the form is editing. Its address as every read shows it (shownUrl), sent back
162
+ // unchanged, is the saved one here too (as save and sign-in map it): the browser never gets the real address back.
163
+ const { name: editing, ...asked } = body;
164
+ const saved = editing === undefined ? undefined : await this.store.mcp.server(String(editing));
165
+ const { url, auth } = this.admit({ ...asked, ...(asked.url !== undefined ? { url: savedOrGiven(asked.url, saved?.url) } : {}) });
150
166
  // A github_app server's credential is a token of the App, minted here, as for a saved one: its static headers are optional.
151
167
  // A per_run server's are optional too: they only list its tools, for a server that lists them only to a caller it knows.
152
168
  if (auth.type !== "none" && auth.type !== "github_app" && auth.type !== "per_run" && !auth.headers)
153
169
  throw invalid([credentialMissing(auth.type, "A preview needs the credential it is to connect with.")]);
154
- return marked(url.href, await this.listServer(url, await this.withAppToken(auth.type, url, auth.headers ?? {}, stop), stop));
170
+ const send = await this.reached(auth.type, url, stop);
171
+ return marked(url.href, await this.signInNoted(url, this.listServer(url, await this.withAppToken(auth.type, url, auth.headers ?? {}, stop), send, stop), stop));
172
+ }
173
+ /** `listing`, and when it is refused as a server that signs in with OAuth (auth_required, `auth: oauth`), whether that
174
+ * sign-in can start with no Client ID entered (`details.oauth.registration`, McpSignIns.registration), so the console
175
+ * asks for one up front. `stop`: the preview's, which cuts that discovery too. */
176
+ async signInNoted(url, listing, stop) {
177
+ try {
178
+ return await listing;
179
+ }
180
+ catch (error) {
181
+ const details = error instanceof ApiError && error.code === "auth_required" ? error.extra.details : undefined;
182
+ if (details?.auth === "oauth") {
183
+ const registration = await this.signIns.registration(url, stop);
184
+ if (registration)
185
+ details.oauth = registration;
186
+ }
187
+ throw error;
188
+ }
155
189
  }
156
190
  /** PUT: preview, then keep the server with the tools listed. A body with no credential keeps the sealed one, while the
157
191
  * auth type and the URL's origin stay the same. */
158
192
  async save(name, body, stop, checkedAgainst) {
159
193
  nameOf(name);
160
- const { url, auth, prices } = this.admit(body, true);
161
194
  const was = await this.store.mcp.server(name);
195
+ // Its URL as every read shows it (shownUrl), sent back unchanged: the saved one.
196
+ const { url, auth, prices } = this.admit({ ...body, ...(body.url !== undefined ? { url: savedOrGiven(body.url, was?.url) } : {}) }, true);
197
+ const send = await this.reached(auth.type, url, stop);
162
198
  // The credential this save may write over: the one the secret-write gate let it through against (`checkedAgainst`,
163
199
  // its credentialMark), else the one read here. The write compares it in its own statement, after the listing's wait.
164
200
  const against = checkedAgainst !== undefined ? checkedAgainst : credentialMark(was);
@@ -196,7 +232,7 @@ export class McpServersOverStore {
196
232
  else if (auth.type !== "none") {
197
233
  credential = { type: "headers", headers: headers };
198
234
  }
199
- const listed = await this.listServer(url, await this.withAppToken(auth.type, url, headers ?? {}, stop), stop);
235
+ const listed = await this.listServer(url, await this.withAppToken(auth.type, url, headers ?? {}, stop), send, stop);
200
236
  const unlisted = Object.keys(prices ?? {}).filter((tool) => !listed.tools.some((listedTool) => listedTool.name === tool));
201
237
  if (unlisted.length)
202
238
  throw invalid(unlisted.map((tool) => ({ field: `prices.${tool}`, reason: "not_an_option", message: `The server ${name} lists no tool ${tool}; its tools are ${listed.tools.map((t) => t.name).join(", ") || "none"}.` })));
@@ -221,8 +257,9 @@ export class McpServersOverStore {
221
257
  /** POST refresh: list the saved server's tools again, keep them, and say what was added, removed and changed. */
222
258
  async refresh(name, stop) {
223
259
  const was = await this.need(name);
260
+ const send = await this.reached(was.auth, new URL(was.url), stop);
224
261
  const open = await this.opened(name, was, "name");
225
- const listed = await this.listServer(new URL(was.url), await this.withAppToken(was.auth, new URL(was.url), open.headers, stop), stop);
262
+ const listed = await this.listServer(new URL(was.url), await this.withAppToken(was.auth, new URL(was.url), open.headers, stop), send, stop);
226
263
  const before = new Map(was.tools.map((tool) => [tool.name, canonical(tool)]));
227
264
  const after = new Map(listed.tools.map((tool) => [tool.name, canonical(tool)]));
228
265
  // A refresh re-lists the tools and leaves the credential as it is (rewriteKeeping: a run's refreshed set kept meanwhile
@@ -264,20 +301,29 @@ export class McpServersOverStore {
264
301
  }
265
302
  /** DELETE. `checkedAgainst`: the credential the secret-write gate let a token's removal through against (one with
266
303
  * none: removing it drops no secret); the row goes only while it is still that, in the store's one statement, so a
267
- * credential saved meanwhile is never dropped by it. */
304
+ * credential saved meanwhile is never dropped by it. An OAuth one's sign-in is then let go at its authorization server
305
+ * (its refresh token revoked, RFC 7009, where its metadata names a revocation_endpoint), behind the answer: best effort,
306
+ * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check). */
268
307
  async remove(name, checkedAgainst) {
269
308
  await this.need(name);
270
- if (checkedAgainst === undefined)
271
- await removeMcpServer(this.store, name);
272
- else if (checkedAgainst === null || !(await removeMcpServerIfCredential(this.store, name, checkedAgainst)))
309
+ // The credential revoked is the one the deleting statement saw (RETURNING): a run's refresh landing before it is in it,
310
+ // one landing after finds no row to keep. A sign-in kept as expired has no refresh token left to revoke.
311
+ const removed = checkedAgainst === undefined ? await removeMcpServer(this.store, this.sealKey, name)
312
+ : checkedAgainst === null ? undefined : await removeMcpServerIfCredential(this.store, this.sealKey, name, checkedAgainst);
313
+ if (checkedAgainst !== undefined && !removed)
273
314
  changedMeanwhile(name, undefined);
274
315
  await this.store.flush();
316
+ const open = removed?.opened;
317
+ const credential = open && "credential" in open && open.credential.type === "oauth" && !open.credential.expired ? open.credential : undefined;
318
+ if (credential && removed)
319
+ void this.track(this.signIns.revoke(credential.set, removed.url, this.stopped.signal));
275
320
  }
276
321
  /** POST .../{name}/oauth/start: `{url, scopes?, client_id?, client_secret?}`; answers the URL the owner opens. */
277
322
  async oauthStart(name, body) {
278
323
  nameOf(name);
279
324
  const issues = unknownFields(body, ["url", "scopes", "client_id", "client_secret"]);
280
- const url = urlOf(body.url, issues);
325
+ // Its URL as every read shows it (shownUrl), sent back unchanged: the saved one.
326
+ const url = urlOf(savedOrGiven(body.url, (await this.store.mcp.server(name))?.url), issues);
281
327
  const { scopes, client_id, client_secret } = body;
282
328
  if (scopes !== undefined && !scopesValid(scopes))
283
329
  issues.push({ field: "scopes", reason: "invalid", message: SCOPE_LIST });
@@ -288,6 +334,8 @@ export class McpServersOverStore {
288
334
  issues.push({ field: "client_id", reason: "missing", message: "A client_secret goes with the client_id it is the secret of." });
289
335
  if (issues.length)
290
336
  throw invalid(issues);
337
+ // The MCP server's own address first: its sign-in's discovery is sent there.
338
+ await this.reached("oauth", url);
291
339
  const was = await this.store.mcp.server(name);
292
340
  // A body with no client_id signs in again with the client kept in the sealed token set, for the same origin only.
293
341
  const kept = typeof client_id !== "string" && was?.auth === "oauth" && new URL(was.url).origin === url.origin ? await this.openedSet(name, was) : undefined;
@@ -316,8 +364,10 @@ export class McpServersOverStore {
316
364
  const error = query.get("error");
317
365
  if (error)
318
366
  return back(/^[a-z_]{1,64}$/.test(error) ? error : "sign_in_failed");
367
+ // Checked again before the code is spent: the owner's list may have changed since the start.
368
+ const send = await this.reached("oauth", new URL(entry.url), stop);
319
369
  const set = await this.signIns.finish(entry, query.get("code") ?? "", query.get("iss") ?? undefined, stop);
320
- const listed = await this.listServer(new URL(entry.url), { authorization: `Bearer ${set.tokens.access_token}` }, stop);
370
+ const listed = await this.listServer(new URL(entry.url), { authorization: `Bearer ${set.tokens.access_token}` }, send, stop);
321
371
  const now = await this.store.mcp.server(entry.name);
322
372
  // Saved, signed in to again or forgotten since this sign-in started: that stands.
323
373
  if ((now ? saving(now) : null) !== entry.was)
@@ -338,9 +388,46 @@ export class McpServersOverStore {
338
388
  return back(await reasonOf(error));
339
389
  }
340
390
  }
341
- listServer(url, headers, stop) {
342
- // The shared probe (mcp-probe.listServer), bound also to this server's own stop.
343
- return listServer(url, headers, this.version, AbortSignal.any([this.stopped.signal, ...(stop ? [stop] : [])]));
391
+ listServer(url, headers, send, stop) {
392
+ // The shared probe (mcp-probe.listServer), bound also to this server's own stop, each request sent as `send` (reached).
393
+ return listServer(url, headers, this.version, AbortSignal.any([this.stopped.signal, ...(stop ? [stop] : [])]), send);
394
+ }
395
+ /** How a request to the MCP server at `url` goes, or a 422 on url before anything is sent to it (or a token minted for
396
+ * it): a github_app server anywhere but GitHub's hosted MCP (GITHUB_MCP_ONLY, as withAppToken says), and at it, as it
397
+ * is, since that one origin is this server's to name, never the owner's; any other server held to the address rule
398
+ * (mcp-oauth.ts mcpServerAt, the one an authorization server's endpoint is held to), with the private-network hosts the
399
+ * owner allows read now, loopback only for a local install. The fetch it answers dials the address checked. A name
400
+ * that does not resolve is the unreachable server it always was (424). */
401
+ async reached(type, url, stop) {
402
+ // A saved row's URL is held to the save's rule too: one with a credential in its query is refused, nothing sent.
403
+ const inQuery = credentialInQuery(url);
404
+ if (inQuery)
405
+ throw invalid([{ field: "url", reason: "invalid", message: credentialInQueryWords(inQuery) }]);
406
+ if (type === "github_app") {
407
+ if (!githubMcpUrl(url, this.appOrigin))
408
+ throw invalid([{ field: "url", reason: "not_allowed", message: GITHUB_MCP_ONLY }]);
409
+ return fetch;
410
+ }
411
+ // A URL on loopback as written, on a server its operator never said is a local install: refused, saying how to say so.
412
+ if (!this.loopback && LOOPBACK.test(url.hostname))
413
+ throw invalid([{ field: "url", reason: "not_allowed", message: loopbackWords(url.hostname) }]);
414
+ const signal = AbortSignal.any([AbortSignal.timeout(ADDRESS_CHECK_MS), this.stopped.signal, ...(stop ? [stop] : [])]);
415
+ let at;
416
+ try {
417
+ at = await mcpServerAt(url, signal, this.network, { own: this.signIns.own, allowed: await privateOAuthHosts(this.store), loopback: this.loopback });
418
+ }
419
+ catch (error) {
420
+ if (stop?.aborted || this.stopped.signal.aborted)
421
+ throw error;
422
+ // Its address check outlived its time: a name lookup that never answered.
423
+ throw new ApiError("upstream_failed", `Could not reach the MCP server at ${url.origin} (DNS lookup timed out after ${ADDRESS_CHECK_MS / 1000} s).`);
424
+ }
425
+ if ("refused" in at) {
426
+ if (at.unresolved)
427
+ throw new ApiError("upstream_failed", `Could not reach the MCP server at ${url.origin} (ENOTFOUND).`);
428
+ throw invalid([{ field: "url", reason: "not_allowed", message: `${at.refused.charAt(0).toUpperCase()}${at.refused.slice(1)}.` }]);
429
+ }
430
+ return dialAt(this.network, at.address);
344
431
  }
345
432
  async need(name) {
346
433
  const row = await this.store.mcp.server(name);
@@ -389,7 +476,8 @@ export class McpServersOverStore {
389
476
  const listedAt = new Date(row.listedAt ?? row.updatedAt).toISOString();
390
477
  return {
391
478
  name,
392
- url: row.url,
479
+ // Its origin, the path and query held as a secret (shownUrl): the whole URL is only ever sent to the server itself.
480
+ url: shownUrl(row.url),
393
481
  ...(prices && Object.keys(prices).length ? { prices } : {}),
394
482
  ...listed,
395
483
  // Each priced tool's price in USD a call, as the owner saved them, on every read.
@@ -436,6 +524,10 @@ export class McpServersOverStore {
436
524
  /** Which save of a server this is: a PUT or a sign-in makes a new one (its updated time moves), a refresh of its tools or
437
525
  * token does not change the url. The staleness key an OAuth sign-in carries from start to callback. */
438
526
  const saving = (row) => `${row.url} ${row.updatedAt}`;
527
+ /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
528
+ export const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
529
+ /** What a URL on loopback says on a server that is not one, with how to make it one. */
530
+ export const loopbackWords = (host) => `${host} is this machine; set ${MCP_ALLOW_LOOPBACK_ENV}=1 when starting the server, only on a machine you alone use.`;
439
531
  /** The owner's MCP registry over the one store. No load() is needed: every read goes to the store (the runner also writes
440
532
  * the OAuth state), so a read is always current. */
441
533
  export function mcpServersOverStore(store, env, version, network) {
@@ -54,14 +54,20 @@ export declare function rewriteMcpServer(store: {
54
54
  }, seen: Uint8Array | null, { githubMcpOrigin }?: {
55
55
  githubMcpOrigin?: string;
56
56
  }): Promise<McpServerRow | undefined>;
57
- /** The server's row goes. */
57
+ /** The server's row goes; what it held as it went (its address, its credential opened, as openServerCredential does), or
58
+ * undefined when there was no row. */
58
59
  export declare function removeMcpServer(store: {
59
60
  mcp: Pick<Mcp, "remove">;
60
- }, name: string): Promise<void>;
61
- /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). False when it is not. */
61
+ }, sealKey: Buffer, name: string): Promise<RemovedMcpServer | undefined>;
62
+ /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). Undefined when it is not. */
62
63
  export declare function removeMcpServerIfCredential(store: {
63
64
  mcp: Pick<Mcp, "removeIfCredential">;
64
- }, name: string, expected: NonNullable<McpCredentialMark>): Promise<boolean>;
65
+ }, sealKey: Buffer, name: string, expected: NonNullable<McpCredentialMark>): Promise<RemovedMcpServer | undefined>;
66
+ /** A removed row: its address and its credential opened (§7), the credential the one the deleting statement saw. */
67
+ export type RemovedMcpServer = {
68
+ url: string;
69
+ opened: OpenedMcpCredential | undefined;
70
+ };
65
71
  /** Every saved server's row, by name (its credential stays sealed). */
66
72
  export declare function listMcpServers(store: {
67
73
  mcp: Pick<Mcp, "servers">;
package/dist/mcp-store.js CHANGED
@@ -70,14 +70,25 @@ export async function rewriteMcpServer(store, server, seen, { githubMcpOrigin =
70
70
  ...(server.listedAt !== undefined ? { listedAt: server.listedAt } : {}), ...(server.updatedAt !== undefined ? { updatedAt: server.updatedAt } : {}),
71
71
  }, seen);
72
72
  }
73
- /** The server's row goes. */
74
- export async function removeMcpServer(store, name) {
75
- await store.mcp.remove(name);
73
+ /** The server's row goes; what it held as it went (its address, its credential opened, as openServerCredential does), or
74
+ * undefined when there was no row. */
75
+ export async function removeMcpServer(store, sealKey, name) {
76
+ return removedServer(sealKey, name, await store.mcp.remove(name));
76
77
  }
77
- /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). False when it is not. */
78
- export async function removeMcpServerIfCredential(store, name, expected) {
79
- return store.mcp.removeIfCredential(name, expected);
78
+ /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). Undefined when it is not. */
79
+ export async function removeMcpServerIfCredential(store, sealKey, name, expected) {
80
+ return removedServer(sealKey, name, await store.mcp.removeIfCredential(name, expected));
80
81
  }
82
+ const removedServer = (sealKey, name, removed) => {
83
+ if (!removed)
84
+ return undefined;
85
+ try {
86
+ return { url: removed.url, opened: openMcpCredential(sealKey, { name, url: removed.url, sealed: removed.sealed }) };
87
+ }
88
+ catch {
89
+ return { url: removed.url, opened: undefined };
90
+ }
91
+ };
81
92
  /** Every saved server's row, by name (its credential stays sealed). */
82
93
  export async function listMcpServers(store) {
83
94
  return store.mcp.servers();
@@ -0,0 +1,26 @@
1
+ /** The current models a person may pick, by vendor, in the vendor's own ids (Anthropic's dashes; OpenRouter's dotted name
2
+ * for the same model is derived, provider.ts openRouterName). The everyday model first: it is the example a refusal gives.
3
+ * A candidate a harness cannot run on this server (one pi-ai's catalog does not list) is dropped before it is served
4
+ * (harness.ts harnessOffers). */
5
+ export declare const PICKABLE: readonly {
6
+ vendor: string;
7
+ ids: readonly string[];
8
+ }[];
9
+ /** `vendor`'s model `id` in the form this server runs it: `vendor/id` on the vendor's own key, or through OpenRouter
10
+ * (`openrouter/vendor/id`, Anthropic's id in OpenRouter's dotted name) when OpenRouter's key is the only one here. */
11
+ export declare function formOf(env: NodeJS.ProcessEnv, vendor: string, id: string): string;
12
+ /** The models offered for `harness` on this server, each in the form it takes, before the harness's own catalog is asked
13
+ * (harness.ts harnessOffers drops those it does not run). Behind serve's gateway every id is the gateway's own string, so
14
+ * the host's tier models stand for what it runs; with the faux model none is offered. */
15
+ export declare function pickerCandidates(env: NodeJS.ProcessEnv, harness: string): string[];
16
+ /** The model `given` most likely means, in the form this harness takes, or undefined when none is obvious: the same id
17
+ * with a dot for a dash or the other way, a missing provider, or a name without its `claude-` ("Sonnet 5.5"). */
18
+ export declare function likelyModel(env: NodeJS.ProcessEnv, harness: string, given: string): string | undefined;
19
+ /** What a refusal says of a model named in a form `harness` does not take: the form it takes, with examples this server
20
+ * can run, and the likely id when one is obvious. `host`: the name is the server's own default, not the revision's. No
21
+ * word of the catalog behind it: a person's words. */
22
+ export declare function modelFormWhy(env: NodeJS.ProcessEnv, harness: string, named: string, host: boolean): string;
23
+ /** "On pi, a model is <provider>/<model id>, like A or B": the forms this server can run, each of the harness's first
24
+ * vendor's everyday model, the vendor's own and OpenRouter's. Only the forms a key here runs; with neither key both, since
25
+ * either key makes one run. */
26
+ export declare function modelShape(env: NodeJS.ProcessEnv, harness: string): string;