@parcha/agentrun-serve 0.1.0-beta.45 → 0.1.0-beta.47
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.
- package/CHANGELOG.md +180 -0
- package/NOTICE +4 -0
- package/README.md +283 -47
- package/dist/acp-package.d.ts +35 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +5 -2
- package/dist/adapter-facts.js +6 -3
- package/dist/adapters.d.ts +7 -0
- package/dist/adapters.js +39 -0
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +7 -10
- package/dist/archil-routes.js +2 -1
- package/dist/cap.js +12 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +119 -44
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +9 -75
- package/dist/computers.js +20 -66
- package/dist/console/assets/index-BBFzAxLB.js +715 -0
- package/dist/console/assets/index-BRi-Rgq6.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +73 -0
- package/dist/harness-check.js +489 -0
- package/dist/harness-cursor.d.ts +45 -0
- package/dist/harness-cursor.js +121 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +357 -0
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +62 -2
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +3 -2
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +34 -4
- package/dist/import.js +134 -32
- package/dist/key-refusal.d.ts +1 -0
- package/dist/key-refusal.js +8 -3
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +11 -4
- package/dist/learn/promote.d.ts +77 -4
- package/dist/learn/promote.js +123 -2
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-setting.d.ts +17 -6
- package/dist/learning-setting.js +41 -5
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +1 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +22 -8
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +2 -1
- package/dist/model.js +9 -7
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +326 -41
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +8 -0
- package/dist/page.js +9 -1
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +6 -4
- package/dist/runner/adapter-loop.d.ts +10 -7
- package/dist/runner/adapter-loop.js +57 -22
- package/dist/runner/adapter-run-spec.d.ts +12 -0
- package/dist/runner/adapter-run-spec.js +40 -6
- package/dist/runner/adapters/index.js +16 -0
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +24 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +15 -7
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/conformance/harness.js +19 -8
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +81 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +41 -0
- package/dist/runner/presence.js +89 -0
- package/dist/runner/promotion.d.ts +10 -3
- package/dist/runner/promotion.js +42 -21
- package/dist/runner/run-child-host.js +52 -14
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runs-over-store.d.ts +6 -2
- package/dist/runs-over-store.js +14 -4
- package/dist/sdk/runs.d.ts +1 -1
- package/dist/sdk/runs.js +6 -1
- package/dist/sdk/schema.js +1 -1
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +31 -2
- package/dist/server.js +326 -53
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +106 -27
- package/dist/store/store.d.ts +75 -23
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +123 -14
- package/dist/store-view.js +154 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/templates.d.ts +6 -3
- package/dist/templates.js +38 -3
- package/dist/timeline/timeline.js +18 -0
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.js +2 -2
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +19 -8
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +2 -1
- package/dist/webhooks.d.ts +85 -9
- package/dist/webhooks.js +129 -46
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +18 -14
- package/dist/workspace/resolve-computer.js +47 -60
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/templates/inbound-lead/agent.md +2 -1
- package/templates/kyb/agent.md +2 -1
- package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
- package/dist/console/assets/index-DaFsZuzQ.css +0 -1
package/dist/listen-first.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
// server is warming. GET /v2/health says so (503, status "warming", the store "opening"), the API answers 503
|
|
5
5
|
// `unavailable` with a Retry-After, and a browser gets a page that reloads itself. Only node's own modules load here.
|
|
6
6
|
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
7
8
|
import { statfs } from "node:fs/promises";
|
|
8
9
|
import { createServer } from "node:http";
|
|
10
|
+
import { networkInterfaces } from "node:os";
|
|
9
11
|
/** The port a server takes when none is named: the first free one from here (cli.ts). */
|
|
10
12
|
export const DEFAULT_PORT = 7340;
|
|
11
13
|
/** The address a server listens on when none is named: this machine only. */
|
|
@@ -43,9 +45,31 @@ export async function listenOn(server, host, first, nextFreePort) {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
const everyAddress = (host) => host === "0.0.0.0" || host === "::";
|
|
49
|
+
// A container network's bridge (Docker's, a VM's) is this machine's alone: no other machine reaches it there.
|
|
50
|
+
const BRIDGES = /^(docker|br-|veth|virbr|cni|flannel|vmnet|bridge\d)/;
|
|
51
|
+
const inContainer = () => existsSync("/.dockerenv") || existsSync("/run/.containerenv");
|
|
52
|
+
/** Where a server listening on every address (`host` 0.0.0.0 or ::) at `port` is reached from another machine: this
|
|
53
|
+
* machine's own IPv4 addresses, loopback, link-local and container bridges left out, at most three. None for a server on one address, and
|
|
54
|
+
* none in a container, whose addresses are its own network's, not the ones its host publishes the port on. None on a
|
|
55
|
+
* machine that cannot list its addresses: the links are a convenience, never a reason not to start. `interfaces` and
|
|
56
|
+
* `container` are the tests'. */
|
|
57
|
+
export function elsewhereOf(host, port, { interfaces = networkInterfaces, container = inContainer } = {}) {
|
|
58
|
+
if (!everyAddress(host) || container())
|
|
59
|
+
return [];
|
|
60
|
+
let found;
|
|
61
|
+
try {
|
|
62
|
+
found = interfaces();
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const addresses = Object.entries(found).filter(([name]) => !BRIDGES.test(name)).flatMap(([, list]) => (list ?? []).filter((one) => one.family === "IPv4" && !one.internal && !one.address.startsWith("169.254.")).map((one) => one.address));
|
|
68
|
+
return [...new Set(addresses)].slice(0, 3).map((address) => `http://${address}:${port}`);
|
|
69
|
+
}
|
|
46
70
|
/** The URL a listening `server` on `host` is reached at on this machine: an address of every interface at its loopback one. */
|
|
47
71
|
export function urlOf(server, host) {
|
|
48
|
-
const shown = host
|
|
72
|
+
const shown = everyAddress(host) ? "127.0.0.1" : host;
|
|
49
73
|
return `http://${shown.includes(":") ? `[${shown}]` : shown}:${server.address().port}`;
|
|
50
74
|
}
|
|
51
75
|
const PAGE = `<!doctype html>
|
package/dist/llms.txt
CHANGED
|
@@ -17,7 +17,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
|
|
|
17
17
|
- `POST /v2/agents` with `{definition: {name, instructions, tools, harness?, model?, thinking?}}` makes an agent (a workflow one holds `workflow` in place of `instructions`). A refusal is `422 input_invalid` naming each field. `PUT /v2/agents/{id}/definition` makes its next revision.
|
|
18
18
|
- `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
|
|
19
19
|
- `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
|
|
20
|
-
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends).
|
|
20
|
+
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
|
|
21
21
|
- An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its audit's shadow run and its share of its workflow revision's compile turn and check, spread over the revision's first `compile_after` served runs; a compile that kept no draft is on no run, in the bill's `unattributed_usd`), `cost.all_in_usd` both. A shadow run is in no run list and sends no webhook. `GET /v2/agents/{id}/learning/cost` has the agent's whole bill (`bill`).
|
|
22
22
|
- `GET /v2/runs/{id}/timeline?after=0&limit=100` pages its steps; follow `next_after` until a page is `final` with `has_more` false.
|
|
23
23
|
- `GET /v2/runs/{id}/files`, then `GET /v2/runs/{id}/files/{path}`: what it wrote.
|
package/dist/mcp-gateway.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export type McpPin = Record<string, {
|
|
|
15
15
|
/** Each granted server's URL now, and its credential's headers when that URL is the pinned one (the claim step's). */
|
|
16
16
|
export type McpCredentials = Record<string, {
|
|
17
17
|
url: string;
|
|
18
|
-
headers?: Record<string, string>; /**
|
|
18
|
+
headers?: Record<string, string>; /** What every request to it adds to its address's query for this run alone: a per-run Composio server's Composio user and connected account (the run's mcp_auth binding), never stored, held for the scrub as headers are. */
|
|
19
|
+
query?: Record<string, string>; /** Why its saved credential did not open: its calls are refused unsent. */
|
|
19
20
|
unopened?: string; /** When its credential ends (ms): a token minted for the run's launch (a github_app server's), whose calls past it are refused unsent, in words. */
|
|
20
21
|
expires_at?: number;
|
|
21
22
|
}>;
|
package/dist/mcp-gateway.js
CHANGED
|
@@ -184,6 +184,8 @@ const until = (work, signal) => new Promise((resolve, reject) => {
|
|
|
184
184
|
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", stop));
|
|
185
185
|
});
|
|
186
186
|
export function mcpGateway(options) {
|
|
187
|
+
/** Each server's client, with the account query it was connected with (`query`, JSON): a message that binds the run to
|
|
188
|
+
* another account connects again, so no session made as one account carries another's calls. */
|
|
187
189
|
const clients = new Map();
|
|
188
190
|
const pins = new Map(Object.entries(options.pin));
|
|
189
191
|
const credentials = { get: (server) => (Object.hasOwn(options.credentials, server) ? options.credentials[server] : undefined) };
|
|
@@ -202,6 +204,8 @@ export function mcpGateway(options) {
|
|
|
202
204
|
values.add(value);
|
|
203
205
|
return headers;
|
|
204
206
|
};
|
|
207
|
+
/** The run's account query of `server` now (none for a server that takes none). */
|
|
208
|
+
const queryOf = (server) => credentials.get(server)?.query ?? {};
|
|
205
209
|
/** A call's own set, held while it is out (released by the call's end). */
|
|
206
210
|
const callSet = (server) => {
|
|
207
211
|
const values = new Set();
|
|
@@ -220,9 +224,17 @@ export function mcpGateway(options) {
|
|
|
220
224
|
};
|
|
221
225
|
/** A call's scrub: the headers it took, every value its server's requests took or sent while it was out, and its
|
|
222
226
|
* credential now. */
|
|
223
|
-
const scrubberOf = (server, headers, values) => (text) => scrub(text, [...Object.values(headers), ...values, ...Object.values(credentials.get(server)?.headers ?? {})]);
|
|
227
|
+
const scrubberOf = (server, headers, values) => (text) => scrub(text, [...Object.values(headers), ...values, ...Object.values(credentials.get(server)?.headers ?? {}), ...Object.values(queryOf(server))]);
|
|
224
228
|
/** The fetch one server's client sends with: its credential added, no redirect followed, at most MAX_RESPONSE read. */
|
|
225
|
-
const guarded = (server, headers, status) => async (input, init = {}) => {
|
|
229
|
+
const guarded = (server, headers, status, query = {}) => async (input, init = {}) => {
|
|
230
|
+
// The account its client was connected as, set over whatever the request's address says, and held for the scrub.
|
|
231
|
+
if (Object.keys(query).length) {
|
|
232
|
+
hold(server, query);
|
|
233
|
+
const at = new URL(input instanceof Request ? input.url : String(input));
|
|
234
|
+
for (const [name, value] of Object.entries(query))
|
|
235
|
+
at.searchParams.set(name, value);
|
|
236
|
+
input = input instanceof Request ? new Request(at, input) : at.href;
|
|
237
|
+
}
|
|
226
238
|
// Its address checked first, every request: a name that resolves somewhere private now is refused before anything
|
|
227
239
|
// (its credential among it) leaves, and the request is dialled at the address checked.
|
|
228
240
|
let through = send;
|
|
@@ -245,19 +257,22 @@ export function mcpGateway(options) {
|
|
|
245
257
|
return capped(response);
|
|
246
258
|
};
|
|
247
259
|
const connect = (server, url, headers) => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
upstream
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
})();
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
260
|
+
const query = queryOf(server);
|
|
261
|
+
const key = JSON.stringify(query);
|
|
262
|
+
const held = clients.get(server);
|
|
263
|
+
if (held && held.query === key)
|
|
264
|
+
return held.upstream;
|
|
265
|
+
const status = {};
|
|
266
|
+
statuses.set(server, status);
|
|
267
|
+
const upstream = (async () => {
|
|
268
|
+
const { client, transport } = mcpClient(await import("@modelcontextprotocol/client"), { name: "agentrun", version: "1.0.0", url: new URL(url), fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status, query) });
|
|
269
|
+
await client.connect(transport, { timeout: options.bounds?.connectMs ?? CONNECT_MS });
|
|
270
|
+
return client;
|
|
271
|
+
})();
|
|
272
|
+
const made = { query: key, upstream };
|
|
273
|
+
clients.set(server, made);
|
|
274
|
+
// A server that did not connect is tried again at the next call.
|
|
275
|
+
upstream.catch(() => clients.get(server) === made && clients.delete(server));
|
|
261
276
|
return upstream;
|
|
262
277
|
};
|
|
263
278
|
/** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
|
|
@@ -305,6 +320,7 @@ export function mcpGateway(options) {
|
|
|
305
320
|
// Read at each use: a token refreshed while the call is out, and sent, is scrubbed with the one it took.
|
|
306
321
|
const held = callSet(server);
|
|
307
322
|
const clean = scrubberOf(server, hold(server, headers), held.values);
|
|
323
|
+
hold(server, queryOf(server));
|
|
308
324
|
try {
|
|
309
325
|
const upstream = await until(connect(server, url, headers), signal);
|
|
310
326
|
connected = true;
|
package/dist/mcp-probe.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
|
+
import type { ComposioBinding } from "./store/seal.js";
|
|
2
3
|
/** `per_run`: the server keeps no credential; each run's caller hands one with the run (mcp_auth), held for that run alone. */
|
|
3
4
|
export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app", "per_run"];
|
|
4
5
|
/** Why a saved credential can't be used for a run's calls, each with its own remedy and no other, as the model reads it
|
|
@@ -78,8 +79,11 @@ export declare function marked<Tool extends {
|
|
|
78
79
|
};
|
|
79
80
|
/** JSON with sorted keys, so two listings of one tool compare equal whatever order the server sends its fields in. */
|
|
80
81
|
export declare const canonical: (value: unknown) => string;
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
82
|
+
/** A tool's price in USD a call, as every save takes one (an owner's `prices`, the Composio preset's `price_usd`): a
|
|
83
|
+
* finite number, 0 or more. */
|
|
84
|
+
export declare const priceValid: (usd: unknown) => usd is number;
|
|
85
|
+
/** The body's prices: each tool's USD a call (priceValid). Which tools the server lists is checked once it has listed
|
|
86
|
+
* them. */
|
|
83
87
|
export declare function pricesOf(value: unknown, issues: InputIssue[]): McpPrices | undefined;
|
|
84
88
|
/** Query parameter names that look like a credential, compared lowercase with every "-" and "_" gone: an MCP server's url
|
|
85
89
|
* is kept and shown in plain text (its row's url, every read, the console), so a credential belongs in a header. Only
|
|
@@ -100,10 +104,18 @@ export declare const credentialInQueryWords: (name: string) => string;
|
|
|
100
104
|
export declare function urlOf(value: unknown, issues: InputIssue[]): URL | undefined;
|
|
101
105
|
/** The body's auth: its type and, when it sends one, its credential as the headers it becomes. */
|
|
102
106
|
export declare function authOf(value: unknown, issues: InputIssue[]): Auth | undefined;
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
/** What a run hands one MCP server in `mcp_auth`: a per_run server's headers, or a per-run Composio server's binding. */
|
|
108
|
+
export type HandedMcp = {
|
|
109
|
+
readonly headers: HeaderMap;
|
|
110
|
+
} | {
|
|
111
|
+
readonly composio: ComposioBinding;
|
|
112
|
+
};
|
|
113
|
+
/** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages), by server: the headers each named
|
|
114
|
+
* per_run server is called with for this run, `{"<server>": {"headers": {...}}}`, or the Composio user (and connected
|
|
115
|
+
* account) a per-run Composio server's calls run as, `{"<server>": {"composio_user_id": "...", "connected_account_id":
|
|
116
|
+
* "ca_..."}}`. Checked for shape here; that each name is a saved server that takes that shape is the caller's check.
|
|
117
|
+
* Undefined when absent or wrong (with its issues). */
|
|
118
|
+
export declare function mcpAuthOf(value: unknown, issues: InputIssue[]): Record<string, HandedMcp> | undefined;
|
|
107
119
|
/** The OAuth scope list a sign-in body may send: 1 to 32 OAuth scopes. */
|
|
108
120
|
export declare const scopesValid: (scopes: unknown) => boolean;
|
|
109
121
|
/** The longest an OAuth client id or secret a sign-in body may send. */
|
package/dist/mcp-probe.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// Nothing here opens a credential or touches a store: listServer connects to a URL with the official SDK client, agrees a
|
|
6
6
|
// protocol revision and lists every tool (all pages, under caps); the validation turns a request body into a URL, auth and
|
|
7
7
|
// prices, or a 422; no redirect is followed, so a credential goes only where the owner sends it.
|
|
8
|
+
import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID } from "./composio-preset.js";
|
|
8
9
|
import { ApiError, invalid } from "./errors.js";
|
|
9
10
|
import { metaToolOf } from "./mcp-meta.js";
|
|
10
11
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
@@ -92,14 +93,17 @@ export function marked(url, listed) {
|
|
|
92
93
|
export const canonical = (value) => Array.isArray(value) ? `[${value.map(canonical).join(",")}]`
|
|
93
94
|
: isObject(value) ? `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`
|
|
94
95
|
: JSON.stringify(value) ?? "null";
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
96
|
+
/** A tool's price in USD a call, as every save takes one (an owner's `prices`, the Composio preset's `price_usd`): a
|
|
97
|
+
* finite number, 0 or more. */
|
|
98
|
+
export const priceValid = (usd) => typeof usd === "number" && Number.isFinite(usd) && usd >= 0;
|
|
99
|
+
/** The body's prices: each tool's USD a call (priceValid). Which tools the server lists is checked once it has listed
|
|
100
|
+
* them. */
|
|
97
101
|
export function pricesOf(value, issues) {
|
|
98
102
|
if (value === undefined)
|
|
99
103
|
return undefined;
|
|
100
104
|
if (!isObject(value))
|
|
101
105
|
return void issues.push({ field: "prices", reason: "wrong_type", message: "prices is an object of the server's tool names to their price in USD a call." });
|
|
102
|
-
const bad = Object.entries(value).filter(([, usd]) =>
|
|
106
|
+
const bad = Object.entries(value).filter(([, usd]) => !priceValid(usd));
|
|
103
107
|
for (const [tool] of bad)
|
|
104
108
|
issues.push({ field: `prices.${tool}`, reason: "invalid", message: `prices.${tool} is a price in USD a call: a finite number, 0 or more.` });
|
|
105
109
|
// Keyed by tool names, which may be an object's own properties (`__proto__`): no prototype to fall into.
|
|
@@ -230,13 +234,15 @@ function headersOf(field, value, issues, noAuthorization) {
|
|
|
230
234
|
}
|
|
231
235
|
/** The most servers one mcp_auth names. */
|
|
232
236
|
const MAX_MCP_AUTH_SERVERS = 8;
|
|
233
|
-
/** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages): the headers each named
|
|
234
|
-
* server is called with for this run, `{"<server>": {"headers": {...}}}
|
|
235
|
-
*
|
|
237
|
+
/** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages), by server: the headers each named
|
|
238
|
+
* per_run server is called with for this run, `{"<server>": {"headers": {...}}}`, or the Composio user (and connected
|
|
239
|
+
* account) a per-run Composio server's calls run as, `{"<server>": {"composio_user_id": "...", "connected_account_id":
|
|
240
|
+
* "ca_..."}}`. Checked for shape here; that each name is a saved server that takes that shape is the caller's check.
|
|
241
|
+
* Undefined when absent or wrong (with its issues). */
|
|
236
242
|
export function mcpAuthOf(value, issues) {
|
|
237
243
|
if (value === undefined)
|
|
238
244
|
return undefined;
|
|
239
|
-
const shape = 'mcp_auth is {"<server>": {"headers": {"<name>": "<value>"}}}, one entry for each
|
|
245
|
+
const shape = 'mcp_auth is {"<server>": {"headers": {"<name>": "<value>"}}} for a per_run MCP server, or {"<server>": {"composio_user_id": "<user>", "connected_account_id": "ca_..."}} for a per-run Composio server (the account optional), one entry for each such server the run calls.';
|
|
240
246
|
if (!isObject(value) || !Object.keys(value).length || Object.keys(value).length > MAX_MCP_AUTH_SERVERS)
|
|
241
247
|
return void issues.push({ field: "mcp_auth", reason: isObject(value) ? "invalid" : "wrong_type", message: `${shape} It names 1 to ${MAX_MCP_AUTH_SERVERS} servers.` });
|
|
242
248
|
const before = issues.length;
|
|
@@ -249,11 +255,38 @@ export function mcpAuthOf(value, issues) {
|
|
|
249
255
|
issues.push({ field, reason: "wrong_type", message: shape });
|
|
250
256
|
continue;
|
|
251
257
|
}
|
|
258
|
+
if (entry.composio_user_id !== undefined || entry.connected_account_id !== undefined) {
|
|
259
|
+
const binding = composioBindingOf(field, entry, issues);
|
|
260
|
+
if (binding)
|
|
261
|
+
out[server] = { composio: binding };
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
252
264
|
issues.push(...unknownFields(entry, ["headers"]).map((issue) => ({ ...issue, field: `${field}.${issue.field}` })));
|
|
253
|
-
out[server] = headersOf(`${field}.headers`, entry.headers, issues);
|
|
265
|
+
out[server] = { headers: headersOf(`${field}.headers`, entry.headers, issues) };
|
|
254
266
|
}
|
|
255
267
|
return issues.length > before ? undefined : out;
|
|
256
268
|
}
|
|
269
|
+
/** A per-run Composio server's binding at `field`: `composio_user_id`, a Composio user id; `connected_account_id`, when
|
|
270
|
+
* given, a Composio connected account's id (ca_...). No headers: the server's key is its own. A refusal never quotes
|
|
271
|
+
* what was sent. */
|
|
272
|
+
function composioBindingOf(field, entry, issues) {
|
|
273
|
+
const before = issues.length;
|
|
274
|
+
if (entry.headers !== undefined)
|
|
275
|
+
issues.push({ field: `${field}.headers`, reason: "not_allowed", message: "A binding to a Composio account sends no headers: the server's Composio key is its own." });
|
|
276
|
+
issues.push(...unknownFields(entry, ["composio_user_id", "connected_account_id", "headers"]).map((issue) => ({ ...issue, field: `${field}.${issue.field}` })));
|
|
277
|
+
const user = entry.composio_user_id;
|
|
278
|
+
const account = entry.connected_account_id;
|
|
279
|
+
if (typeof user !== "string" || !COMPOSIO_USER_ID.test(user))
|
|
280
|
+
issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message: "composio_user_id is the Composio user this run's calls run as: letters, digits and . _ @ - (1 to 128)." });
|
|
281
|
+
// The preset's default user is the one single-user preset servers call as: a run that forgot to name its own never lands there.
|
|
282
|
+
else if (user === COMPOSIO_USER)
|
|
283
|
+
issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is the Composio preset's shared default user, the one single-user preset servers call as: bind the run to its own person's Composio user." });
|
|
284
|
+
if (account !== undefined && (typeof account !== "string" || !COMPOSIO_ACCOUNT_ID.test(account)))
|
|
285
|
+
issues.push({ field: `${field}.connected_account_id`, reason: "invalid", message: "connected_account_id is a Composio connected account's id: ca_ and 5 to 64 letters, digits, _ or -." });
|
|
286
|
+
if (issues.length > before)
|
|
287
|
+
return undefined;
|
|
288
|
+
return { user_id: user, ...(account !== undefined ? { connected_account_id: account } : {}) };
|
|
289
|
+
}
|
|
257
290
|
/** The OAuth scope list a sign-in body may send: 1 to 32 OAuth scopes. */
|
|
258
291
|
export const scopesValid = (scopes) => Array.isArray(scopes) && scopes.length > 0 && scopes.length <= 32 && scopes.every((scope) => typeof scope === "string" && SCOPE.test(scope));
|
|
259
292
|
/** The longest an OAuth client id or secret a sign-in body may send. */
|
|
@@ -20,4 +20,12 @@ export declare function mcpSaveDropsSecret(body: unknown, request: SecretRequest
|
|
|
20
20
|
export declare function mcpDeleteDropsSecret(_body: unknown, request: SecretRequest): Promise<boolean>;
|
|
21
21
|
/** MCP's operations the one gate reads: the predicates above decide each request. */
|
|
22
22
|
export declare const MCP_SECRET_OPERATIONS: readonly ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
|
|
23
|
+
/** 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
|
+
* characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
|
|
25
|
+
* nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
|
|
26
|
+
* name or value, no key spanning path segments or a query's separators (spansKey), and no host label that could be an id.
|
|
27
|
+
* Its fragment is dropped. Anything else is left out whole, and the person pastes it in the console. */
|
|
28
|
+
export declare function linkableUrl(value: unknown): string | undefined;
|
|
29
|
+
/** `operation`'s console page, built from the request (see above). */
|
|
30
|
+
export declare const mcpSecretPage: (operation: string) => (body: unknown, request: SecretRequest) => Promise<string>;
|
|
23
31
|
export {};
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
// since they widen where a sign-in sends its code and tokens.
|
|
10
10
|
// A server with no credential, a save that keeps the sealed one (prices, tools, url), a preview and a refresh (each keeps
|
|
11
11
|
// nothing new) stay open to a token.
|
|
12
|
-
import {
|
|
12
|
+
import { COMPOSIO_TOOLKIT } from "./composio-preset.js";
|
|
13
|
+
import { secretShapes } from "./learn/secrets.js";
|
|
14
|
+
import { urlOf } from "./mcp-probe.js";
|
|
15
|
+
import { registerNotSecretWrite, registerSecretPage, registerSecretWrite } from "./secret-writes.js";
|
|
16
|
+
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
13
17
|
import { isObject } from "./validate.js";
|
|
14
18
|
/** Whether `operation`'s `body` writes an MCP secret by the body alone (see above). */
|
|
15
19
|
export function mcpWritesSecret(operation, body) {
|
|
@@ -58,9 +62,6 @@ export const MCP_SECRET_OPERATIONS = ["saveMcpServer", "startMcpOAuth", "putMcpP
|
|
|
58
62
|
const STORED = { saveMcpServer: mcpSaveDropsSecret, deleteMcpServer: mcpDeleteDropsSecret };
|
|
59
63
|
for (const operation of MCP_SECRET_OPERATIONS)
|
|
60
64
|
registerSecretWrite(operation, (body) => mcpWritesSecret(operation, body), STORED[operation]);
|
|
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
|
-
// registered all the same.
|
|
63
|
-
registerSecretWrite("previewMcpServer", () => false);
|
|
64
65
|
// 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
66
|
// whatever the body (the listing sends the key too, and only the session may type one).
|
|
66
67
|
registerSecretWrite("listComposioTools", () => true);
|
|
@@ -69,3 +70,102 @@ registerSecretWrite("saveComposioServer", () => true);
|
|
|
69
70
|
registerSecretWrite("rotateComposioSecret", () => true);
|
|
70
71
|
registerSecretWrite("deleteComposioSubscription", () => true);
|
|
71
72
|
registerNotSecretWrite("refreshMcpServer", "A refresh lists the saved server's tools again with its sealed credential, and writes no credential.");
|
|
73
|
+
registerNotSecretWrite("previewMcpServer", "A preview lists a server's tools and keeps nothing.");
|
|
74
|
+
// ---- where a refused MCP secret write is finished ---------------------------------------------------------------------
|
|
75
|
+
//
|
|
76
|
+
// The console's Settings → MCP servers (`/#/settings/mcp`). A save or a sign-in's start opens its form filled with what
|
|
77
|
+
// the request held that is no secret (the console reads these: apps/console src/lib/mcp.ts addOf): `add=<name>` for a new
|
|
78
|
+
// server, `change=<name>` for a saved one (its Change form, so the save lands on it and never on a `<name>-2`); `url`,
|
|
79
|
+
// only when nothing in it could be a credential (linkableUrl); `auth`, the kind of credential (never one); `toolkit`.
|
|
80
|
+
// A Composio save or listing opens the Composio form with its toolkit and the actions to tick. Never a token, a header's
|
|
81
|
+
// name or value, a client id or secret, a Composio key.
|
|
82
|
+
/** A path segment, query name or value, or name shaped like a key: 20 or more characters of a token's alphabet, with a
|
|
83
|
+
* digit or both cases of letter in it (a Zapier-style /mcp/<key>/sse, a UUID, base64). A plain word or a dashed name
|
|
84
|
+
* ("streamable-http-endpoint") is none. */
|
|
85
|
+
const keyShaped = (part) => /^[A-Za-z0-9_\-+/=.~%]{20,}$/.test(part) && (/\d/.test(part) || (/[a-z]/.test(part) && /[A-Z]/.test(part)));
|
|
86
|
+
/** Whether `text` holds a key that spans separators: base64's alphabet has "/" and "+", so one key can cross path segments
|
|
87
|
+
* (`aB3dE5gH7jK9mN2p/Q4rS6tU8vW0xY2z4`, each piece too short to look like one) or read as two words once a query's "+"
|
|
88
|
+
* is decoded. Any run of 20 or more base64 characters, separators counted, with both cases of letter in it. A path of
|
|
89
|
+
* plain lowercase words and digits ("/mcp/v1/sse/stream/events") is none. */
|
|
90
|
+
const spansKey = (text) => (text.match(/[A-Za-z0-9+/=]{20,}/g) ?? []).some((run) => /[a-z]/.test(run) && /[A-Z]/.test(run));
|
|
91
|
+
/** Whether a host's label could be an unguessable id (a per-person subdomain): 20 or more letters and digits in a row with
|
|
92
|
+
* a digit in them, or a UUID. */
|
|
93
|
+
const hostKeyed = (label) => (label.match(/[a-z0-9]{20,}/g) ?? []).some((run) => /\d/.test(run)) || /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/.test(label);
|
|
94
|
+
const decoded = (part) => {
|
|
95
|
+
try {
|
|
96
|
+
return decodeURIComponent(part);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return part;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
|
|
103
|
+
* characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
|
|
104
|
+
* nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
|
|
105
|
+
* name or value, no key spanning path segments or a query's separators (spansKey), and no host label that could be an id.
|
|
106
|
+
* Its fragment is dropped. Anything else is left out whole, and the person pastes it in the console. */
|
|
107
|
+
export function linkableUrl(value) {
|
|
108
|
+
if (typeof value !== "string")
|
|
109
|
+
return undefined;
|
|
110
|
+
const issues = [];
|
|
111
|
+
const url = urlOf(value, issues);
|
|
112
|
+
if (!url || issues.length || secretShapes(value).length || secretShapes(decoded(value)).length)
|
|
113
|
+
return undefined;
|
|
114
|
+
const parts = [...url.pathname.split("/"), ...[...url.searchParams].flat()];
|
|
115
|
+
if (parts.some((part) => keyShaped(part) || keyShaped(decoded(part)) || keyShaped(part.replace(/\s+/g, ""))))
|
|
116
|
+
return undefined;
|
|
117
|
+
if ([url.pathname, decoded(url.pathname), url.search, decoded(url.search)].some(spansKey))
|
|
118
|
+
return undefined;
|
|
119
|
+
return url.hostname.split(".").some(hostKeyed) ? undefined : url.href;
|
|
120
|
+
}
|
|
121
|
+
/** A server's name or a toolkit as a link may carry it: a name a server can have, and not key-shaped. */
|
|
122
|
+
const linkName = (value) => (typeof value === "string" && MCP_SERVER_NAME.test(value) && !keyShaped(value) ? value : undefined);
|
|
123
|
+
/** The kinds of credential the console's form can fill. `per_run` (and anything else) it cannot: such a save's link opens
|
|
124
|
+
* the page alone, since a form filled otherwise would save another kind than the one asked for. */
|
|
125
|
+
const AUTH_TYPES = new Set(["none", "bearer", "headers", "oauth", "github_app"]);
|
|
126
|
+
const MCP_PAGE = "/#/settings/mcp";
|
|
127
|
+
/** `operation`'s console page, built from the request (see above). */
|
|
128
|
+
export const mcpSecretPage = (operation) => async (body, request) => {
|
|
129
|
+
const given = isObject(body) ? body : {};
|
|
130
|
+
const toolkit = linkName(given.toolkit);
|
|
131
|
+
const servers = request.store.mcp;
|
|
132
|
+
if (operation === "listComposioTools" || operation === "saveComposioServer") {
|
|
133
|
+
// The toolkit as the preset takes it (composio-preset.ts: trimmed, lower-cased, Composio's slug rule, which allows
|
|
134
|
+
// "_" and 64 characters); a listing names no server, so its link's name is that toolkit as a server's name can be.
|
|
135
|
+
const slug = typeof given.toolkit === "string" ? given.toolkit.trim().toLowerCase() : "";
|
|
136
|
+
const composio = COMPOSIO_TOOLKIT.test(slug) && !keyShaped(slug) ? slug : undefined;
|
|
137
|
+
const name = linkName(operation === "saveComposioServer" ? request.params[0] : composio?.replace(/_/g, "-").slice(0, 32));
|
|
138
|
+
if (!name || !composio)
|
|
139
|
+
return MCP_PAGE;
|
|
140
|
+
// A save over a saved server's name replaces that server: `change`, so the console saves under the name asked for and
|
|
141
|
+
// never moves it to a free `<name>-2` beside the old one. A listing names no server, so it is always a new one's.
|
|
142
|
+
const replaces = operation === "saveComposioServer" && (await servers.server(name)) !== undefined;
|
|
143
|
+
const query = new URLSearchParams({ [replaces ? "change" : "add"]: name, preset: "composio", toolkit: composio });
|
|
144
|
+
const tools = Array.isArray(given.tools) ? given.tools.filter((tool) => typeof tool === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(tool) && !keyShaped(tool)).slice(0, 64) : [];
|
|
145
|
+
if (tools.length)
|
|
146
|
+
query.set("tools", tools.join(","));
|
|
147
|
+
return `${MCP_PAGE}?${query}`;
|
|
148
|
+
}
|
|
149
|
+
if (operation !== "saveMcpServer" && operation !== "startMcpOAuth")
|
|
150
|
+
return MCP_PAGE;
|
|
151
|
+
const name = linkName(request.params[0]);
|
|
152
|
+
if (!name)
|
|
153
|
+
return MCP_PAGE;
|
|
154
|
+
// The kind of credential the request asks for. A save with no auth asks for none (mcp-probe authOf), which the link says
|
|
155
|
+
// so a Change form never falls back to the saved kind and keeps the credential the save would have dropped.
|
|
156
|
+
const asked = operation === "startMcpOAuth" ? "oauth" : given.auth === undefined ? "none" : isObject(given.auth) ? given.auth.type : undefined;
|
|
157
|
+
if (typeof asked !== "string" || !AUTH_TYPES.has(asked))
|
|
158
|
+
return MCP_PAGE;
|
|
159
|
+
const saved = await servers.server(name);
|
|
160
|
+
const query = new URLSearchParams({ [saved ? "change" : "add"]: name });
|
|
161
|
+
const url = linkableUrl(given.url);
|
|
162
|
+
if (url)
|
|
163
|
+
query.set("url", url);
|
|
164
|
+
query.set("auth", asked);
|
|
165
|
+
if (toolkit)
|
|
166
|
+
query.set("toolkit", toolkit);
|
|
167
|
+
return `${MCP_PAGE}?${query}`;
|
|
168
|
+
};
|
|
169
|
+
for (const operation of ["saveMcpServer", "startMcpOAuth", "listComposioTools", "saveComposioServer"])
|
|
170
|
+
registerSecretPage(operation, mcpSecretPage(operation));
|
|
171
|
+
registerSecretPage(["putMcpPrivateHosts", "deleteMcpServer", "rotateComposioSecret", "deleteComposioSubscription"], MCP_PAGE);
|
|
@@ -5,6 +5,7 @@ import { type Cleanup, 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
7
|
import { type McpCredentialMark, type Mcp, type McpOauth, type Settings, type Store } from "./store/index.js";
|
|
8
|
+
import { MCP_ALLOW_LOOPBACK_ENV } from "./start-switches.js";
|
|
8
9
|
/** The store slice this layer reads and writes; `settings` for the private-network OAuth hosts the owner allows and each
|
|
9
10
|
* server's source and toolkit (mcp-sources.ts). */
|
|
10
11
|
type McpServersStore = {
|
|
@@ -356,7 +357,11 @@ export declare class McpServersOverStore {
|
|
|
356
357
|
* kept). Answers where to send the browser; 400 for a state that is unknown, used or expired. */
|
|
357
358
|
oauthCallback(query: URLSearchParams, stop?: AbortSignal): Promise<string>;
|
|
358
359
|
private callback;
|
|
360
|
+
/** `perRun`: the server is a per-run Composio server, whose saved address names no user, which Composio refuses even
|
|
361
|
+
* for a listing: listed as composio-preset.ts COMPOSIO_LISTING_USER, at that address alone. */
|
|
359
362
|
private listServer;
|
|
363
|
+
/** Whether the saved server `row` (named `name`) is a per-run Composio server (composio-made.ts composioPerRun). */
|
|
364
|
+
private perRunComposio;
|
|
360
365
|
/** 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
|
|
361
366
|
* it): a github_app server anywhere but GitHub's hosted MCP (GITHUB_MCP_ONLY, as withAppToken says), and at it, as it
|
|
362
367
|
* is, since that one origin is this server's to name, never the owner's; any other server held to the address rule
|
|
@@ -373,13 +378,15 @@ export declare class McpServersOverStore {
|
|
|
373
378
|
* client. */
|
|
374
379
|
private openedSet;
|
|
375
380
|
/** A saved Composio preset server's key (its sealed x-api-key), the Composio user its address names (`user_id`, the
|
|
376
|
-
* preset's default when none)
|
|
381
|
+
* preset's default when none), its toolkit and the auth config its save recorded (composio-made.ts; none for a server
|
|
382
|
+
* saved before that was recorded): what its Composio triggers are made with (composio-triggers.ts). Refused
|
|
377
383
|
* when `name` is no such server: on the trigger's `source.server` at its create (`field`), as a 404 on the server's own
|
|
378
384
|
* routes (`route`). The key goes only to Composio. */
|
|
379
385
|
composioOf(name: string, refusal: "field" | "route"): Promise<{
|
|
380
386
|
key: string;
|
|
381
387
|
user: string;
|
|
382
388
|
toolkit: string;
|
|
389
|
+
auth_config?: string;
|
|
383
390
|
}>;
|
|
384
391
|
/** What the saved server `row` is, for a template's apply to match (mcp-sources.ts sourceOf): github on the GitHub App's
|
|
385
392
|
* tokens, else its record, else url with none. */
|
|
@@ -393,11 +400,10 @@ export declare class McpServersOverStore {
|
|
|
393
400
|
* is checked first (githubMcpUrl), so a row saved at another address never gets a token minted or sent. */
|
|
394
401
|
private withAppToken;
|
|
395
402
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
403
|
+
export { MCP_ALLOW_LOOPBACK_ENV };
|
|
404
|
+
/** What a URL on loopback says on a server that is not one, with how to make it one: the switch, its value and the restart
|
|
405
|
+
* it takes (start-switches.ts). */
|
|
399
406
|
export declare const loopbackWords: (host: string) => string;
|
|
400
407
|
/** The owner's MCP registry over the one store. No load() is needed: every read goes to the store (the runner also writes
|
|
401
408
|
* the OAuth state), so a read is always current. */
|
|
402
409
|
export declare function mcpServersOverStore(store: McpServersStore, env: NodeJS.ProcessEnv, version: string, network?: OAuthNetwork): McpServersOverStore;
|
|
403
|
-
export {};
|