@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
@@ -68,8 +68,9 @@ export async function pinFirst(revision, deps) {
68
68
  * that server's own ports (`own`, Serve.own). `githubApp`:
69
69
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
70
70
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
71
- * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
72
- export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin } = {}) {
71
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
72
+ * test's fake Composio MCP (McpServersOverStore.composioOrigin). */
73
+ export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin, composioOrigin } = {}) {
73
74
  let registry;
74
75
  // The listing tokens minted and not yet revoked, and how many listings are under way: no one holds a listing token
75
76
  // after its listing (the claim's cleanup reaches only githubTokens' tokens), so once no listing is under way, each is
@@ -82,6 +83,8 @@ export function registryListing(store, sealKey, { loopback = false, own = [], ne
82
83
  opened.attach("", "", loopback, own);
83
84
  if (appOrigin)
84
85
  opened.appOrigin = appOrigin;
86
+ if (composioOrigin)
87
+ opened.composioOrigin = composioOrigin;
85
88
  if (githubApp)
86
89
  opened.appToken = async () => {
87
90
  const got = await listingToken(githubApp);
@@ -2,24 +2,33 @@ import { type SecretRequest } from "./secret-writes.js";
2
2
  import type { McpCredentialMark } from "./store/index.js";
3
3
  /** Whether `operation`'s `body` writes an MCP secret by the body alone (see above). */
4
4
  export declare function mcpWritesSecret(operation: string, body: unknown): boolean;
5
- /** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set. */
5
+ /** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set,
6
+ * and when the row was made (its source record is bound to it). */
6
7
  type SavedRow = {
7
8
  auth: string;
8
9
  sealed: unknown;
9
10
  credentialChangedAt?: number | null;
11
+ createdAt?: number;
10
12
  };
11
13
  /** A saved server's credential as a writer read it (McpCredentialMark): its auth type, whether one is sealed, and when it
12
14
  * was set. A save let through against one mark writes only while the row still has it, in the store's one statement
13
15
  * (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
14
16
  export declare const credentialMark: (row: SavedRow | undefined) => McpCredentialMark;
15
- /** Whether a save of the server its path names (with no value in its body) would drop or change the credential the
16
- * server holds: it holds one, and the save names another auth type, or none (a body with no auth is none). */
17
- export declare function mcpSaveDropsSecret(body: unknown, request: SecretRequest): Promise<boolean>;
18
- /** Whether removing the server its path names drops a credential: it holds a sealed one. A server saved with none (an
19
- * eval's fake, say) is the token's to remove; the removal lands only while that is still so (request.seen). */
20
- export declare function mcpDeleteDropsSecret(_body: unknown, request: SecretRequest): Promise<boolean>;
17
+ /** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
18
+ * generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
19
+ * mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
20
+ * token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
21
+ * write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
22
+ * still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
23
+ * remove), so an owner's save landing after this check is never written over or removed. */
24
+ export declare function tokenWriteOverRefused(_body: unknown, request: SecretRequest): Promise<boolean>;
21
25
  /** MCP's operations the one gate reads: the predicates above decide each request. */
22
26
  export declare const MCP_SECRET_OPERATIONS: readonly ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
27
+ /** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
28
+ * secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
29
+ * new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
30
+ * the console, so the token's is the one refusal as before. */
31
+ export declare function composioSaveDropsSecret(body: unknown, request: SecretRequest): Promise<boolean>;
23
32
  /** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
24
33
  * characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
25
34
  * nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
@@ -1,17 +1,19 @@
1
1
  // MCP's predicates for the one secret-write gate (secret-writes.ts): which MCP operations the server's dispatch takes from
2
2
  // the owner's signed-in page alone, refusing every token.
3
3
  // - A save that sends a value (a bearer token or a header's value, in any auth type: a value sent is a value, even in a
4
- // body the save then refuses) writes a secret; so does one that would DROP or CHANGE the credential a saved server
5
- // holds (another auth type, or none), read from the store.
4
+ // body the save then refuses) writes a secret.
6
5
  // - A sign-in's start always writes one: its callback seals whatever token set the sign-in it started returns, so who
7
6
  // starts it decides whose credential the server's runs use.
8
- // - Removing a server that holds a credential drops it (read from the store); the private-network OAuth hosts count whole,
9
- // since they widen where a sign-in sends its code and tokens.
10
- // A server with no credential, a save that keeps the sealed one (prices, tools, url), a preview and a refresh (each keeps
11
- // nothing new) stay open to a token.
7
+ // - The private-network OAuth hosts count whole, since they widen where a sign-in sends its code and tokens.
8
+ // - The token saves over and removes only a server the token saved that seals no credential (tokenWriteOverRefused: one
9
+ // rule for every such route, read from the store): the owner's stays the owner's, sealed or not, so the token never
10
+ // drops or changes its credential, moves it, or removes what it made at Composio.
11
+ // A new server with no credential, the token's own server, a preview and a refresh (each keeps nothing new) stay open to a
12
+ // token.
12
13
  import { COMPOSIO_TOOLKIT } from "./composio-preset.js";
13
14
  import { secretShapes } from "./learn/secrets.js";
14
15
  import { urlOf } from "./mcp-probe.js";
16
+ import { mcpSourceKey, savedByToken } from "./mcp-sources.js";
15
17
  import { registerNotSecretWrite, registerSecretPage, registerSecretWrite } from "./secret-writes.js";
16
18
  import { MCP_SERVER_NAME } from "./tool-names.js";
17
19
  import { isObject } from "./validate.js";
@@ -32,40 +34,46 @@ export function mcpWritesSecret(operation, body) {
32
34
  * was set. A save let through against one mark writes only while the row still has it, in the store's one statement
33
35
  * (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
34
36
  export const credentialMark = (row) => (row ? { auth: row.auth, sealed: row.sealed !== null && row.sealed !== undefined, changedAt: row.credentialChangedAt ?? null } : null);
35
- /** Whether a save of the server its path names (with no value in its body) would drop or change the credential the
36
- * server holds: it holds one, and the save names another auth type, or none (a body with no auth is none). */
37
- export async function mcpSaveDropsSecret(body, request) {
37
+ /** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
38
+ * generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
39
+ * mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
40
+ * token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
41
+ * write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
42
+ * still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
43
+ * remove), so an owner's save landing after this check is never written over or removed. */
44
+ export async function tokenWriteOverRefused(_body, request) {
38
45
  const [name] = request.params;
39
46
  if (!name)
40
47
  return false;
41
- const was = await request.store.mcp.server(name);
42
- // What the save is let through against: it lands only if the credential is still this one.
48
+ const store = request.store;
49
+ const was = await store.mcp.server(name);
43
50
  request.seen = credentialMark(was);
44
- if (!was || was.sealed === null || was.sealed === undefined)
51
+ if (!was)
45
52
  return false;
46
- const auth = isObject(body) ? body.auth : undefined;
47
- const type = auth === undefined ? "none" : isObject(auth) ? auth.type : undefined;
48
- return type !== was.auth;
49
- }
50
- /** Whether removing the server its path names drops a credential: it holds a sealed one. A server saved with none (an
51
- * eval's fake, say) is the token's to remove; the removal lands only while that is still so (request.seen). */
52
- export async function mcpDeleteDropsSecret(_body, request) {
53
- const [name] = request.params;
54
- if (!name)
55
- return false;
56
- const was = await request.store.mcp.server(name);
57
- request.seen = credentialMark(was);
58
- return !!was && was.sealed !== null && was.sealed !== undefined;
53
+ return (was.sealed !== null && was.sealed !== undefined) || !savedByToken(await store.settings.get(mcpSourceKey(name)), was.createdAt);
59
54
  }
60
55
  /** MCP's operations the one gate reads: the predicates above decide each request. */
61
56
  export const MCP_SECRET_OPERATIONS = ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
62
- const STORED = { saveMcpServer: mcpSaveDropsSecret, deleteMcpServer: mcpDeleteDropsSecret };
57
+ const STORED = { saveMcpServer: tokenWriteOverRefused, deleteMcpServer: tokenWriteOverRefused };
63
58
  for (const operation of MCP_SECRET_OPERATIONS)
64
59
  registerSecretWrite(operation, (body) => mcpWritesSecret(operation, body), STORED[operation]);
65
60
  // The Composio preset takes the owner's API key and seals it as an MCP header: both routes are the owner's session alone,
66
61
  // whatever the body (the listing sends the key too, and only the session may type one).
67
62
  registerSecretWrite("listComposioTools", () => true);
68
- registerSecretWrite("saveComposioServer", () => true);
63
+ registerSecretWrite("saveComposioServer", composioSaveSendsKey, composioSaveDropsSecret);
64
+ // A save's body that sends a key's value, or anything but api_key_env alone in its place: a secret written.
65
+ function composioSaveSendsKey(body) {
66
+ return !(isObject(body) && body.api_key === undefined && body.api_key_env !== undefined);
67
+ }
68
+ /** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
69
+ * secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
70
+ * new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
71
+ * the console, so the token's is the one refusal as before. */
72
+ export async function composioSaveDropsSecret(body, request) {
73
+ if (!request.apiOnly || !request.params[0])
74
+ return true;
75
+ return tokenWriteOverRefused(body, request);
76
+ }
69
77
  // A Composio server's webhook subscription (composio-triggers.ts): a rotate seals its new secret, a delete drops it.
70
78
  registerSecretWrite("rotateComposioSecret", () => true);
71
79
  registerSecretWrite("deleteComposioSubscription", () => true);
@@ -1,10 +1,10 @@
1
1
  import { type Listed, type McpPrices, type McpTool } from "./mcp-probe.js";
2
2
  import { type SecretMeta } from "./secret-writes.js";
3
3
  import { type ClientKind, type OAuthNetwork } from "./mcp-oauth.js";
4
- import { type Cleanup, type ComposioMade } from "./composio-made.js";
4
+ import { type Cleanup, COMPOSIO_KEY_ENV, type ComposioMade } from "./composio-made.js";
5
5
  import { type RecordedRow, type SourceRecord } from "./mcp-sources.js";
6
6
  import { type ToolSettingsMap } from "./tool-plane.js";
7
- import { type McpCredentialMark, type Mcp, type McpOauth, type Settings, type Store } from "./store/index.js";
7
+ import { type McpCredentialMark, type Mcp, type McpOauth, type McpServerRow, type Settings, type Store } from "./store/index.js";
8
8
  import { MCP_ALLOW_LOOPBACK_ENV } from "./start-switches.js";
9
9
  /** The store slice this layer reads and writes; `settings` for the private-network OAuth hosts the owner allows and each
10
10
  * server's source and toolkit (mcp-sources.ts). */
@@ -64,10 +64,15 @@ export declare class McpServersOverStore {
64
64
  /** The one origin a github_app server may have (GITHUB_MCP_ORIGIN; a test's fake through the server's seam): the App's
65
65
  * tokens are minted for, and sent to, nothing else. */
66
66
  appOrigin: string;
67
+ /** The one origin a key read from the environment is sent to (COMPOSIO_ORIGIN; a test's fake through the server's
68
+ * seam): a Composio server saved with api_key_env at any other address is refused (composioEnvKey). */
69
+ composioOrigin: string;
67
70
  private readonly sealKey;
68
71
  private readonly signIns;
69
72
  /** The callbacks under way, which close() waits out before the server lets its data go. */
70
73
  private readonly inflight;
74
+ /** Each server name's save turn (nameTurn): the last save in it, settled either way. */
75
+ private readonly nameTurns;
71
76
  private readonly stopped;
72
77
  /** Whether this server is a local install (attach): only then may an MCP server's URL be on loopback. */
73
78
  private loopback;
@@ -142,6 +147,7 @@ export declare class McpServersOverStore {
142
147
  expires_at?: string | undefined;
143
148
  } | undefined;
144
149
  auth: {
150
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
145
151
  headers?: string[] | undefined;
146
152
  type: string;
147
153
  };
@@ -184,6 +190,7 @@ export declare class McpServersOverStore {
184
190
  expires_at?: string | undefined;
185
191
  } | undefined;
186
192
  auth: {
193
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
187
194
  headers?: string[] | undefined;
188
195
  type: string;
189
196
  };
@@ -244,8 +251,11 @@ export declare class McpServersOverStore {
244
251
  * server's record now owns or the caller removes. `guard`, a preset row's: the turn its write and cleanup take, once
245
252
  * the listing is done (never across it), and the check of the triggers that use it, made in that turn before a write
246
253
  * that leaves what they stand on (an ordinary save moving the row off Composio, a preset save as another user or auth
247
- * config): refused, nothing written. */
248
- save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord, stands?: ComposioMade, dropped?: (left: ComposioDropped) => void, guard?: SaveGuard): Promise<{
254
+ * config): refused, nothing written. `byToken`: the API token makes the save (a request the secret-write gate read), so
255
+ * a row it makes is recorded as the token's (mcp-sources.ts savedByToken), and it writes over a saved row only while
256
+ * that row still carries the token's mark, compared in the row's own statement (412, nothing written, when an owner's
257
+ * save took it meanwhile). */
258
+ save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord, stands?: ComposioMade, dropped?: (left: ComposioDropped) => void, guard?: SaveGuard, byToken?: boolean): Promise<{
249
259
  listed_at: string;
250
260
  updated_at: string;
251
261
  secret: SecretMeta;
@@ -256,6 +266,7 @@ export declare class McpServersOverStore {
256
266
  expires_at?: string | undefined;
257
267
  } | undefined;
258
268
  auth: {
269
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
259
270
  headers?: string[] | undefined;
260
271
  type: string;
261
272
  };
@@ -286,6 +297,11 @@ export declare class McpServersOverStore {
286
297
  source: "url" | "github" | "composio";
287
298
  toolkit: string | null;
288
299
  }>;
300
+ /** `work` in the turn of the saved server `name`, after every save of that name already in it: a save writes its row and
301
+ * then its source record (mcp-sources.ts), so the token's mark, written after its row, never lands on a row an owner's
302
+ * save wrote between the two. One server holds a store (StoreOwned), so the turn is this process's. A delete takes
303
+ * none: its statement compares the mark itself (Mcp.removeIfCredential). */
304
+ private nameTurn;
289
305
  /** POST refresh: list the saved server's tools again, keep them, and say what was added, removed and changed. */
290
306
  refresh(name: string, stop?: AbortSignal): Promise<{
291
307
  added: string[];
@@ -302,6 +318,7 @@ export declare class McpServersOverStore {
302
318
  expires_at?: string | undefined;
303
319
  } | undefined;
304
320
  auth: {
321
+ api_key_env?: "COMPOSIO_API_KEY" | undefined;
305
322
  headers?: string[] | undefined;
306
323
  type: string;
307
324
  };
@@ -341,8 +358,12 @@ export declare class McpServersOverStore {
341
358
  * none: removing it drops no secret); the row goes only while it is still that, in the store's one statement, so a
342
359
  * credential saved meanwhile is never dropped by it. An OAuth one's sign-in is then let go at its authorization server
343
360
  * (its refresh token revoked, RFC 7009, where its metadata names a revocation_endpoint), behind the answer: best effort,
344
- * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check). */
345
- remove(name: string, checkedAgainst?: McpCredentialMark): Promise<{
361
+ * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check).
362
+ * `byToken`: the API token removes it, which it may only while the row is one the token saved (savedByToken): its
363
+ * credential and its mark are compared in the deleting statement itself (Mcp.removeIfCredential), never in a read
364
+ * before it, so an owner's save that lands after the gate's check (it drops the mark in the transaction that writes
365
+ * its row) is never removed, and nothing is sent to Composio for it. */
366
+ remove(name: string, checkedAgainst?: McpCredentialMark, byToken?: boolean): Promise<{
346
367
  composio?: ComposioHandle;
347
368
  }>;
348
369
  /** Whether `name` is a Composio preset server now (auth headers, source composio): a save of it takes the Composio turn,
@@ -379,6 +400,9 @@ export declare class McpServersOverStore {
379
400
  * read and checked, never the one saved now: a save at another address with a new credential while the caller waited
380
401
  * (its address check, a listing) must never have that credential sent to the old address. */
381
402
  private opened;
403
+ /** The variable a Composio server saved with api_key_env reads its key from (composio-made.ts key_env): a headers row
404
+ * that seals no credential, whose record for this row names it. None for every other row. */
405
+ keyEnvOf(row: McpServerRow): Promise<typeof COMPOSIO_KEY_ENV | undefined>;
382
406
  /** The saved OAuth token set of `row` (the row read and checked, as opened), for a sign-in again that reuses the kept
383
407
  * client. */
384
408
  private openedSet;
@@ -15,9 +15,9 @@ import { checkPrivateHosts, privateOAuthHosts, savePrivateOAuthHosts } from "./m
15
15
  import { credentialMark } from "./mcp-secret-writes.js";
16
16
  import { secretMeta, secretName } from "./secret-writes.js";
17
17
  import { dialAt, issuerOf, LOOPBACK, MAX_PENDING, MCP_SETTINGS_PAGE, mcpServerAt, McpSignIns, reasonOf, SIGN_IN_AGAIN, systemNetwork } from "./mcp-oauth.js";
18
- import { cleanupOf, composioMadeKey, composioPerRun, droppedOf, madeToWrite, recordedMade, releasedOf, storedMade } from "./composio-made.js";
18
+ import { cleanupOf, COMPOSIO_ORIGIN, composioEnvKey, composioKeyFromEnv, composioMadeKey, composioPerRun, droppedOf, madeToWrite, recordedMade, releasedOf, storedMade } from "./composio-made.js";
19
19
  import { COMPOSIO_PER_RUN, COMPOSIO_USER, composioListingAddress, composioServerId } from "./composio-preset.js";
20
- import { mcpSourceKey, recordedForAnother, sourceOf, sourceToWrite, standInGiven, storedSource, toolkitGiven } from "./mcp-sources.js";
20
+ import { mcpSourceKey, recordedForAnother, savedByToken, sourceOf, sourceToWrite, standInGiven, storedSource, toolkitGiven } from "./mcp-sources.js";
21
21
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
22
22
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "./github.js";
23
23
  import { serverGate } from "./tool-plane.js";
@@ -41,9 +41,10 @@ function changedMeanwhile(name, saved) {
41
41
  throw new ApiError("precondition_failed", `The MCP server ${name}'s credential changed while this save ran (another save, a sign-in or a removal): read it again, then save again.`);
42
42
  return saved;
43
43
  }
44
- function composioHandleOf(removed, cleanup) {
44
+ function composioHandleOf(removed, cleanup, keyEnv) {
45
45
  const id = removed ? composioServerId(removed.url) : undefined;
46
- const key = composioKeyOf(removed?.opened);
46
+ // A server saved with api_key_env seals no key: its variable's value, as this process was started with it.
47
+ const key = composioKeyOf(removed?.opened) ?? (keyEnv && composioKeyFromEnv(keyEnv));
47
48
  return { ...(id && key ? { id, key } : { unusable: true }), ...(cleanup ? { cleanup } : {}) };
48
49
  }
49
50
  /** The Composio key a preset row's opened credential holds (its x-api-key header); none when it does not open. */
@@ -100,10 +101,15 @@ export class McpServersOverStore {
100
101
  /** The one origin a github_app server may have (GITHUB_MCP_ORIGIN; a test's fake through the server's seam): the App's
101
102
  * tokens are minted for, and sent to, nothing else. */
102
103
  appOrigin = GITHUB_MCP_ORIGIN;
104
+ /** The one origin a key read from the environment is sent to (COMPOSIO_ORIGIN; a test's fake through the server's
105
+ * seam): a Composio server saved with api_key_env at any other address is refused (composioEnvKey). */
106
+ composioOrigin = COMPOSIO_ORIGIN;
103
107
  sealKey;
104
108
  signIns;
105
109
  /** The callbacks under way, which close() waits out before the server lets its data go. */
106
110
  inflight = new Set();
111
+ /** Each server name's save turn (nameTurn): the last save in it, settled either way. */
112
+ nameTurns = new Map();
107
113
  stopped = new AbortController();
108
114
  /** Whether this server is a local install (attach): only then may an MCP server's URL be on loopback. */
109
115
  loopback = false;
@@ -260,8 +266,11 @@ export class McpServersOverStore {
260
266
  * server's record now owns or the caller removes. `guard`, a preset row's: the turn its write and cleanup take, once
261
267
  * the listing is done (never across it), and the check of the triggers that use it, made in that turn before a write
262
268
  * that leaves what they stand on (an ordinary save moving the row off Composio, a preset save as another user or auth
263
- * config): refused, nothing written. */
264
- async save(name, body, stop, checkedAgainst, made, stands, dropped, guard) {
269
+ * config): refused, nothing written. `byToken`: the API token makes the save (a request the secret-write gate read), so
270
+ * a row it makes is recorded as the token's (mcp-sources.ts savedByToken), and it writes over a saved row only while
271
+ * that row still carries the token's mark, compared in the row's own statement (412, nothing written, when an owner's
272
+ * save took it meanwhile). */
273
+ async save(name, body, stop, checkedAgainst, made, stands, dropped, guard, byToken = false) {
265
274
  nameOf(name);
266
275
  const was = await this.store.mcp.server(name);
267
276
  // Its URL as every read shows it (shownUrl), sent back unchanged: the saved one.
@@ -270,8 +279,10 @@ export class McpServersOverStore {
270
279
  // is now, checked before anything is listed; written once the server is, for the row it wrote.
271
280
  const sourceIssues = [];
272
281
  const wasSource = await this.sourceOf({ name, auth: auth.type, createdAt: was?.createdAt });
273
- // Whether the row was a Composio preset server (auth headers, source composio), read before this save writes its own.
282
+ // Whether the row was a Composio preset server (auth headers, source composio), read before this save writes its own;
283
+ // and the variable its key was read from, when it was saved with api_key_env.
274
284
  const wasPreset = was !== undefined && was.auth === "headers" && (await this.sourceOf(was)).source === "composio";
285
+ const wasKeyEnv = wasPreset ? await this.keyEnvOf(was) : undefined;
275
286
  // An ordinary save that moves a Composio preset row to another address makes it another service's server: it stops being
276
287
  // Composio's, whatever its path looks like, so its delete never sends the key it holds to Composio. It is url's, with the
277
288
  // toolkit the same save names, else none.
@@ -313,11 +324,23 @@ export class McpServersOverStore {
313
324
  throw invalid([credentialMissing(auth.type, `The address moved from ${new URL(was.url).origin} to ${url.origin}: send the credential again, so a saved one never goes to another origin.`)]);
314
325
  const open = await this.opened(name, was, credentialMissing(auth.type, "").field);
315
326
  headers = open.headers;
316
- keeping = true;
327
+ // A key read from the environment is no sealed one to keep: the row is written sealing none again.
328
+ keeping = !open.env;
317
329
  }
318
- else if (auth.type !== "none") {
330
+ else if (auth.type !== "none" && !stands?.key_env) {
331
+ // A Composio key read from the environment (`stands.key_env`) only lists the tools now: the row seals none.
319
332
  credential = { type: "headers", headers: headers };
320
333
  }
334
+ else if (stands?.key_env) {
335
+ // ...and only at Composio's origin: an address Composio answered elsewhere is refused, and the key is not sent there.
336
+ const got = composioEnvKey(name, url.href, stands.key_env, this.composioOrigin);
337
+ if ("refused" in got)
338
+ throw invalid([{ field: "url", reason: got.reason, message: got.refused }]);
339
+ }
340
+ // The token keeps no sealed credential: the secret-write gate lets its save over no sealed row (mcp-secret-writes.ts
341
+ // tokenWriteOverRefused), so one read here is an owner's, saved since. Refused as changed meanwhile, nothing written.
342
+ if (byToken && keeping)
343
+ changedMeanwhile(name, undefined);
321
344
  // A per-run Composio server, made so now (`stands`) or saved so and kept at its address by an ordinary save.
322
345
  const perRun = Boolean(stands?.per_run) || (!made && was !== undefined && auth.type === "headers" && was.url === url.href && (await this.perRunComposio(name, was)));
323
346
  const listed = await this.listServer(url, await this.withAppToken(auth.type, url, headers ?? {}, stop), send, stop, perRun);
@@ -345,16 +368,31 @@ export class McpServersOverStore {
345
368
  if (moved || (made && stands && (!stood || stood.user !== stands.user || Boolean(stood.per_run) !== Boolean(stands.per_run) || (stood.auth_config?.id ?? null) !== (stands.auth_config?.id ?? null))))
346
369
  await guard.inUse();
347
370
  }
371
+ // Who saved the row (mcp-sources.ts `by`): the token marks a row it makes, and keeps the mark on its own; the owner's
372
+ // row stays the owner's under the token's save. The owner's save over a saved row drops the token's mark in the
373
+ // store's transaction that writes the row, once it is written (`owns`, McpOwnersMark): a save refused (412) leaves
374
+ // the row and its record as they were, so the server stays the token's; one that lands is the owner's with no
375
+ // moment between its row and its record, so the token's write or delete, which compares the mark in its own
376
+ // statement, never takes the row the owner saved.
377
+ const recorded = was ? await this.store.settings.get(mcpSourceKey(name)) : undefined;
378
+ const wasToken = was !== undefined && savedByToken(recorded, was.createdAt);
379
+ const mark = byToken && (was === undefined || wasToken);
380
+ const owns = !byToken && was !== undefined ? { record: mcpSourceKey(name) } : undefined;
348
381
  const saved = keeping
349
382
  // Re-applied only onto a row that still holds a credential of this auth type, at the address this save read: never
350
383
  // onto another one's, nor over a row another save moved meanwhile (a Composio save over it, whose cleanup removed the
351
384
  // MCP server at the address read; Composio's share an origin). It writes no credential column, so it never drops or
352
385
  // replaces one.
353
- ? await this.rewriteKeeping(name, was, fields, "save", (fresh) => fresh.auth === auth.type && fresh.sealed !== null && fresh.url === was.url)
354
- // A new credential, or none: written only while the row's credential is still `against`, in the store's one statement.
355
- : changedMeanwhile(name, await saveMcpServerIfCredential(this.store, this.sealKey, { ...fields(was), ...(credential ? { credential } : {}) }, against, { githubMcpOrigin: this.appOrigin }));
386
+ ? await this.rewriteKeeping(name, was, fields, "save", (fresh) => fresh.auth === auth.type && fresh.sealed !== null && fresh.url === was.url, owns)
387
+ // A new credential, or none: written only while the row's credential is still `against`, and the token's over a
388
+ // saved row only while that row still carries its mark (savedByToken), both in the store's one statement: the
389
+ // check and the write are one step, so an owner's save that lands after the gate's read is never written over.
390
+ : changedMeanwhile(name, await saveMcpServerIfCredential(this.store, this.sealKey, { ...fields(was), ...(credential ? { credential } : {}) }, against, { githubMcpOrigin: this.appOrigin, ...(byToken ? { tokens: { record: mcpSourceKey(name) } } : {}), ...(owns ? { owns } : {}) }));
356
391
  if (source)
357
- await this.store.settings.put(mcpSourceKey(name), storedSource(source, saved, !made && source === standIn));
392
+ await this.store.settings.put(mcpSourceKey(name), storedSource(source, saved, !made && source === standIn, mark));
393
+ // A row the token made with no source given: url with none, as an unrecorded row reads (sourceOf), marked.
394
+ else if (mark && !wasToken)
395
+ await this.store.settings.put(mcpSourceKey(name), storedSource({ source: "url", toolkit: null }, saved, false, true));
358
396
  // The Composio MCP server the row named before, when the preset made it (the row was a preset server) and the row names
359
397
  // it no longer: a preset save over it made a new one, or an ordinary save moved the row off Composio.
360
398
  const madeBefore = wasPreset && (made || moved) ? composioServerId(was.url) : undefined;
@@ -401,14 +439,32 @@ export class McpServersOverStore {
401
439
  catch {
402
440
  key = undefined;
403
441
  }
442
+ key ??= wasKeyEnv && composioKeyFromEnv(wasKeyEnv);
404
443
  dropped?.({ ...(key ? { key } : { unusable: true }), cleanup: left ?? { remove: [], kept: [] }, ...(leftMcp ? { mcp: leftMcp } : {}) });
405
444
  }
406
445
  return saved;
407
446
  };
408
- const saved = guard ? await guard.turn(write) : await write();
447
+ // The name's turn (nameTurn) inside the guard's: the row and its record are written with no other save of the name between.
448
+ const saved = guard ? await guard.turn(() => this.nameTurn(name, write)) : await this.nameTurn(name, write);
409
449
  await this.store.flush();
410
450
  return this.view(saved);
411
451
  }
452
+ /** `work` in the turn of the saved server `name`, after every save of that name already in it: a save writes its row and
453
+ * then its source record (mcp-sources.ts), so the token's mark, written after its row, never lands on a row an owner's
454
+ * save wrote between the two. One server holds a store (StoreOwned), so the turn is this process's. A delete takes
455
+ * none: its statement compares the mark itself (Mcp.removeIfCredential). */
456
+ async nameTurn(name, work) {
457
+ const mine = (this.nameTurns.get(name) ?? Promise.resolve()).then(work);
458
+ const held = mine.then(() => undefined, () => undefined);
459
+ this.nameTurns.set(name, held);
460
+ try {
461
+ return await mine;
462
+ }
463
+ finally {
464
+ if (this.nameTurns.get(name) === held)
465
+ this.nameTurns.delete(name);
466
+ }
467
+ }
412
468
  /** POST refresh: list the saved server's tools again, keep them, and say what was added, removed and changed. */
413
469
  async refresh(name, stop) {
414
470
  const was = await this.need(name);
@@ -438,10 +494,10 @@ export class McpServersOverStore {
438
494
  /** Writes the owner's change over the row it read (`was`), its credential left as it is, by a compare-and-set on that
439
495
  * credential (store.mcp.rewrite). A lost one (a run kept a refreshed set meanwhile) reads the row again and re-applies the
440
496
  * change onto it, while `still` holds of it, at most REWRITE_TRIES writes; then it is refused in words, nothing written. */
441
- async rewriteKeeping(name, was, fields, doing, still) {
497
+ async rewriteKeeping(name, was, fields, doing, still, owns) {
442
498
  let row = was;
443
499
  for (let tries = 1;; tries++) {
444
- const saved = await rewriteMcpServer(this.store, fields(row), row.sealed, { githubMcpOrigin: this.appOrigin });
500
+ const saved = await rewriteMcpServer(this.store, fields(row), row.sealed, { githubMcpOrigin: this.appOrigin, ...(owns ? { owns } : {}) });
445
501
  if (saved)
446
502
  return saved;
447
503
  const fresh = await this.store.mcp.server(name);
@@ -461,18 +517,24 @@ export class McpServersOverStore {
461
517
  * none: removing it drops no secret); the row goes only while it is still that, in the store's one statement, so a
462
518
  * credential saved meanwhile is never dropped by it. An OAuth one's sign-in is then let go at its authorization server
463
519
  * (its refresh token revoked, RFC 7009, where its metadata names a revocation_endpoint), behind the answer: best effort,
464
- * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check). */
465
- async remove(name, checkedAgainst) {
520
+ * never holding or failing the removal. A claimed run sees the removal at its next call (runner/mcp-claim.ts check).
521
+ * `byToken`: the API token removes it, which it may only while the row is one the token saved (savedByToken): its
522
+ * credential and its mark are compared in the deleting statement itself (Mcp.removeIfCredential), never in a read
523
+ * before it, so an owner's save that lands after the gate's check (it drops the mark in the transaction that writes
524
+ * its row) is never removed, and nothing is sent to Composio for it. */
525
+ async remove(name, checkedAgainst, byToken = false) {
466
526
  const row = await this.need(name);
527
+ // The credential the row goes against: the gate's, else (a token's removal the gate did not read) the one read here.
528
+ const expected = checkedAgainst !== undefined ? checkedAgainst : byToken ? credentialMark(row) : undefined;
467
529
  // Whether it is a Composio preset server: from its record (source composio), read before the row goes.
468
530
  const preset = row.auth === "headers" && (await this.sourceOf(row)).source === "composio";
469
531
  // What it stands on at Composio, as its save recorded it (none: saved before that was recorded, or not a preset).
470
532
  const stands = preset ? recordedMade(await this.store.settings.get(composioMadeKey(name)), row.createdAt) : undefined;
471
533
  // The credential revoked is the one the deleting statement saw (RETURNING): a run's refresh landing before it is in it,
472
534
  // one landing after finds no row to keep. A sign-in kept as expired has no refresh token left to revoke.
473
- const removed = checkedAgainst === undefined ? await removeMcpServer(this.store, this.sealKey, name)
474
- : checkedAgainst === null ? undefined : await removeMcpServerIfCredential(this.store, this.sealKey, name, checkedAgainst);
475
- if (checkedAgainst !== undefined && !removed)
535
+ const removed = expected === undefined ? await removeMcpServer(this.store, this.sealKey, name)
536
+ : expected === null ? undefined : await removeMcpServerIfCredential(this.store, this.sealKey, name, expected, byToken ? { record: mcpSourceKey(name) } : undefined);
537
+ if (expected !== undefined && !removed)
476
538
  changedMeanwhile(name, undefined);
477
539
  // Its record goes with it, unless a server saved again under the name meanwhile wrote its own: one left behind is
478
540
  // never read for another row (mcp-sources.ts), so a server saved again says what it is afresh.
@@ -494,7 +556,7 @@ export class McpServersOverStore {
494
556
  const credential = open && "credential" in open && open.credential.type === "oauth" && !open.credential.expired ? open.credential : undefined;
495
557
  if (credential && removed)
496
558
  void this.track(this.signIns.revoke(credential.set, removed.url, this.stopped.signal));
497
- return preset ? { composio: composioHandleOf(removed, cleanup) } : {};
559
+ return preset ? { composio: composioHandleOf(removed, cleanup, stands?.key_env) } : {};
498
560
  }
499
561
  /** Whether `name` is a Composio preset server now (auth headers, source composio): a save of it takes the Composio turn,
500
562
  * since one that moves it off Composio removes there what the preset made for it. */
@@ -650,6 +712,17 @@ export class McpServersOverStore {
650
712
  * read and checked, never the one saved now: a save at another address with a new credential while the caller waited
651
713
  * (its address check, a listing) must never have that credential sent to the old address. */
652
714
  async opened(name, row, field) {
715
+ // A Composio server saved with api_key_env: its key is its variable's value as the server was started with it
716
+ // (composioKeyFromEnv), refused by name when unset.
717
+ // Sent to Composio's origin alone (composioEnvKey): a row at any other address is refused by name, and nothing is sent.
718
+ const keyEnv = await this.keyEnvOf(row);
719
+ if (keyEnv) {
720
+ const got = composioEnvKey(name, row.url, keyEnv, this.composioOrigin);
721
+ if ("refused" in got)
722
+ throw invalid([{ field, reason: got.reason, message: got.refused }]);
723
+ const headers = { "x-api-key": got.key };
724
+ return { headers, credential: { type: "headers", headers, origin: new URL(row.url).origin }, env: keyEnv };
725
+ }
653
726
  // No credential kept: none for a server that takes none, nor for a github_app server with no static headers, nor for a
654
727
  // per_run server (each run hands its own).
655
728
  if (row.auth === "none" || row.sealed === null)
@@ -665,6 +738,13 @@ export class McpServersOverStore {
665
738
  }
666
739
  return { headers: credential.headers, credential };
667
740
  }
741
+ /** The variable a Composio server saved with api_key_env reads its key from (composio-made.ts key_env): a headers row
742
+ * that seals no credential, whose record for this row names it. None for every other row. */
743
+ async keyEnvOf(row) {
744
+ if (row.auth !== "headers" || row.sealed !== null)
745
+ return undefined;
746
+ return recordedMade(await this.store.settings.get(composioMadeKey(row.name)), row.createdAt)?.key_env;
747
+ }
668
748
  /** The saved OAuth token set of `row` (the row read and checked, as opened), for a sign-in again that reuses the kept
669
749
  * client. */
670
750
  openedSet(row) {
@@ -712,7 +792,9 @@ export class McpServersOverStore {
712
792
  const prices = (row.prices ?? undefined);
713
793
  const listed = marked(row.url, { protocol: row.protocol ?? "unknown", server_info: row.serverInfo ?? null, ...(typeof row.instructions === "string" ? { instructions: row.instructions } : {}), tools });
714
794
  const unmetered = tools.filter((tool) => !(prices && Object.hasOwn(prices, tool.name))).map((tool) => tool.name);
715
- const opened = row.auth === "none" || row.auth === "per_run" || (row.auth === "github_app" && row.sealed === null) ? null : openMcpRow(this.sealKey, row);
795
+ // A key read from the environment (api_key_env) is no credential kept here: its header is named, its value never read.
796
+ const keyEnv = await this.keyEnvOf(row);
797
+ const opened = keyEnv || row.auth === "none" || row.auth === "per_run" || (row.auth === "github_app" && row.sealed === null) ? null : openMcpRow(this.sealKey, row);
716
798
  const cred = opened && "credential" in opened ? opened.credential : undefined;
717
799
  const set = cred?.type === "oauth" ? cred.set : undefined;
718
800
  const expired = cred?.type === "oauth" && cred.expired === true;
@@ -738,12 +820,12 @@ export class McpServersOverStore {
738
820
  return { ...tool, effect, ...serverGate(mcpToolName(name, tool.name), settings, effect), ...grantProblemsOf(this.env, name, tool) };
739
821
  }),
740
822
  ...(unmetered.length ? { not_metered: unmetered } : {}),
741
- auth: { type: row.auth, ...(row.auth === "headers" || row.auth === "github_app" ? { headers: Object.keys((cred?.type === "headers" ? cred.headers : {})) } : {}) },
823
+ auth: { type: row.auth, ...(row.auth === "headers" || row.auth === "github_app" ? { headers: keyEnv ? ["x-api-key"] : Object.keys((cred?.type === "headers" ? cred.headers : {})) } : {}), ...(keyEnv ? { api_key_env: keyEnv } : {}) },
742
824
  credential: opened === null ? null : !cred ? "unreadable" : expired ? "expired" : "sealed",
743
825
  ...(set ? { oauth: { ...(set.expires_at ? { expires_at: set.expires_at } : {}), scopes: (set.tokens.scope ?? "").split(" ").filter(Boolean), client: set.kind, ...(set.client?.client_id ? { client_id: set.client.client_id } : {}) } } : {}),
744
826
  listed_at: listedAt,
745
827
  updated_at: updatedAt,
746
- secret: secretOf(row),
828
+ secret: secretOf(row, keyEnv),
747
829
  };
748
830
  }
749
831
  /** A body's URL, auth and prices, and a save's source and toolkit (`priced`: a save's body), or 422. */
@@ -806,9 +888,11 @@ export function mcpServersOverStore(store, env, version, network) {
806
888
  return new McpServersOverStore(store, env, version, network);
807
889
  }
808
890
  /** The server's credential as every secret is read (SECRETS-PLAN.md): set or not, how it came ("console": pasted, a
809
- * bearer token or headers; "sign-in": an OAuth sign-in; null: none), and the credential's own last change. Never a value.
810
- * An MCP credential never comes from the server's environment. */
811
- function secretOf(row) {
891
+ * bearer token or headers; "sign-in": an OAuth sign-in; "env": a Composio key read from the variable `keyEnv`, set when
892
+ * the variable is set now, with no time; null: none), and the credential's own last change. Never a value. */
893
+ function secretOf(row, keyEnv) {
894
+ if (keyEnv)
895
+ return secretMeta(secretName("mcp", row.name), { set: composioKeyFromEnv(keyEnv) !== undefined, source: "env", changedAt: null });
812
896
  const set = row.sealed !== null && row.auth !== "none";
813
897
  return secretMeta(secretName("mcp", row.name), { set, source: row.auth === "oauth" ? "sign-in" : "console", changedAt: row.credentialChangedAt === null ? null : new Date(row.credentialChangedAt) });
814
898
  }
@@ -17,13 +17,21 @@ export type RecordedRow = {
17
17
  createdAt?: number;
18
18
  };
19
19
  /** The settings value a record is stored as, bound to the server row it was written for. `standIn`: an eval's fake
20
- * standing in for a need (standInGiven), the one record that may say github. */
20
+ * standing in for a need (standInGiven), the one record that may say github. `byToken`: the API token saved the row. */
21
21
  export declare const storedSource: (record: SourceRecord, row: {
22
22
  createdAt: number;
23
- }, standIn?: boolean) => SourceRecord & {
23
+ }, standIn?: boolean, byToken?: boolean) => SourceRecord & {
24
24
  of: number;
25
25
  stand_in?: true;
26
+ by?: "token";
26
27
  };
28
+ /** Whether the stored record `value`, read for the server row created at `createdAt`, says the API token saved that row.
29
+ * No record, one written for another row, or one with no mark: the owner's. */
30
+ export declare const savedByToken: (value: unknown, createdAt: number | undefined) => boolean;
31
+ /** A stored record as it stands once the owner saves over the token's row: the same, without the token's mark. The store
32
+ * writes it so in the owner's write's own transaction (store/sqlite/store.ts dropTokensMark); tests write it to stand for
33
+ * that save. */
34
+ export declare const ownersRecord: (value: Record<string, unknown>) => Record<string, unknown>;
27
35
  /** Whether the stored value `value` was written for another server row than the one created at `createdAt`: a record left
28
36
  * behind, which a removal of this row leaves for the row it is. */
29
37
  export declare const recordedForAnother: (value: unknown, createdAt: number) => boolean;
@@ -19,8 +19,15 @@ export const mcpSourceKey = (name) => `mcp.source/${name}`;
19
19
  const GITHUB = { source: "github", toolkit: "github" };
20
20
  const NONE = { source: "url", toolkit: null };
21
21
  /** The settings value a record is stored as, bound to the server row it was written for. `standIn`: an eval's fake
22
- * standing in for a need (standInGiven), the one record that may say github. */
23
- export const storedSource = (record, row, standIn = false) => ({ ...record, of: row.createdAt, ...(standIn ? { stand_in: true } : {}) });
22
+ * standing in for a need (standInGiven), the one record that may say github. `byToken`: the API token saved the row. */
23
+ export const storedSource = (record, row, standIn = false, byToken = false) => ({ ...record, of: row.createdAt, ...(standIn ? { stand_in: true } : {}), ...(byToken ? { by: "token" } : {}) });
24
+ /** Whether the stored record `value`, read for the server row created at `createdAt`, says the API token saved that row.
25
+ * No record, one written for another row, or one with no mark: the owner's. */
26
+ export const savedByToken = (value, createdAt) => isObject(value) && createdAt !== undefined && value.of === createdAt && value.by === "token";
27
+ /** A stored record as it stands once the owner saves over the token's row: the same, without the token's mark. The store
28
+ * writes it so in the owner's write's own transaction (store/sqlite/store.ts dropTokensMark); tests write it to stand for
29
+ * that save. */
30
+ export const ownersRecord = (value) => Object.fromEntries(Object.entries(value).filter(([field]) => field !== "by"));
24
31
  /** Whether the stored value `value` was written for another server row than the one created at `createdAt`: a record left
25
32
  * behind, which a removal of this row leaves for the row it is. */
26
33
  export const recordedForAnother = (value, createdAt) => isObject(value) && typeof value.of === "number" && value.of !== createdAt;