@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53
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 +160 -1
- package/README.md +306 -36
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +14 -4
- package/dist/agent-delete.js +30 -58
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +28 -18
- package/dist/agents-store.js +48 -34
- package/dist/api-only.d.ts +30 -8
- package/dist/api-only.js +40 -16
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +9 -0
- package/dist/computer-setting.js +19 -1
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +365 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +19 -1
- package/dist/learn/commit.js +160 -2
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +46 -15
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +16 -0
- package/dist/learn/folder.js +30 -4
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +29 -4
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +15 -10
- package/dist/learning.js +14 -8
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +56 -12
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +17 -12
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +211 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +29 -5
- package/dist/run-launch.js +44 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +18 -1
- package/dist/run-view.js +28 -8
- package/dist/runner/adapter-loop.d.ts +14 -4
- package/dist/runner/adapter-loop.js +150 -31
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +35 -22
- package/dist/runner/audit.d.ts +10 -3
- package/dist/runner/audit.js +30 -7
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +31 -4
- package/dist/runner/claim-secrets.js +43 -7
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +32 -20
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +16 -3
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +9 -3
- package/dist/runner/learning-end.js +66 -29
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +7 -2
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +14 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +51 -24
- package/dist/runner/promotion.js +206 -78
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +174 -42
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +41 -12
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +4 -4
- package/dist/runs-over-store.d.ts +39 -8
- package/dist/runs-over-store.js +147 -32
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +185 -78
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +678 -124
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +8 -0
- package/dist/store/agent-body.js +20 -6
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +43 -4
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +14 -0
- package/dist/store/sqlite/run-launch.js +58 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +319 -153
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +173 -33
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-eval.js +4 -4
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +29 -5
- package/dist/templates.js +68 -14
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +1 -1
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +4 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
package/dist/mcp-gateway.js
CHANGED
|
@@ -15,14 +15,20 @@
|
|
|
15
15
|
// - A tool its owner priced (the server's `prices`) is held at that price on the run's one ledger and booked as the
|
|
16
16
|
// run's tool cost (paid-calls.ts paidStep): refused unsent when the cap cannot take it, or when no ledger books it. A
|
|
17
17
|
// tool with no price runs, marked "not metered" on the run's root (TOOL_UNMETERED), outside the run's cost.
|
|
18
|
+
// - A server with a meter (McpMeter; fal's, fal-price.ts) prices each billed call itself before it leaves: held and
|
|
19
|
+
// booked the same way, at the meter's quote. A call it cannot price is refused unsent under a spend cap, and with
|
|
20
|
+
// none runs booked as an unknown charge. A meter's keys (McpMeter.keys; fal's submission keys on fal's own host) are
|
|
21
|
+
// scoped to the run on every call of its server as it leaves, and read back as the agent's own in what the model reads.
|
|
18
22
|
import { randomUUID } from "node:crypto";
|
|
19
23
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
24
|
import { TOOL_UNMETERED } from "./timeline/index.js";
|
|
25
|
+
import { meterFor, meterNamed } from "./fal-price.js";
|
|
21
26
|
import { filedAnswer } from "./filed-answer.js";
|
|
22
27
|
import { paidLedger, paidStep } from "./paid-calls.js";
|
|
23
28
|
import { metaToolOf } from "./mcp-meta.js";
|
|
24
29
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
25
30
|
import { capped, mcpClient, scrub } from "./mcp-wire.js";
|
|
31
|
+
import { resourceResult, resourceToolOperation, resourceToolProblem } from "./mcp-resources.js";
|
|
26
32
|
import { mcpNameOf, mcpToolName } from "./tool-names.js";
|
|
27
33
|
import { workspaceAt, workspaceErrorWords } from "./workspace/index.js";
|
|
28
34
|
/** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
|
|
@@ -116,6 +122,9 @@ export function mcpPinOf(names, source) {
|
|
|
116
122
|
throw new Error(`The MCP tool ${name} cannot be pinned: no MCP server ${parsed.server} is saved.`);
|
|
117
123
|
if (!tool)
|
|
118
124
|
throw new Error(`The MCP tool ${name} cannot be pinned: the MCP server ${parsed.server} does not list ${parsed.tool}.`);
|
|
125
|
+
const resourceProblem = resourceToolProblem(tool);
|
|
126
|
+
if (resourceProblem)
|
|
127
|
+
throw new Error(`The MCP tool ${name} cannot be pinned: ${resourceProblem}.`);
|
|
119
128
|
// A meta tool granted before the rule (mcp-meta.ts): refused here, never run.
|
|
120
129
|
const meta = metaToolOf(saved.url, tool.name);
|
|
121
130
|
if (meta)
|
|
@@ -123,8 +132,9 @@ export function mcpPinOf(names, source) {
|
|
|
123
132
|
const declared = mcpHeaderProblem(tool.inputSchema);
|
|
124
133
|
if (declared)
|
|
125
134
|
throw new Error(`The MCP tool ${name} declares a header it cannot send: ${declared}.`);
|
|
135
|
+
const meter = saved.meter ?? meterNamed(saved.url, saved.toolkit);
|
|
126
136
|
if (!Object.hasOwn(pin, parsed.server))
|
|
127
|
-
pin[parsed.server] = { url: saved.url, tools: [] };
|
|
137
|
+
pin[parsed.server] = { url: saved.url, tools: [], ...(meter ? { meter } : {}) };
|
|
128
138
|
const pinned = pin[parsed.server];
|
|
129
139
|
pinned.tools.push(tool);
|
|
130
140
|
const price = saved.prices && Object.hasOwn(saved.prices, tool.name) ? saved.prices[tool.name] : undefined;
|
|
@@ -188,6 +198,7 @@ export function mcpGateway(options) {
|
|
|
188
198
|
* another account connects again, so no session made as one account carries another's calls. */
|
|
189
199
|
const clients = new Map();
|
|
190
200
|
const pins = new Map(Object.entries(options.pin));
|
|
201
|
+
const meters = new Map([...pins].map(([server, pinned]) => [server, meterFor(pinned, { media: options.media, now: options.now, run: options.run })]));
|
|
191
202
|
const credentials = { get: (server) => (Object.hasOwn(options.credentials, server) ? options.credentials[server] : undefined) };
|
|
192
203
|
/** Each server's last HTTP status, which tells a refused credential from another failure. (An address refusal is never
|
|
193
204
|
* kept here: it is read from each call's own error, since calls to one server run at once.) */
|
|
@@ -314,15 +325,20 @@ export function mcpGateway(options) {
|
|
|
314
325
|
/** The call itself, to a server whose address is the pinned one. A gate's decision or a paid call's hold goes around
|
|
315
326
|
* it, in `call` below: the one place every harness's call passes before anything is sent. */
|
|
316
327
|
/** `sending`, when given, runs once the server is connected and right before the call leaves: its refusal (a text)
|
|
317
|
-
* keeps the call from leaving. A call that never got that far (a failed connect, a stop) never ran it.
|
|
318
|
-
|
|
328
|
+
* keeps the call from leaving. A call that never got that far (a failed connect, a stop) never ran it. `outcome`
|
|
329
|
+
* takes the server's raw result, when one came back. */
|
|
330
|
+
const forward = async (server, url, headers, tool, args, signal, sending, outcome = {}, back) => {
|
|
319
331
|
let connected = false;
|
|
332
|
+
const operation = resourceToolOperation(tool);
|
|
333
|
+
const boundedSignal = operation ? AbortSignal.any([signal, AbortSignal.timeout(options.bounds?.callMs ?? CALL_MS)]) : signal;
|
|
320
334
|
// Read at each use: a token refreshed while the call is out, and sent, is scrubbed with the one it took.
|
|
321
335
|
const held = callSet(server);
|
|
322
|
-
const
|
|
336
|
+
const scrubbed = scrubberOf(server, hold(server, headers), held.values);
|
|
337
|
+
// Every text the model reads of the call (its answer, a filed one, an error), its keys read as the agent's own.
|
|
338
|
+
const clean = back ? (text) => back(scrubbed(text)) : scrubbed;
|
|
323
339
|
hold(server, queryOf(server));
|
|
324
340
|
try {
|
|
325
|
-
const upstream = await until(connect(server, url, headers),
|
|
341
|
+
const upstream = await until(connect(server, url, headers), boundedSignal);
|
|
326
342
|
connected = true;
|
|
327
343
|
if (sending && !signal.aborted) {
|
|
328
344
|
const refused = await sending();
|
|
@@ -331,12 +347,18 @@ export function mcpGateway(options) {
|
|
|
331
347
|
}
|
|
332
348
|
// The pinned definition, so the SDK mirrors its x-mcp-header parameters into Mcp-Param-* headers on a 2026-07-28
|
|
333
349
|
// server, as its own listing would have it do.
|
|
334
|
-
const result =
|
|
335
|
-
|
|
350
|
+
const result = operation
|
|
351
|
+
? await resourceResult(upstream, operation, args, boundedSignal, options.bounds?.callMs ?? CALL_MS, scrubbed)
|
|
352
|
+
: (await upstream.callTool({ name: tool.name, arguments: args }, { signal, timeout: options.bounds?.callMs ?? CALL_MS, toolDefinition: { name: tool.name, inputSchema: tool.inputSchema } }));
|
|
353
|
+
outcome.raw = result;
|
|
354
|
+
// A meter's own read (`quiet`): its raw result is all that is wanted, nothing filed for a model to read.
|
|
355
|
+
return said(outcome.quiet ? "" : await textOf(server, tool.name, result, clean), result.isError === true);
|
|
336
356
|
}
|
|
337
357
|
catch (error) {
|
|
338
358
|
if (signal.aborted)
|
|
339
359
|
return said(`The call to the MCP server ${server} was stopped.`, true);
|
|
360
|
+
if (boundedSignal.aborted)
|
|
361
|
+
return said(`The resource operation on the MCP server ${server} exceeded its deadline.`, true);
|
|
340
362
|
// The next call connects again (a server that dropped its session, say); this one is never sent again.
|
|
341
363
|
clients.delete(server);
|
|
342
364
|
// Its address refused before the request left (reach): nothing reached it. Read from this call's own error, never
|
|
@@ -369,6 +391,9 @@ export function mcpGateway(options) {
|
|
|
369
391
|
const pinned = pins.get(server);
|
|
370
392
|
if (!pinned?.tools.some((t) => t.name === tool))
|
|
371
393
|
return `${tool} is not a tool of the MCP server ${server} in this run.`;
|
|
394
|
+
const resourceProblem = resourceToolProblem(pinned.tools.find(t => t.name === tool));
|
|
395
|
+
if (resourceProblem)
|
|
396
|
+
return `The MCP operation ${tool} is invalid: ${resourceProblem}. Nothing was sent.`;
|
|
372
397
|
const meta = metaToolOf(pinned.url, tool);
|
|
373
398
|
if (meta)
|
|
374
399
|
return `mcp:${server}/${tool} can't be granted: ${meta.reason} Nothing was sent.`;
|
|
@@ -405,23 +430,29 @@ export function mcpGateway(options) {
|
|
|
405
430
|
const listed = pinnedTools.find((t) => t.name === tool);
|
|
406
431
|
// Whether the call left for the server: only then is it booked, at its price or as not metered.
|
|
407
432
|
let went = false;
|
|
433
|
+
let raw;
|
|
434
|
+
// The server's keys scoped to the run as the call leaves (fal's submission keys): its price is read from the call as
|
|
435
|
+
// the agent made it.
|
|
436
|
+
const keys = meters.get(server)?.keys;
|
|
408
437
|
const call = async (mark = async () => undefined) => {
|
|
409
438
|
const outcome = {};
|
|
410
|
-
const result = await forward(server, url, credentials.get(server)?.headers ?? {}, listed, args, signal, async () => {
|
|
439
|
+
const result = await forward(server, url, credentials.get(server)?.headers ?? {}, listed, keys ? keys.out(tool, args) : args, signal, async () => {
|
|
411
440
|
const refused = await mark();
|
|
412
441
|
went = refused === undefined;
|
|
413
442
|
return refused;
|
|
414
|
-
}, outcome);
|
|
443
|
+
}, outcome, keys?.back);
|
|
415
444
|
// The request's own address check refused it after the mark: it never left, so nothing is booked.
|
|
416
445
|
if (outcome.unsent)
|
|
417
446
|
went = false;
|
|
447
|
+
raw = outcome.raw;
|
|
418
448
|
return result;
|
|
419
449
|
};
|
|
420
450
|
const name = mcpToolName(server, tool);
|
|
421
451
|
const label = { tool: name, charged_by: server, call: callId };
|
|
422
452
|
const commit = options.commit?.();
|
|
423
453
|
const price = prices && Object.hasOwn(prices, tool) ? prices[tool] : undefined;
|
|
424
|
-
|
|
454
|
+
const meter = price === undefined && meters.get(server)?.bills(tool) ? meters.get(server) : undefined;
|
|
455
|
+
if (price === undefined && !meter) {
|
|
425
456
|
const result = await call();
|
|
426
457
|
if (commit && went)
|
|
427
458
|
await record(commit, TOOL_UNMETERED, label).catch(() => undefined);
|
|
@@ -430,11 +461,24 @@ export function mcpGateway(options) {
|
|
|
430
461
|
// On the runner's one ledger (paid-calls.ts Ledger.paid): held there at its price before it leaves and settled at its
|
|
431
462
|
// price once it left (nothing when it never left), in place of this process's spend and the root's marks.
|
|
432
463
|
const onLedger = paidLedger();
|
|
433
|
-
if (onLedger)
|
|
464
|
+
if (!onLedger)
|
|
465
|
+
return said(`${name} was not sent: this call has no run to book its price under.`, true);
|
|
466
|
+
if (price !== undefined) {
|
|
434
467
|
const stepped = await paidStep(onLedger, callId ?? name, { name, holdUsd: price, basis: `the price its owner set for ${name}`, by: label.charged_by }, () => call(), () => (went ? price : 0));
|
|
435
468
|
return "refused" in stepped ? said(stepped.refused, true) : stepped.result;
|
|
436
469
|
}
|
|
437
|
-
|
|
470
|
+
// The meter reads its prices from the server itself: the run's credential, no record, no booking.
|
|
471
|
+
const ask = async (asked, input) => {
|
|
472
|
+
const outcome = { quiet: true };
|
|
473
|
+
await forward(server, url, credentials.get(server)?.headers ?? {}, { name: asked, inputSchema: { type: "object" } }, input, signal, undefined, outcome);
|
|
474
|
+
return outcome.raw;
|
|
475
|
+
};
|
|
476
|
+
const quote = await meter.quote(tool, args, ask, signal);
|
|
477
|
+
if (quote.unpriceable && (options.capped?.() ?? true))
|
|
478
|
+
return said(`${name} was not sent: ${quote.unpriceable}, so a run with a spend cap can't send it. Nothing was sent.`, true);
|
|
479
|
+
// Settled by the server's reply; one that left and brought none back is an unknown charge.
|
|
480
|
+
const stepped = await paidStep(onLedger, callId ?? name, { name, holdUsd: quote.holdUsd, basis: quote.basis, by: label.charged_by }, () => call(), () => (went ? quote.chargeOf(raw) : 0));
|
|
481
|
+
return "refused" in stepped ? said(stepped.refused, true) : stepped.result;
|
|
438
482
|
};
|
|
439
483
|
const gateway = {
|
|
440
484
|
servers: [...pins].map(([name, pinned]) => ({ name, tools: pinned.tools })),
|
package/dist/mcp-pin-first.js
CHANGED
|
@@ -54,7 +54,7 @@ export async function pinFirst(revision, deps) {
|
|
|
54
54
|
}
|
|
55
55
|
let pin;
|
|
56
56
|
try {
|
|
57
|
-
pin = mcpPinOf(granted, { server: (name) => { const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices }; } });
|
|
57
|
+
pin = mcpPinOf(granted, { server: (name) => { const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices, toolkit: listing.toolkit }; } });
|
|
58
58
|
}
|
|
59
59
|
catch {
|
|
60
60
|
return undefined;
|
package/dist/mcp-probe.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
2
|
import type { ComposioBinding } from "./store/seal.js";
|
|
3
|
+
import { type ResourceOperation } from "./mcp-resources.js";
|
|
3
4
|
/** `per_run`: the server keeps no credential; each run's caller hands one with the run (mcp_auth), held for that run alone. */
|
|
4
5
|
export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app", "per_run"];
|
|
5
6
|
/** 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
|
|
@@ -35,6 +36,7 @@ export type McpTool = {
|
|
|
35
36
|
input_schema: unknown;
|
|
36
37
|
output_schema?: unknown;
|
|
37
38
|
annotations?: unknown;
|
|
39
|
+
resource?: ResourceOperation;
|
|
38
40
|
};
|
|
39
41
|
/** A registry tool (input_schema, as the server listed it) in the harnesses' shape (the kernel's McpTool: inputSchema),
|
|
40
42
|
* as a run is pinned to it and a session binds it. */
|
|
@@ -44,6 +46,7 @@ export declare function boundTool(tool: McpTool): {
|
|
|
44
46
|
description?: string;
|
|
45
47
|
inputSchema: Record<string, unknown>;
|
|
46
48
|
annotations?: Record<string, unknown>;
|
|
49
|
+
resource?: ResourceOperation;
|
|
47
50
|
};
|
|
48
51
|
export type Listed = {
|
|
49
52
|
protocol: string;
|
package/dist/mcp-probe.js
CHANGED
|
@@ -10,6 +10,7 @@ import { ApiError, invalid } from "./errors.js";
|
|
|
10
10
|
import { metaToolOf } from "./mcp-meta.js";
|
|
11
11
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
12
12
|
import { capped, MAX_RESPONSE, mcpClient, scrub } from "./mcp-wire.js";
|
|
13
|
+
import { reservedResourceName, resourceTools } from "./mcp-resources.js";
|
|
13
14
|
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
14
15
|
import { isObject, unknownFields } from "./validate.js";
|
|
15
16
|
/** The names AgentRun's own tools are called by, which no MCP server takes: claude-agent calls the kernel's host tools
|
|
@@ -67,7 +68,7 @@ const LOOPBACK = (host) => LOOPBACK_NAMES.includes(host) || LOOPBACK_V4.test(hos
|
|
|
67
68
|
/** A registry tool (input_schema, as the server listed it) in the harnesses' shape (the kernel's McpTool: inputSchema),
|
|
68
69
|
* as a run is pinned to it and a session binds it. */
|
|
69
70
|
export function boundTool(tool) {
|
|
70
|
-
return { name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}) };
|
|
71
|
+
return { name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), inputSchema: (tool.input_schema ?? {}), ...(tool.annotations ? { annotations: tool.annotations } : {}), ...(tool.resource !== undefined ? { resource: tool.resource } : {}) };
|
|
71
72
|
}
|
|
72
73
|
export const notFound = (name) => new ApiError("not_found", `No MCP server ${name}: GET /v2/settings/mcp-servers lists them.`);
|
|
73
74
|
export const credentialMissing = (type, message) => ({ field: type === "bearer" ? "auth.token" : type === "oauth" ? "auth.type" : "auth.headers", reason: "missing", message: type === "oauth" ? `${message} An OAuth server is signed in to first: POST /v2/settings/mcp-servers/{name}/oauth/start.` : message });
|
|
@@ -277,7 +278,7 @@ function composioBindingOf(field, entry, issues) {
|
|
|
277
278
|
const user = entry.composio_user_id;
|
|
278
279
|
const account = entry.connected_account_id;
|
|
279
280
|
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
|
+
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
282
|
// 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
283
|
else if (user === COMPOSIO_USER)
|
|
283
284
|
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." });
|
|
@@ -320,6 +321,8 @@ export async function listServer(url, headers, version, stop, send = fetch) {
|
|
|
320
321
|
for (let cursor, pages = 0;;) {
|
|
321
322
|
const page = await client.request({ method: "tools/list", ...(cursor !== undefined ? { params: { cursor } } : {}) }, { timeout: PREVIEW_MS, signal: deadline });
|
|
322
323
|
for (const tool of page.tools) {
|
|
324
|
+
if (reservedResourceName(tool.name))
|
|
325
|
+
throw invalid([{ field: "url", reason: "reserved", message: `The tool name ${tool.name} is reserved for AgentRun's resource operations.` }]);
|
|
323
326
|
const kept = {
|
|
324
327
|
name: tool.name,
|
|
325
328
|
...(tool.title ? { title: tool.title } : {}),
|
|
@@ -342,6 +345,8 @@ export async function listServer(url, headers, version, stop, send = fetch) {
|
|
|
342
345
|
cursor = page.nextCursor;
|
|
343
346
|
}
|
|
344
347
|
}
|
|
348
|
+
if (client.getServerCapabilities()?.resources)
|
|
349
|
+
tools.push(...resourceTools());
|
|
345
350
|
const instructions = client.getInstructions();
|
|
346
351
|
return {
|
|
347
352
|
protocol: client.getNegotiatedProtocolVersion() ?? "unknown",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const RESOURCE_OPERATIONS: readonly ["list", "templates", "read"];
|
|
2
|
+
export type ResourceOperation = typeof RESOURCE_OPERATIONS[number];
|
|
3
|
+
export declare const RESOURCE_NAMES: Record<ResourceOperation, string>;
|
|
4
|
+
export declare const RESOURCE_URI_MAX = 8192;
|
|
5
|
+
export declare const RESOURCE_LIST_MAX = 500;
|
|
6
|
+
export declare const RESOURCE_LIST_BYTES: number;
|
|
7
|
+
export declare const RESOURCE_PAGES_MAX = 64;
|
|
8
|
+
export declare const reservedResourceName: (name: string) => boolean;
|
|
9
|
+
export declare function resourceTools(): {
|
|
10
|
+
name: string;
|
|
11
|
+
resource: "read" | "templates" | "list";
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
input_schema: {
|
|
15
|
+
additionalProperties: boolean;
|
|
16
|
+
required?: string[] | undefined;
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
uri: {
|
|
20
|
+
type: string;
|
|
21
|
+
minLength: number;
|
|
22
|
+
maxLength: number;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
uri?: undefined;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
annotations: {
|
|
29
|
+
readOnlyHint: boolean;
|
|
30
|
+
destructiveHint: boolean;
|
|
31
|
+
idempotentHint: boolean;
|
|
32
|
+
openWorldHint: boolean;
|
|
33
|
+
};
|
|
34
|
+
}[];
|
|
35
|
+
/** A stored marker is accepted only with its exact operation name and bounded schema. Older ordinary tools without
|
|
36
|
+
* a marker remain ordinary tools; a name alone never turns tools/call into resources/read. */
|
|
37
|
+
export declare function resourceToolProblem(value: unknown): string | undefined;
|
|
38
|
+
export declare function resourceToolOperation(value: unknown): ResourceOperation | undefined;
|
|
39
|
+
type ResourceClient = {
|
|
40
|
+
request(input: unknown, options: unknown): Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
/** One bounded logical operation. Pagination belongs to this operation's deadline and fails if incomplete. */
|
|
43
|
+
export declare function resourceResult(client: ResourceClient, operation: ResourceOperation, args: Record<string, unknown>, signal: AbortSignal, timeout: number, clean: (text: string) => string): Promise<Record<string, unknown>>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Resource operations use the same per-server grants, revision pins, credentials and run gate as MCP tools.
|
|
2
|
+
// Only our probe creates these entries; an upstream tools/list entry never supplies the operation marker.
|
|
3
|
+
export const RESOURCE_OPERATIONS = ["list", "templates", "read"];
|
|
4
|
+
export const RESOURCE_NAMES = {
|
|
5
|
+
list: "agentrun_list_resources", templates: "agentrun_list_resource_templates", read: "agentrun_read_resource",
|
|
6
|
+
};
|
|
7
|
+
export const RESOURCE_URI_MAX = 8192;
|
|
8
|
+
export const RESOURCE_LIST_MAX = 500;
|
|
9
|
+
export const RESOURCE_LIST_BYTES = 1024 * 1024;
|
|
10
|
+
export const RESOURCE_PAGES_MAX = 64;
|
|
11
|
+
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
const keysAre = (value, keys) => Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
13
|
+
export const reservedResourceName = (name) => Object.values(RESOURCE_NAMES).includes(name);
|
|
14
|
+
export function resourceTools() {
|
|
15
|
+
return RESOURCE_OPERATIONS.map(resource => ({
|
|
16
|
+
name: RESOURCE_NAMES[resource], resource,
|
|
17
|
+
title: resource === "list" ? "List resources" : resource === "templates" ? "List resource templates" : "Read resource",
|
|
18
|
+
description: resource === "list" ? "List the resources available from this MCP server."
|
|
19
|
+
: resource === "templates" ? "List this MCP server's resource URI templates."
|
|
20
|
+
: "Read a resource URI from this MCP server. The URI is sent to the server, never fetched directly.",
|
|
21
|
+
input_schema: { type: "object", properties: resource === "read" ? { uri: { type: "string", minLength: 1, maxLength: RESOURCE_URI_MAX } } : {}, ...(resource === "read" ? { required: ["uri"] } : {}), additionalProperties: false },
|
|
22
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
/** A stored marker is accepted only with its exact operation name and bounded schema. Older ordinary tools without
|
|
26
|
+
* a marker remain ordinary tools; a name alone never turns tools/call into resources/read. */
|
|
27
|
+
export function resourceToolProblem(value) {
|
|
28
|
+
if (!object(value) || value.resource === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
const op = value.resource;
|
|
31
|
+
if (typeof op !== "string" || !RESOURCE_OPERATIONS.includes(op) || value.name !== RESOURCE_NAMES[op])
|
|
32
|
+
return "invalid resource operation marker";
|
|
33
|
+
const schema = value.inputSchema ?? value.input_schema;
|
|
34
|
+
const read = op === "read";
|
|
35
|
+
if (!object(schema) || !keysAre(schema, read ? ["type", "properties", "required", "additionalProperties"] : ["type", "properties", "additionalProperties"]) || schema.type !== "object" || schema.additionalProperties !== false || !object(schema.properties))
|
|
36
|
+
return "invalid resource operation schema";
|
|
37
|
+
if (!keysAre(schema.properties, read ? ["uri"] : []))
|
|
38
|
+
return "invalid resource operation arguments";
|
|
39
|
+
if (read) {
|
|
40
|
+
const uri = schema.properties.uri;
|
|
41
|
+
if (!object(uri) || !keysAre(uri, ["type", "minLength", "maxLength"]) || uri.type !== "string" || uri.minLength !== 1 || uri.maxLength !== RESOURCE_URI_MAX || !Array.isArray(schema.required) || schema.required.length !== 1 || schema.required[0] !== "uri")
|
|
42
|
+
return "invalid resource URI schema";
|
|
43
|
+
}
|
|
44
|
+
if (!object(value.annotations) || value.annotations.readOnlyHint !== true || value.annotations.destructiveHint !== false)
|
|
45
|
+
return "invalid resource operation effect";
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
export function resourceToolOperation(value) {
|
|
49
|
+
return object(value) && value.resource !== undefined && resourceToolProblem(value) === undefined ? value.resource : undefined;
|
|
50
|
+
}
|
|
51
|
+
/** One bounded logical operation. Pagination belongs to this operation's deadline and fails if incomplete. */
|
|
52
|
+
export async function resourceResult(client, operation, args, signal, timeout, clean) {
|
|
53
|
+
signal.throwIfAborted();
|
|
54
|
+
if (!keysAre(args, operation === "read" ? ["uri"] : []))
|
|
55
|
+
throw new Error("The resource operation has unexpected or missing arguments.");
|
|
56
|
+
if (operation === "read") {
|
|
57
|
+
if (typeof args.uri !== "string" || !args.uri.length || args.uri.length > RESOURCE_URI_MAX || /[\u0000-\u001f\u007f]/.test(args.uri))
|
|
58
|
+
throw new Error("A resource URI must be bounded text without control characters.");
|
|
59
|
+
const answer = await client.request({ method: "resources/read", params: { uri: args.uri } }, { signal, timeout });
|
|
60
|
+
if (!object(answer) || !Array.isArray(answer.contents) || answer.contents.length > RESOURCE_LIST_MAX || answer.contents.some(item => !object(item) || typeof item.uri !== "string" || (typeof item.text !== "string" && typeof item.blob !== "string")))
|
|
61
|
+
throw new Error("The MCP server returned invalid resource contents.");
|
|
62
|
+
for (const item of answer.contents)
|
|
63
|
+
if (typeof item.blob === "string") {
|
|
64
|
+
// The wire caps the whole response. Check the decoded binary too: a JSON-only scrub cannot see a token
|
|
65
|
+
// encoded inside a BlobResourceContents. Withhold it rather than corrupting arbitrary binary bytes.
|
|
66
|
+
const bytes = Buffer.from(item.blob, "base64");
|
|
67
|
+
if (bytes.toString("base64") !== item.blob)
|
|
68
|
+
throw new Error("The MCP server returned an invalid base64 resource.");
|
|
69
|
+
const decoded = bytes.toString("utf8");
|
|
70
|
+
if (clean(decoded) !== decoded)
|
|
71
|
+
throw new Error("The MCP resource contained a connection credential; its contents were withheld.");
|
|
72
|
+
}
|
|
73
|
+
return { content: answer.contents.map(resource => ({ type: "resource", resource })) };
|
|
74
|
+
}
|
|
75
|
+
const method = operation === "list" ? "resources/list" : "resources/templates/list";
|
|
76
|
+
const key = operation === "list" ? "resources" : "resourceTemplates";
|
|
77
|
+
const items = [], cursors = new Set();
|
|
78
|
+
let cursor, bytes = 0;
|
|
79
|
+
for (let pageNumber = 0; pageNumber < RESOURCE_PAGES_MAX; pageNumber++) {
|
|
80
|
+
signal.throwIfAborted();
|
|
81
|
+
const answer = await client.request({ method, ...(cursor === undefined ? {} : { params: { cursor } }) }, { signal, timeout });
|
|
82
|
+
if (!object(answer) || !Array.isArray(answer[key]))
|
|
83
|
+
throw new Error("The MCP server returned an invalid resource list.");
|
|
84
|
+
for (const item of answer[key]) {
|
|
85
|
+
if (!object(item) || typeof item.name !== "string" || typeof item[operation === "list" ? "uri" : "uriTemplate"] !== "string")
|
|
86
|
+
throw new Error("The MCP server returned an invalid resource entry.");
|
|
87
|
+
items.push(item);
|
|
88
|
+
bytes += Buffer.byteLength(JSON.stringify(item));
|
|
89
|
+
if (items.length > RESOURCE_LIST_MAX || bytes > RESOURCE_LIST_BYTES)
|
|
90
|
+
throw new Error("The MCP server's resource listing exceeds the item or byte limit; no incomplete listing was returned.");
|
|
91
|
+
}
|
|
92
|
+
if (answer.nextCursor === undefined)
|
|
93
|
+
return { structuredContent: { [key]: items } };
|
|
94
|
+
if (typeof answer.nextCursor !== "string" || answer.nextCursor.length > 4096 || cursors.has(answer.nextCursor))
|
|
95
|
+
throw new Error("The MCP server's resource cursor is invalid or repeats; no incomplete listing was returned.");
|
|
96
|
+
cursors.add(answer.nextCursor);
|
|
97
|
+
cursor = answer.nextCursor;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("The MCP server's resource list did not finish within the page limit.");
|
|
100
|
+
}
|
|
@@ -149,11 +149,11 @@ export declare class McpServersOverStore {
|
|
|
149
149
|
not_metered?: string[] | undefined;
|
|
150
150
|
tools: {
|
|
151
151
|
grant_problems?: Record<string, string>;
|
|
152
|
-
default_permission: "ask" | "
|
|
153
|
-
permissions: ("ask" | "
|
|
152
|
+
default_permission: "ask" | "deny" | "allow";
|
|
153
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
154
154
|
fallback_allow_reads?: true | undefined;
|
|
155
155
|
allow_reads?: true | undefined;
|
|
156
|
-
permission: "ask" | "
|
|
156
|
+
permission: "ask" | "deny" | "allow";
|
|
157
157
|
effect: import("./tool-gate.js").ToolEffect;
|
|
158
158
|
name: string;
|
|
159
159
|
title?: string;
|
|
@@ -161,6 +161,7 @@ export declare class McpServersOverStore {
|
|
|
161
161
|
input_schema: unknown;
|
|
162
162
|
output_schema?: unknown;
|
|
163
163
|
annotations?: unknown;
|
|
164
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
164
165
|
}[];
|
|
165
166
|
prices?: McpPrices | undefined;
|
|
166
167
|
instructions?: string | undefined;
|
|
@@ -190,11 +191,11 @@ export declare class McpServersOverStore {
|
|
|
190
191
|
not_metered?: string[] | undefined;
|
|
191
192
|
tools: {
|
|
192
193
|
grant_problems?: Record<string, string>;
|
|
193
|
-
default_permission: "ask" | "
|
|
194
|
-
permissions: ("ask" | "
|
|
194
|
+
default_permission: "ask" | "deny" | "allow";
|
|
195
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
195
196
|
fallback_allow_reads?: true | undefined;
|
|
196
197
|
allow_reads?: true | undefined;
|
|
197
|
-
permission: "ask" | "
|
|
198
|
+
permission: "ask" | "deny" | "allow";
|
|
198
199
|
effect: import("./tool-gate.js").ToolEffect;
|
|
199
200
|
name: string;
|
|
200
201
|
title?: string;
|
|
@@ -202,6 +203,7 @@ export declare class McpServersOverStore {
|
|
|
202
203
|
input_schema: unknown;
|
|
203
204
|
output_schema?: unknown;
|
|
204
205
|
annotations?: unknown;
|
|
206
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
205
207
|
}[];
|
|
206
208
|
prices?: McpPrices | undefined;
|
|
207
209
|
instructions?: string | undefined;
|
|
@@ -227,6 +229,7 @@ export declare class McpServersOverStore {
|
|
|
227
229
|
reason?: string;
|
|
228
230
|
})[];
|
|
229
231
|
prices: McpPrices;
|
|
232
|
+
toolkit: string | null;
|
|
230
233
|
} | undefined>;
|
|
231
234
|
/** `listing`, and when it is refused as a server that signs in with OAuth (auth_required, `auth: oauth`), whether that
|
|
232
235
|
* sign-in can start with no Client ID entered (`details.oauth.registration`, McpSignIns.registration), so the console
|
|
@@ -260,11 +263,11 @@ export declare class McpServersOverStore {
|
|
|
260
263
|
not_metered?: string[] | undefined;
|
|
261
264
|
tools: {
|
|
262
265
|
grant_problems?: Record<string, string>;
|
|
263
|
-
default_permission: "ask" | "
|
|
264
|
-
permissions: ("ask" | "
|
|
266
|
+
default_permission: "ask" | "deny" | "allow";
|
|
267
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
265
268
|
fallback_allow_reads?: true | undefined;
|
|
266
269
|
allow_reads?: true | undefined;
|
|
267
|
-
permission: "ask" | "
|
|
270
|
+
permission: "ask" | "deny" | "allow";
|
|
268
271
|
effect: import("./tool-gate.js").ToolEffect;
|
|
269
272
|
name: string;
|
|
270
273
|
title?: string;
|
|
@@ -272,6 +275,7 @@ export declare class McpServersOverStore {
|
|
|
272
275
|
input_schema: unknown;
|
|
273
276
|
output_schema?: unknown;
|
|
274
277
|
annotations?: unknown;
|
|
278
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
275
279
|
}[];
|
|
276
280
|
prices?: McpPrices | undefined;
|
|
277
281
|
instructions?: string | undefined;
|
|
@@ -305,11 +309,11 @@ export declare class McpServersOverStore {
|
|
|
305
309
|
not_metered?: string[] | undefined;
|
|
306
310
|
tools: {
|
|
307
311
|
grant_problems?: Record<string, string>;
|
|
308
|
-
default_permission: "ask" | "
|
|
309
|
-
permissions: ("ask" | "
|
|
312
|
+
default_permission: "ask" | "deny" | "allow";
|
|
313
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
310
314
|
fallback_allow_reads?: true | undefined;
|
|
311
315
|
allow_reads?: true | undefined;
|
|
312
|
-
permission: "ask" | "
|
|
316
|
+
permission: "ask" | "deny" | "allow";
|
|
313
317
|
effect: import("./tool-gate.js").ToolEffect;
|
|
314
318
|
name: string;
|
|
315
319
|
title?: string;
|
|
@@ -317,6 +321,7 @@ export declare class McpServersOverStore {
|
|
|
317
321
|
input_schema: unknown;
|
|
318
322
|
output_schema?: unknown;
|
|
319
323
|
annotations?: unknown;
|
|
324
|
+
resource?: import("./mcp-resources.js").ResourceOperation;
|
|
320
325
|
}[];
|
|
321
326
|
prices?: McpPrices | undefined;
|
|
322
327
|
instructions?: string | undefined;
|
|
@@ -218,10 +218,11 @@ export class McpServersOverStore {
|
|
|
218
218
|
const row = await this.store.mcp.server(name);
|
|
219
219
|
if (!row)
|
|
220
220
|
return undefined;
|
|
221
|
+
const { toolkit } = await this.sourceOf(row);
|
|
221
222
|
const url = new URL(row.url);
|
|
222
223
|
const pinned = (tools) => {
|
|
223
224
|
const listed = marked(row.url, { tools });
|
|
224
|
-
return { url: row.url, tools: listed.tools, prices: pricesListed((row.prices ?? undefined), listed.tools) };
|
|
225
|
+
return { url: row.url, tools: listed.tools, prices: pricesListed((row.prices ?? undefined), listed.tools), toolkit };
|
|
225
226
|
};
|
|
226
227
|
const send = await this.reached(row.auth, url, stop);
|
|
227
228
|
try {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// A media file's length in seconds, read from its bytes alone: an ISO file's movie header (mp4, m4a, mov), a WAV's data
|
|
2
|
+
// chunk over its byte rate, an MP3's frame count (Xing, Info or VBRI) or, with none, its frames walked one by one. Pure: no decoder, nothing read past the bytes given. Undefined for anything else, or a file cut short of the
|
|
3
|
+
// header its length is in.
|
|
4
|
+
const tag = (b, at, text) => at >= 0 && b.length >= at + text.length && [...text].every((c, i) => b[at + i] === c.charCodeAt(0));
|
|
5
|
+
const u32 = (b, at) => (b[at] * 0x1000000) + (b[at + 1] << 16) + (b[at + 2] << 8) + b[at + 3];
|
|
6
|
+
const u32le = (b, at) => b[at] + (b[at + 1] << 8) + (b[at + 2] << 16) + b[at + 3] * 0x1000000;
|
|
7
|
+
const length = (seconds) => (Number.isFinite(seconds) && seconds > 0 ? seconds : undefined);
|
|
8
|
+
/** The boxes of an ISO file between `from` and `to`: each one's type and where its body starts and ends. A box that runs
|
|
9
|
+
* past `to`, or is smaller than its own header, ends the walk. */
|
|
10
|
+
function* boxes(b, from, to) {
|
|
11
|
+
for (let at = from; at + 8 <= to;) {
|
|
12
|
+
let size = u32(b, at);
|
|
13
|
+
let head = 8;
|
|
14
|
+
if (size === 1) {
|
|
15
|
+
if (at + 16 > to)
|
|
16
|
+
return;
|
|
17
|
+
size = u32(b, at + 8) * 0x100000000 + u32(b, at + 12);
|
|
18
|
+
head = 16;
|
|
19
|
+
}
|
|
20
|
+
else if (size === 0)
|
|
21
|
+
size = to - at;
|
|
22
|
+
if (size < head || at + size > to)
|
|
23
|
+
return;
|
|
24
|
+
yield { type: String.fromCharCode(b[at + 4], b[at + 5], b[at + 6], b[at + 7]), start: at + head, end: at + size };
|
|
25
|
+
at += size;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** An ISO file's length: its moov's mvhd, duration over timescale (64-bit in version 1). */
|
|
29
|
+
function isoSeconds(b) {
|
|
30
|
+
for (const top of boxes(b, 0, b.length)) {
|
|
31
|
+
if (top.type !== "moov")
|
|
32
|
+
continue;
|
|
33
|
+
for (const { type, start, end } of boxes(b, top.start, top.end)) {
|
|
34
|
+
if (type !== "mvhd")
|
|
35
|
+
continue;
|
|
36
|
+
const wide = b[start] === 1;
|
|
37
|
+
if (end - start < (wide ? 32 : 20))
|
|
38
|
+
return undefined;
|
|
39
|
+
const scale = u32(b, start + (wide ? 20 : 12));
|
|
40
|
+
const ticks = wide ? u32(b, start + 24) * 0x100000000 + u32(b, start + 28) : u32(b, start + 16);
|
|
41
|
+
return scale > 0 ? length(ticks / scale) : undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** A WAV's length: its data chunk's bytes (those in the file, when it states more) over its fmt chunk's byte rate. */
|
|
47
|
+
function wavSeconds(b) {
|
|
48
|
+
let rate;
|
|
49
|
+
for (let at = 12; at + 8 <= b.length;) {
|
|
50
|
+
const size = u32le(b, at + 4);
|
|
51
|
+
if (tag(b, at, "fmt ")) {
|
|
52
|
+
if (at + 20 > b.length)
|
|
53
|
+
return undefined;
|
|
54
|
+
rate = u32le(b, at + 16);
|
|
55
|
+
}
|
|
56
|
+
else if (tag(b, at, "data"))
|
|
57
|
+
return rate ? length(Math.min(size, b.length - at - 8) / rate) : undefined;
|
|
58
|
+
at += 8 + size + (size % 2);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
// MPEG audio, by version bits (3: MPEG-1, 2: MPEG-2, 0: MPEG-2.5) and layer bits (3: I, 2: II, 1: III).
|
|
63
|
+
const RATES = { 3: [44_100, 48_000, 32_000], 2: [22_050, 24_000, 16_000], 0: [11_025, 12_000, 8_000] };
|
|
64
|
+
const KBPS_V1 = {
|
|
65
|
+
3: [0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448],
|
|
66
|
+
2: [0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384],
|
|
67
|
+
1: [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320],
|
|
68
|
+
};
|
|
69
|
+
const KBPS_V2 = {
|
|
70
|
+
3: [0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256],
|
|
71
|
+
2: [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160],
|
|
72
|
+
1: [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160],
|
|
73
|
+
};
|
|
74
|
+
/** The MPEG audio frame header at `at`, or undefined when those four bytes are none. */
|
|
75
|
+
function frameAt(b, at) {
|
|
76
|
+
if (at + 4 > b.length || b[at] !== 0xff || (b[at + 1] & 0xe0) !== 0xe0)
|
|
77
|
+
return undefined;
|
|
78
|
+
const version = (b[at + 1] >> 3) & 3;
|
|
79
|
+
const layer = (b[at + 1] >> 1) & 3;
|
|
80
|
+
const rate = RATES[version]?.[(b[at + 2] >> 2) & 3];
|
|
81
|
+
const kbps = (version === 3 ? KBPS_V1 : KBPS_V2)[layer]?.[b[at + 2] >> 4];
|
|
82
|
+
if (!rate || !kbps)
|
|
83
|
+
return undefined;
|
|
84
|
+
const padding = (b[at + 2] >> 1) & 1;
|
|
85
|
+
const mono = b[at + 3] >> 6 === 3;
|
|
86
|
+
const samples = layer === 3 ? 384 : layer === 2 || version === 3 ? 1152 : 576;
|
|
87
|
+
const bytes = layer === 3 ? (Math.floor((12 * kbps * 1000) / rate) + padding) * 4 : Math.floor(((samples / 8) * kbps * 1000) / rate) + padding;
|
|
88
|
+
return { rate, samples, bytes, side: version === 3 ? (mono ? 17 : 32) : mono ? 9 : 17 };
|
|
89
|
+
}
|
|
90
|
+
/** The furthest past a tag an MP3's first frame is looked for. */
|
|
91
|
+
const SYNC_SCAN = 64 * 1024;
|
|
92
|
+
/** Every frame's samples over its rate, from the frame at `at` to `end`. A last frame cut short ends it; bytes that stop
|
|
93
|
+
* being frames before that give no length, since a bitrate guessed for them could read the file short. */
|
|
94
|
+
function walkedSeconds(b, at, end) {
|
|
95
|
+
let seconds = 0;
|
|
96
|
+
while (at < end) {
|
|
97
|
+
const frame = frameAt(b, at);
|
|
98
|
+
if (!frame)
|
|
99
|
+
return undefined;
|
|
100
|
+
if (at + frame.bytes > end)
|
|
101
|
+
break;
|
|
102
|
+
seconds += frame.samples / frame.rate;
|
|
103
|
+
at += frame.bytes;
|
|
104
|
+
}
|
|
105
|
+
return length(seconds);
|
|
106
|
+
}
|
|
107
|
+
/** An MP3's length: its first frame's Xing, Info or VBRI frame count times a frame's samples over its rate; with none,
|
|
108
|
+
* its frames walked one by one (a variable bitrate needs no header), the first taken only when another follows it. */
|
|
109
|
+
function mp3Seconds(b) {
|
|
110
|
+
let start = 0;
|
|
111
|
+
// An ID3v2 tag: its size is four 7-bit bytes, with a 10-byte footer when flagged.
|
|
112
|
+
if (tag(b, 0, "ID3") && b.length >= 10)
|
|
113
|
+
start = 10 + ((b[6] & 0x7f) << 21) + ((b[7] & 0x7f) << 14) + ((b[8] & 0x7f) << 7) + (b[9] & 0x7f) + (b[5] & 0x10 ? 10 : 0);
|
|
114
|
+
const end = b.length - (tag(b, b.length - 128, "TAG") ? 128 : 0);
|
|
115
|
+
for (let at = start; at < Math.min(end, start + SYNC_SCAN); at++) {
|
|
116
|
+
const frame = frameAt(b, at);
|
|
117
|
+
if (!frame)
|
|
118
|
+
continue;
|
|
119
|
+
const xing = at + 4 + frame.side;
|
|
120
|
+
if ((tag(b, xing, "Xing") || tag(b, xing, "Info")) && xing + 12 <= b.length && b[xing + 7] & 1)
|
|
121
|
+
return length((u32(b, xing + 8) * frame.samples) / frame.rate);
|
|
122
|
+
if (tag(b, at + 36, "VBRI") && at + 54 <= b.length)
|
|
123
|
+
return length((u32(b, at + 50) * frame.samples) / frame.rate);
|
|
124
|
+
if (at + frame.bytes === end || frameAt(b, at + frame.bytes))
|
|
125
|
+
return walkedSeconds(b, at, end);
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
/** The length of the media file `bytes`, in seconds; undefined when it can't be read from them. */
|
|
130
|
+
export function mediaSeconds(bytes) {
|
|
131
|
+
if (tag(bytes, 4, "ftyp") || tag(bytes, 4, "moov") || tag(bytes, 4, "mdat") || tag(bytes, 4, "free") || tag(bytes, 4, "wide"))
|
|
132
|
+
return isoSeconds(bytes);
|
|
133
|
+
if (tag(bytes, 0, "RIFF") && tag(bytes, 8, "WAVE"))
|
|
134
|
+
return wavSeconds(bytes);
|
|
135
|
+
return mp3Seconds(bytes);
|
|
136
|
+
}
|