@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/mcp-servers.js
DELETED
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
// Remote MCP servers a person adds through /v2/settings/mcp-servers. A preview connects with the official SDK client
|
|
2
|
-
// (@modelcontextprotocol/client: 2026-07-28 first, 2025-era servers by its fallback), lists every tool and stores
|
|
3
|
-
// nothing. A save previews, then keeps the URL, the tool snapshot the person saw and the credential in
|
|
4
|
-
// DIR/mcp-servers.json (0600, written whole, synced, renamed), each header value sealed (AES-256-GCM, tool-keys.ts' seal
|
|
5
|
-
// key) and bound to `mcp:<server>:<header>`, so a value moved to another server or header does not open. An OAuth
|
|
6
|
-
// server's token set (mcp-oauth.ts) is sealed the same way, bound to `mcp:<server>:oauth`, and refreshed here. No read
|
|
7
|
-
// returns a credential. No redirect is followed: a credential goes only to the URL the person gave.
|
|
8
|
-
import { createHmac } from "node:crypto";
|
|
9
|
-
import { readFileSync } from "node:fs";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { seal, unseal } from "@parcha/pi-durable-agent";
|
|
12
|
-
import { ApiError, invalid } from "./errors.js";
|
|
13
|
-
import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "./github.js";
|
|
14
|
-
import { writeDurableSync } from "./server-fs.js";
|
|
15
|
-
// The probe and request validation are the one copy in mcp-probe.ts, shared with the store-backed registry
|
|
16
|
-
// (mcp-servers-store.ts) so both answer and refuse byte-identically; only the storage and sealing differ, below.
|
|
17
|
-
import { authOf, canonical, credentialMissing, listServer, marked, MAX_OAUTH_VALUE_BYTES, MCP_AUTH_TYPES, MCP_SERVER_NAME, nameOf, notFound, oauthValueValid, pricesListed, pricesOf, REFRESH_MARGIN_MS, RESERVED_MCP_NAMES, scopesValid, SEAL_KEY_HOW, UNKNOWN_EXPIRY_MS, UNUSABLE, urlOf, } from "./mcp-probe.js";
|
|
18
|
-
import { MCP_SETTINGS_PAGE, McpSignIns, systemNetwork, reasonOf, refreshed, refused, SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
19
|
-
import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
|
|
20
|
-
import { serverGate } from "./tool-plane.js";
|
|
21
|
-
import { isObject, unknownFields } from "./validate.js";
|
|
22
|
-
// The names other modules still import from here (server.ts, openapi.ts, templates.ts, the runner's claim) now live in
|
|
23
|
-
// mcp-probe.ts; re-exported so those importers are unchanged until the cut repoints them.
|
|
24
|
-
export { MCP_AUTH_TYPES, MCP_SERVER_NAME, REFRESH_MARGIN_MS, RESERVED_MCP_NAMES, UNKNOWN_EXPIRY_MS, UNUSABLE };
|
|
25
|
-
export const MCP_SERVERS_FILE = "mcp-servers.json";
|
|
26
|
-
const FORMAT = "mcp-servers/1";
|
|
27
|
-
/** How long a stop waits for the refreshes and code exchanges it aborted. */
|
|
28
|
-
const CLOSE_MS = 2_000;
|
|
29
|
-
export class McpServers {
|
|
30
|
-
version;
|
|
31
|
-
network;
|
|
32
|
-
file;
|
|
33
|
-
/** The connected GitHub App's installation token for listing a `github_app` server's tools as it is saved, refreshed
|
|
34
|
-
* or previewed by name (github-connection.ts tokenForListing); a run's own is minted at its launch in the runner
|
|
35
|
-
* (runner/mcp-github.ts). Set by the server; absent, such a server cannot be saved. */
|
|
36
|
-
appToken;
|
|
37
|
-
/** The one origin a github_app server may have (GITHUB_MCP_ORIGIN; a test's fake through the server's seam): the App's
|
|
38
|
-
* tokens are minted for, and sent to, nothing else. */
|
|
39
|
-
appOrigin = GITHUB_MCP_ORIGIN;
|
|
40
|
-
key;
|
|
41
|
-
sealCheck;
|
|
42
|
-
signIns;
|
|
43
|
-
/** Each OAuth server's refresh under way: one at a time, so a rotating refresh token is spent once. */
|
|
44
|
-
refreshing = new Map();
|
|
45
|
-
/** The server's stop: aborts every refresh and code exchange under way, and from then on nothing is written. */
|
|
46
|
-
stopped = new AbortController();
|
|
47
|
-
/** The refreshes and callbacks under way, which close() waits out before the server lets its data directory go. */
|
|
48
|
-
inflight = new Set();
|
|
49
|
-
/** `network`: how an MCP server off loopback's authorization server is reached (mcp-oauth.ts); tests give their own. */
|
|
50
|
-
constructor(data, env, version, network = systemNetwork) {
|
|
51
|
-
this.version = version;
|
|
52
|
-
this.network = network;
|
|
53
|
-
this.signIns = new McpSignIns(network);
|
|
54
|
-
this.file = join(data, MCP_SERVERS_FILE);
|
|
55
|
-
this.key = sealKeyOf(env[SEAL_KEY_ENV]);
|
|
56
|
-
this.sealCheck = this.key && createHmac("sha256", this.key).update(`agentrun-serve ${FORMAT} key check`).digest("base64url");
|
|
57
|
-
}
|
|
58
|
-
get atRest() {
|
|
59
|
-
return this.key ? "sealed" : "unavailable";
|
|
60
|
-
}
|
|
61
|
-
/** This server's address as a browser reaches it (`base`: an OAuth sign-in's callback is under it), and where it
|
|
62
|
-
* listens (`listening`, required: the same as `base` when no public address is set). A loopback authorization
|
|
63
|
-
* server never reaches either one's port when it is local (McpSignIns.own). */
|
|
64
|
-
attach(base, listening) {
|
|
65
|
-
this.signIns.base = base.replace(/\/+$/, "");
|
|
66
|
-
this.signIns.listening = listening.replace(/\/+$/, "");
|
|
67
|
-
}
|
|
68
|
-
clientDocument() {
|
|
69
|
-
return this.signIns.clientDocument();
|
|
70
|
-
}
|
|
71
|
-
/** The origin the authorization server sends the browser back to: a sign-in starts there, where its cookie is set. */
|
|
72
|
-
get callbackOrigin() {
|
|
73
|
-
return new URL(this.signIns.base).origin;
|
|
74
|
-
}
|
|
75
|
-
/** At the server's stop, before its data directory's lock goes: every refresh and code exchange under way is aborted
|
|
76
|
-
* and waited for (at most `boundMs`), and no write is made after. One aborted writes nothing, so the token set stays
|
|
77
|
-
* as it was; if its authorization server had already rotated the refresh token, the next start's refresh is refused
|
|
78
|
-
* and the server reads `credential: expired`, asking for a sign-in again. */
|
|
79
|
-
async close(boundMs = CLOSE_MS) {
|
|
80
|
-
this.stopped.abort();
|
|
81
|
-
await Promise.race([Promise.allSettled([...this.inflight]), new Promise((done) => setTimeout(done, boundMs).unref())]);
|
|
82
|
-
}
|
|
83
|
-
track(work) {
|
|
84
|
-
this.inflight.add(work);
|
|
85
|
-
void work.then(() => this.inflight.delete(work), () => this.inflight.delete(work));
|
|
86
|
-
return work;
|
|
87
|
-
}
|
|
88
|
-
list() {
|
|
89
|
-
const servers = this.kept();
|
|
90
|
-
if (servers === "unreadable")
|
|
91
|
-
return { servers: [], file_unreadable: true };
|
|
92
|
-
return { servers: Object.keys(servers).sort().map((name) => this.view(name, servers[name])) };
|
|
93
|
-
}
|
|
94
|
-
get(name) {
|
|
95
|
-
return this.view(name, this.need(name));
|
|
96
|
-
}
|
|
97
|
-
/** POST preview: `{url, auth}`, or `{name}` for a saved server with its sealed credential. Stores nothing. */
|
|
98
|
-
async preview(body, stop) {
|
|
99
|
-
if (body.name !== undefined && body.url === undefined) {
|
|
100
|
-
const issues = unknownFields(body, ["name"]);
|
|
101
|
-
if (issues.length)
|
|
102
|
-
throw invalid(issues);
|
|
103
|
-
const name = String(body.name);
|
|
104
|
-
await this.freshen(name);
|
|
105
|
-
const kept = this.need(name);
|
|
106
|
-
return marked(kept.url, await listServer(new URL(kept.url), await this.withAppToken(kept, new URL(kept.url), this.opened(name, kept, "name"), stop), this.version, stop));
|
|
107
|
-
}
|
|
108
|
-
const { url, auth } = this.admit(body);
|
|
109
|
-
// A github_app server's credential is a token of the App, minted here, as for a saved one: its static headers are optional.
|
|
110
|
-
if (auth.type !== "none" && auth.type !== "github_app" && !auth.headers)
|
|
111
|
-
throw invalid([credentialMissing(auth.type, "A preview needs the credential it is to connect with.")]);
|
|
112
|
-
return marked(url.href, await listServer(url, await this.withAppToken({ auth: { type: auth.type } }, url, auth.headers ?? {}, stop), this.version, stop));
|
|
113
|
-
}
|
|
114
|
-
/** PUT: preview, then keep the server with the tools listed. A body with no credential keeps the sealed one, while
|
|
115
|
-
* the auth type and the URL's origin stay the same. */
|
|
116
|
-
async save(name, body, stop) {
|
|
117
|
-
nameOf(name);
|
|
118
|
-
const { url, auth, prices } = this.admit(body, true);
|
|
119
|
-
if (auth.type !== "none" && !this.key)
|
|
120
|
-
throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no MCP server credential: it never keeps one in the clear. ${SEAL_KEY_HOW}`);
|
|
121
|
-
const was = this.servers()[name];
|
|
122
|
-
let headers = auth.headers;
|
|
123
|
-
// A github_app server's own headers are only its static ones (its token is minted), kept as saved only at the same
|
|
124
|
-
// origin, as any saved credential: a move takes them again, or none goes to another origin.
|
|
125
|
-
if (auth.type === "github_app" && !headers && was?.auth.type === "github_app" && was.auth.sealed) {
|
|
126
|
-
if (new URL(was.url).origin !== url.origin)
|
|
127
|
-
throw invalid([credentialMissing(auth.type, `The address moved from ${new URL(was.url).origin} to ${url.origin}: send the headers again, so saved ones never go to another origin.`)]);
|
|
128
|
-
headers = this.opened(name, was, "auth.headers");
|
|
129
|
-
}
|
|
130
|
-
if (auth.type !== "none" && auth.type !== "github_app" && !headers) {
|
|
131
|
-
if (!was || was.auth.type !== auth.type)
|
|
132
|
-
throw invalid([credentialMissing(auth.type, `The server ${name} has no saved ${auth.type} credential to keep.`)]);
|
|
133
|
-
if (new URL(was.url).origin !== url.origin)
|
|
134
|
-
throw invalid([credentialMissing(auth.type, `The address moved from ${new URL(was.url).origin} to ${url.origin}: send the credential again, so a saved one never goes to another origin.`)]);
|
|
135
|
-
await this.freshen(name);
|
|
136
|
-
// Read again after the refresh's wait: a sign-in to another URL that landed meanwhile is never sent here.
|
|
137
|
-
const now = this.need(name);
|
|
138
|
-
if (saving(now) !== saving(was))
|
|
139
|
-
throw new ApiError("unavailable", `The server ${name} was signed in to, saved or forgotten meanwhile: save it again.`);
|
|
140
|
-
headers = this.opened(name, now, credentialMissing(auth.type, "").field);
|
|
141
|
-
}
|
|
142
|
-
const listed = await listServer(url, await this.withAppToken({ auth: { type: auth.type } }, url, headers ?? {}, stop), this.version, stop);
|
|
143
|
-
// A price names a tool the server listed now, or nothing is saved.
|
|
144
|
-
const unlisted = Object.keys(prices ?? {}).filter((tool) => !listed.tools.some((listedTool) => listedTool.name === tool));
|
|
145
|
-
if (unlisted.length)
|
|
146
|
-
throw invalid(unlisted.map((tool) => ({ field: `prices.${tool}`, reason: "not_an_option", message: `The server ${name} lists no tool ${tool}; its tools are ${listed.tools.map((t) => t.name).join(", ") || "none"}.` })));
|
|
147
|
-
const now = new Date().toISOString();
|
|
148
|
-
const sealed = auth.type !== "oauth" && headers && Object.keys(headers).length > 0 && Object.fromEntries(Object.entries(headers).map(([header, value]) => [header, seal(this.key, Buffer.from(value, "utf8"), aad(name, header)).toString("base64")]));
|
|
149
|
-
const servers = this.servers();
|
|
150
|
-
// An OAuth server keeps its token set as sealed (a refresh meanwhile kept); only a sign-in replaces it, and one that
|
|
151
|
-
// lands, or a PUT or DELETE, while this listed makes the listing stale: its token never goes with another URL.
|
|
152
|
-
if (auth.type === "oauth" && (!servers[name] || saving(servers[name]) !== saving(was)))
|
|
153
|
-
throw new ApiError("unavailable", `The server ${name} was signed in to, saved or forgotten while its tools were listed: save it again.`);
|
|
154
|
-
const kept = auth.type === "oauth" ? servers[name].auth : { type: auth.type, ...(sealed ? { sealed, check: this.sealCheck } : {}) };
|
|
155
|
-
// A body with no `prices` keeps the saved ones, for the tools still listed at the same address: a save from any
|
|
156
|
-
// client never turns a paid tool into an unmetered one. `{}` clears them, and a new address is another server.
|
|
157
|
-
const before = servers[name];
|
|
158
|
-
const priced = prices ?? (before?.url === url.href ? pricesListed(before.prices, listed.tools) : undefined);
|
|
159
|
-
servers[name] = { url: url.href, auth: kept, ...listed, ...(priced && Object.keys(priced).length ? { prices: priced } : {}), listed_at: now, updated_at: now };
|
|
160
|
-
this.write(servers);
|
|
161
|
-
return this.view(name, servers[name]);
|
|
162
|
-
}
|
|
163
|
-
/** POST refresh: list the saved server's tools again, keep them, and say what was added, removed and changed. */
|
|
164
|
-
async refresh(name, stop) {
|
|
165
|
-
await this.freshen(name);
|
|
166
|
-
const was = this.need(name);
|
|
167
|
-
const listed = await listServer(new URL(was.url), await this.withAppToken(was, new URL(was.url), this.opened(name, was, "name"), stop), this.version, stop);
|
|
168
|
-
const servers = this.servers();
|
|
169
|
-
const now = servers[name];
|
|
170
|
-
if (!now)
|
|
171
|
-
throw notFound(name);
|
|
172
|
-
// A PUT while listing (another URL, another account's credential) makes this listing stale: never kept.
|
|
173
|
-
if (canonical([now.url, now.auth, now.updated_at]) !== canonical([was.url, was.auth, was.updated_at]))
|
|
174
|
-
throw new ApiError("unavailable", `The server ${name} was changed while its tools were listed: refresh it again.`);
|
|
175
|
-
const before = new Map(now.tools.map((tool) => [tool.name, canonical(tool)]));
|
|
176
|
-
const after = new Map(listed.tools.map((tool) => [tool.name, canonical(tool)]));
|
|
177
|
-
const next = { ...now, ...listed, listed_at: new Date().toISOString() };
|
|
178
|
-
// A price of a tool the server no longer lists goes with it.
|
|
179
|
-
const prices = pricesListed(now.prices, listed.tools);
|
|
180
|
-
if (Object.keys(prices).length)
|
|
181
|
-
next.prices = prices;
|
|
182
|
-
else
|
|
183
|
-
delete next.prices;
|
|
184
|
-
servers[name] = next;
|
|
185
|
-
this.write(servers);
|
|
186
|
-
return {
|
|
187
|
-
added: [...after.keys()].filter((tool) => !before.has(tool)),
|
|
188
|
-
removed: [...before.keys()].filter((tool) => !after.has(tool)),
|
|
189
|
-
changed: [...after.keys()].filter((tool) => before.has(tool) && before.get(tool) !== after.get(tool)),
|
|
190
|
-
server: this.view(name, servers[name]),
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
/** POST .../{name}/oauth/start: `{url, scopes?, client_id?, client_secret?}`; answers the URL the owner opens. */
|
|
194
|
-
async oauthStart(name, body) {
|
|
195
|
-
nameOf(name);
|
|
196
|
-
const issues = unknownFields(body, ["url", "scopes", "client_id", "client_secret"]);
|
|
197
|
-
const url = urlOf(body.url, issues);
|
|
198
|
-
const { scopes, client_id, client_secret } = body;
|
|
199
|
-
if (scopes !== undefined && !scopesValid(scopes))
|
|
200
|
-
issues.push({ field: "scopes", reason: "invalid", message: "scopes is a list of 1 to 32 OAuth scopes." });
|
|
201
|
-
for (const [field, text] of [["client_id", client_id], ["client_secret", client_secret]])
|
|
202
|
-
if (text !== undefined && !oauthValueValid(text))
|
|
203
|
-
issues.push({ field, reason: "invalid", message: `${field} is text, at most ${MAX_OAUTH_VALUE_BYTES} bytes.` });
|
|
204
|
-
if (client_secret !== undefined && client_id === undefined)
|
|
205
|
-
issues.push({ field: "client_id", reason: "missing", message: "A client_secret goes with the client_id it is the secret of." });
|
|
206
|
-
if (issues.length)
|
|
207
|
-
throw invalid(issues);
|
|
208
|
-
if (!this.key)
|
|
209
|
-
throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no MCP server credential: it never keeps one in the clear. ${SEAL_KEY_HOW}`);
|
|
210
|
-
const was = this.servers()[name];
|
|
211
|
-
// A body with no client_id signs in again with the client kept in the sealed token set (a pre-registered one with
|
|
212
|
-
// its secret, or the one registered or named last time), for the same origin only; one with a client_id replaces it.
|
|
213
|
-
const opened = typeof client_id !== "string" && was?.auth.type === "oauth" && new URL(was.url).origin === url.origin ? this.open(name, was) : undefined;
|
|
214
|
-
const kept = opened && "set" in opened ? opened.set : undefined;
|
|
215
|
-
const client = typeof client_id === "string" ? { client: { client_id, ...(typeof client_secret === "string" ? { client_secret } : {}) }, kind: "pre-registered" } : kept ? { client: kept.client, kind: kept.kind } : {};
|
|
216
|
-
return { authorization_url: await this.signIns.start(name, url, { was: was ? saving(was) : null, ...(scopes ? { scope: scopes.join(" ") } : {}), ...client }) };
|
|
217
|
-
}
|
|
218
|
-
/** GET .../oauth/callback, the browser's way back: its state's sign-in finished (the code exchanged, the token set
|
|
219
|
-
* sealed, the tools listed and kept). Answers where to send the browser; 400 for a state that is unknown, used or
|
|
220
|
-
* expired. */
|
|
221
|
-
oauthCallback(query, stop) {
|
|
222
|
-
return this.track(this.callback(query, AbortSignal.any([this.stopped.signal, ...(stop ? [stop] : [])])));
|
|
223
|
-
}
|
|
224
|
-
async callback(query, stop) {
|
|
225
|
-
const entry = this.signIns.take(query.get("state"));
|
|
226
|
-
const stale = (servers) => (servers[entry.name] ? saving(servers[entry.name]) : null) !== entry.was;
|
|
227
|
-
const back = (error) => `${MCP_SETTINGS_PAGE}?server=${entry.name}&sign_in=${error ? `failed&error=${error}` : "ok"}`;
|
|
228
|
-
try {
|
|
229
|
-
const error = query.get("error");
|
|
230
|
-
if (error)
|
|
231
|
-
return back(/^[a-z_]{1,64}$/.test(error) ? error : "sign_in_failed");
|
|
232
|
-
const set = await this.signIns.finish(entry, query.get("code") ?? "", query.get("iss") ?? undefined, stop);
|
|
233
|
-
const listed = await listServer(new URL(entry.url), { authorization: `Bearer ${set.tokens.access_token}` }, this.version, stop);
|
|
234
|
-
const servers = this.servers();
|
|
235
|
-
// Saved, signed in to again or forgotten since this sign-in started: that stands.
|
|
236
|
-
if (stale(servers))
|
|
237
|
-
return back("changed_meanwhile");
|
|
238
|
-
const now = new Date().toISOString();
|
|
239
|
-
// The tools' prices stay with a sign-in again to the same address.
|
|
240
|
-
const prices = servers[entry.name]?.url === entry.url ? servers[entry.name].prices : undefined;
|
|
241
|
-
servers[entry.name] = { url: entry.url, auth: this.sealedSet(entry.name, set), ...listed, ...(prices ? { prices } : {}), listed_at: now, updated_at: now };
|
|
242
|
-
this.write(servers);
|
|
243
|
-
return back();
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
return back(await reasonOf(error));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/** A run's launch: the server's credential (headers), an OAuth access token refreshed first when it expires within
|
|
250
|
-
* `margin`. Undefined when it takes none; `{ unopened }` when it does not open, its sign-in expired among them. */
|
|
251
|
-
async headersForRun(name, margin = REFRESH_MARGIN_MS) {
|
|
252
|
-
await this.freshen(name, margin);
|
|
253
|
-
return this.headers(name);
|
|
254
|
-
}
|
|
255
|
-
/** The saved server's credential, opened, for a run's launch: its headers, or why it does not open, each under its own
|
|
256
|
-
* tag; undefined when it takes none. An OAuth sign-in that expired, or whose refresh was refused or had no refresh
|
|
257
|
-
* token left, is a credential that does not open: its calls are refused unsent, saying to sign in again. */
|
|
258
|
-
headers(name) {
|
|
259
|
-
const kept = this.saved(name);
|
|
260
|
-
if (!kept || kept.auth.type === "none")
|
|
261
|
-
return undefined;
|
|
262
|
-
// Opened first: a credential that does not open says so, whatever else is true of it (an expired token on a server
|
|
263
|
-
// without its seal key is a seal problem, which no retry fixes).
|
|
264
|
-
const opened = this.open(name, kept);
|
|
265
|
-
if (!("headers" in opened))
|
|
266
|
-
return { unopened: opened.unreadable === "seal_key_missing" ? UNUSABLE.noSealKey : UNUSABLE.damaged };
|
|
267
|
-
if (kept.auth.oauth?.expired)
|
|
268
|
-
return { unopened: UNUSABLE.signedOut };
|
|
269
|
-
// An access token past its expiry whose refresh got no answer (freshen kept the refresh token for the next launch):
|
|
270
|
-
// never handed over, so the server's 401 never reads as a sign-in to make again.
|
|
271
|
-
const until = kept.auth.type === "oauth" && kept.auth.oauth?.expires_at ? Date.parse(kept.auth.oauth.expires_at) : NaN;
|
|
272
|
-
if (until <= Date.now())
|
|
273
|
-
return { unopened: UNUSABLE.silent };
|
|
274
|
-
// Tagged, never told apart by a key a saved header could also have (`unopened` is a header name like any other).
|
|
275
|
-
return { headers: opened.headers };
|
|
276
|
-
}
|
|
277
|
-
/** An OAuth server's token set refreshed when its access token expires within `margin`. Tried twice when its
|
|
278
|
-
* authorization server does not answer, which writes nothing. A refusal (revoked, expired)
|
|
279
|
-
* marks the sign-in expired; an authorization server out of reach leaves it as it is. It runs on exactly these
|
|
280
|
-
* paths: before a run's process is spawned (runs.ts mcpFresh: a start, a reopen, a relaunch after a crash, a
|
|
281
|
-
* message that brings the process up, an approval's answer that does), and before a preview by name, a PUT that keeps the token set, and a POST
|
|
282
|
-
* refresh. Never on a stop or an abort, nor on a path that only reaches a live process. */
|
|
283
|
-
freshen(name, margin = REFRESH_MARGIN_MS) {
|
|
284
|
-
const running = this.refreshing.get(name);
|
|
285
|
-
if (running)
|
|
286
|
-
return running;
|
|
287
|
-
const kept = this.saved(name);
|
|
288
|
-
if (this.stopped.signal.aborted || kept?.auth.type !== "oauth" || kept.auth.oauth?.expired)
|
|
289
|
-
return Promise.resolve();
|
|
290
|
-
const opened = this.open(name, kept);
|
|
291
|
-
const set = "set" in opened ? opened.set : undefined;
|
|
292
|
-
// An access token whose expiry was not given is taken to last UNKNOWN_EXPIRY_MS from when it was obtained.
|
|
293
|
-
const due = set?.expires_at ? Date.parse(set.expires_at) : set?.obtained_at ? Date.parse(set.obtained_at) + UNKNOWN_EXPIRY_MS : undefined;
|
|
294
|
-
if (!set || due === undefined || due - Date.now() > margin)
|
|
295
|
-
return Promise.resolve();
|
|
296
|
-
const run = (async () => {
|
|
297
|
-
let next;
|
|
298
|
-
let no = !set.tokens.refresh_token && !!set.expires_at && Date.parse(set.expires_at) <= Date.now();
|
|
299
|
-
// Tried twice when the authorization server does not answer (a timeout, a 5xx, the network): only a refusal is final.
|
|
300
|
-
for (let tries = 0; set.tokens.refresh_token && !next && !no && tries < 2 && !this.stopped.signal.aborted; tries++) {
|
|
301
|
-
try {
|
|
302
|
-
next = await refreshed(set, kept.url, this.stopped.signal, this.network, { own: this.signIns.own });
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
no = await refused(error);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// Stopped while it waited: nothing is written, and the token set stays as it was.
|
|
309
|
-
if (this.stopped.signal.aborted)
|
|
310
|
-
return;
|
|
311
|
-
const servers = this.kept();
|
|
312
|
-
// Signed in again, or forgotten, while it refreshed: that stands.
|
|
313
|
-
if (servers === "unreadable" || servers[name]?.auth.sealed?.oauth !== kept.auth.sealed?.oauth || (!next && !no))
|
|
314
|
-
return;
|
|
315
|
-
// Only the credential changes: a PUT that saved meanwhile (same token set) keeps its URL and tools.
|
|
316
|
-
const now = servers[name];
|
|
317
|
-
servers[name] = { ...now, auth: next ? this.sealedSet(name, next) : { ...now.auth, oauth: { ...now.auth.oauth, expired: true } } };
|
|
318
|
-
this.write(servers);
|
|
319
|
-
})().finally(() => this.refreshing.delete(name));
|
|
320
|
-
this.track(run);
|
|
321
|
-
this.refreshing.set(name, run);
|
|
322
|
-
return run;
|
|
323
|
-
}
|
|
324
|
-
sealedSet(name, set) {
|
|
325
|
-
const oauth = seal(this.key, Buffer.from(JSON.stringify(set), "utf8"), aad(name, "oauth")).toString("base64");
|
|
326
|
-
const note = { ...(set.expires_at ? { expires_at: set.expires_at } : {}), scopes: (set.tokens.scope ?? "").split(" ").filter(Boolean), client: set.kind, client_id: set.client.client_id };
|
|
327
|
-
return { type: "oauth", sealed: { oauth }, check: this.sealCheck, oauth: note };
|
|
328
|
-
}
|
|
329
|
-
remove(name) {
|
|
330
|
-
const servers = this.servers();
|
|
331
|
-
if (!servers[name])
|
|
332
|
-
throw notFound(name);
|
|
333
|
-
delete servers[name];
|
|
334
|
-
this.write(servers);
|
|
335
|
-
}
|
|
336
|
-
saved(name) {
|
|
337
|
-
const kept = this.kept();
|
|
338
|
-
return kept === "unreadable" || !Object.hasOwn(kept, name) ? undefined : kept[name];
|
|
339
|
-
}
|
|
340
|
-
need(name) {
|
|
341
|
-
const kept = this.servers()[name];
|
|
342
|
-
if (!kept)
|
|
343
|
-
throw notFound(name);
|
|
344
|
-
return kept;
|
|
345
|
-
}
|
|
346
|
-
/** The server's own tool settings (GET /settings/tools), set as the server starts: each tool's permission on a read
|
|
347
|
-
* is the one they put in force (serverGate), as capabilities and an agent's read give it. */
|
|
348
|
-
toolSettings = () => ({});
|
|
349
|
-
view(name, kept) {
|
|
350
|
-
const { auth, ...rest } = kept;
|
|
351
|
-
const settings = this.toolSettings();
|
|
352
|
-
const listed = marked(kept.url, rest);
|
|
353
|
-
const opened = auth.type === "none" ? null : this.open(name, kept);
|
|
354
|
-
// The tools a call of which no price meters: outside the run's cost and its cap, said on every read.
|
|
355
|
-
const unmetered = kept.tools.filter((tool) => !(kept.prices && Object.hasOwn(kept.prices, tool.name))).map((tool) => tool.name);
|
|
356
|
-
return {
|
|
357
|
-
name,
|
|
358
|
-
...listed,
|
|
359
|
-
// Each tool's permission as this server applies it to an agent that sets none: the console shows a tool's row by
|
|
360
|
-
// it as soon as the tool is ticked, before any agent's read gives it.
|
|
361
|
-
tools: listed.tools.map((tool) => ({ ...tool, ...serverGate(`mcp:${name}/${tool.name}`, settings) })),
|
|
362
|
-
...(unmetered.length ? { not_metered: unmetered } : {}),
|
|
363
|
-
auth: { type: auth.type, ...(auth.type === "headers" || auth.type === "github_app" ? { headers: Object.keys(auth.sealed ?? {}) } : {}) },
|
|
364
|
-
credential: opened === null ? null : !("headers" in opened) ? opened.unreadable : auth.oauth?.expired ? "expired" : "sealed",
|
|
365
|
-
...(auth.oauth ? { oauth: { ...(auth.oauth.expires_at ? { expires_at: auth.oauth.expires_at } : {}), scopes: auth.oauth.scopes, client: auth.oauth.client, ...(auth.oauth.client_id ? { client_id: auth.oauth.client_id } : {}) } } : {}),
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
/** The sealed credential opened: its headers, and for OAuth the token set, whose access token is the header. */
|
|
369
|
-
open(name, kept) {
|
|
370
|
-
// A github_app server with no static headers keeps nothing sealed: its token is minted for each use.
|
|
371
|
-
if (kept.auth.type === "github_app" && !kept.auth.sealed)
|
|
372
|
-
return { headers: {} };
|
|
373
|
-
if (!this.key)
|
|
374
|
-
return { unreadable: "seal_key_missing" };
|
|
375
|
-
if (kept.auth.check !== this.sealCheck || !isObject(kept.auth.sealed))
|
|
376
|
-
return { unreadable: "unreadable" };
|
|
377
|
-
try {
|
|
378
|
-
const headers = Object.fromEntries(Object.entries(kept.auth.sealed).map(([header, value]) => [header, unseal(this.key, Buffer.from(value, "base64"), aad(name, header)).toString("utf8")]));
|
|
379
|
-
if (kept.auth.type !== "oauth")
|
|
380
|
-
return { headers };
|
|
381
|
-
const set = JSON.parse(headers.oauth);
|
|
382
|
-
return { headers: { authorization: `Bearer ${set.tokens.access_token}` }, set };
|
|
383
|
-
}
|
|
384
|
-
catch {
|
|
385
|
-
return { unreadable: "unreadable" };
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/** The saved credential, opened, or the refusal that asks for it again. */
|
|
389
|
-
opened(name, kept, field) {
|
|
390
|
-
if (kept.auth.type === "none")
|
|
391
|
-
return {};
|
|
392
|
-
if (kept.auth.oauth?.expired)
|
|
393
|
-
throw invalid([{ field, reason: "expired", message: `The sign-in to ${name} expired or was revoked: ${SIGN_IN_AGAIN}.` }]);
|
|
394
|
-
const opened = this.open(name, kept);
|
|
395
|
-
if ("headers" in opened)
|
|
396
|
-
return opened.headers;
|
|
397
|
-
if (opened.unreadable === "seal_key_missing")
|
|
398
|
-
throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so the saved credential of ${name} does not open. ${SEAL_KEY_HOW}`);
|
|
399
|
-
throw invalid([{ field, reason: "missing", message: `The saved credential of ${name} does not open here (sealed under another seal key, or damaged): send it again.` }]);
|
|
400
|
-
}
|
|
401
|
-
/** `headers` and, for a github_app server, an installation token of the connected App to list its tools with. The run's
|
|
402
|
-
* own token is minted in the runner (runner/mcp-github.ts); this one lists tools as the server is saved or previewed. */
|
|
403
|
-
async withAppToken(kept, url, headers, stop) {
|
|
404
|
-
if (kept.auth.type !== "github_app")
|
|
405
|
-
return headers;
|
|
406
|
-
// Never a token of the App to another origin: a row saved before this rule is refused here too.
|
|
407
|
-
if (!githubMcpUrl(url, this.appOrigin))
|
|
408
|
-
throw invalid([{ field: "url", reason: "not_allowed", message: GITHUB_MCP_ONLY }]);
|
|
409
|
-
const minted = this.appToken ? await this.appToken(stop) : { unusable: "This server has no GitHub App: Connect GitHub in Settings." };
|
|
410
|
-
if ("failed" in minted)
|
|
411
|
-
throw new ApiError("github_failed", minted.failed);
|
|
412
|
-
if ("unusable" in minted)
|
|
413
|
-
throw new ApiError("github_not_connected", minted.unusable);
|
|
414
|
-
return { ...headers, authorization: `Bearer ${minted.token}` };
|
|
415
|
-
}
|
|
416
|
-
/** A body's URL, auth and prices, or 422. */
|
|
417
|
-
admit(body, priced = false) {
|
|
418
|
-
const issues = unknownFields(body, priced ? ["url", "auth", "prices"] : ["url", "auth"]);
|
|
419
|
-
const url = urlOf(body.url, issues);
|
|
420
|
-
const auth = authOf(body.auth, issues);
|
|
421
|
-
const prices = pricesOf(body.prices, issues);
|
|
422
|
-
// The App's tokens go to GitHub alone: a github_app server is GitHub's hosted MCP, nothing else. Its URL is refused
|
|
423
|
-
// in the GitHub rule's words, in place of any other the URL drew.
|
|
424
|
-
if (url && auth?.type === "github_app" && !githubMcpUrl(url, this.appOrigin))
|
|
425
|
-
issues.splice(0, issues.length, ...issues.filter((issue) => issue.field !== "url"), { field: "url", reason: "not_allowed", message: GITHUB_MCP_ONLY });
|
|
426
|
-
if (issues.length)
|
|
427
|
-
throw invalid(issues);
|
|
428
|
-
return { url: url, auth: auth, ...(prices ? { prices } : {}) };
|
|
429
|
-
}
|
|
430
|
-
/** The saved servers: none with no file, "unreadable" when the file does not read as this format. */
|
|
431
|
-
kept() {
|
|
432
|
-
try {
|
|
433
|
-
const doc = JSON.parse(readFileSync(this.file, "utf8"));
|
|
434
|
-
return isObject(doc) && doc.format === FORMAT && isObject(doc.servers) ? Object.assign(Object.create(null), doc.servers) : "unreadable";
|
|
435
|
-
}
|
|
436
|
-
catch (error) {
|
|
437
|
-
return error.code === "ENOENT" ? Object.create(null) : "unreadable";
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
/** The saved servers, or 409: a file that does not read is never written over, so no saved server is lost to it. */
|
|
441
|
-
servers() {
|
|
442
|
-
const kept = this.kept();
|
|
443
|
-
if (kept === "unreadable")
|
|
444
|
-
throw new ApiError("store_unreadable", `${MCP_SERVERS_FILE} in the data directory does not read as ${FORMAT}: nothing is read from it or written to it until it is restored or removed.`);
|
|
445
|
-
return kept;
|
|
446
|
-
}
|
|
447
|
-
write(servers) {
|
|
448
|
-
if (this.stopped.signal.aborted)
|
|
449
|
-
throw new ApiError("unavailable", "This server is stopping: nothing more is saved. Try again once it is back.", { retry_after_ms: 1000 }, { "retry-after": "1" });
|
|
450
|
-
writeDurableSync(this.file, `${JSON.stringify({ format: FORMAT, servers }, null, 2)}\n`);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
/** The file store's own seal AAD: each header value is sealed bound to its server and header name. */
|
|
454
|
-
const aad = (name, header) => `mcp:${name}:${header}`;
|
|
455
|
-
/** Which save of a server this is: a PUT or a sign-in makes a new one, a refresh of its token or tools does not. */
|
|
456
|
-
const saving = (kept) => `${kept.url} ${kept.updated_at}`;
|
package/dist/packs.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { InputIssue } from "./errors.js";
|
|
2
|
-
import { type Effort, THINKING_LEVELS } from "./model.js";
|
|
3
|
-
/** A pack's name. */
|
|
4
|
-
export declare const PACK_NAME: RegExp;
|
|
5
|
-
/** An output type: a key of a pack's `outputs`. */
|
|
6
|
-
export declare const OUTPUT_TYPE: RegExp;
|
|
7
|
-
/** A skill name a pack names: the name rule Agent Skills and the Claude adapter use. */
|
|
8
|
-
export declare const PACK_SKILL: RegExp;
|
|
9
|
-
/** The most skills one list of a pack names. */
|
|
10
|
-
export declare const MAX_PACK_SKILLS = 32;
|
|
11
|
-
/** The most output types one pack names. */
|
|
12
|
-
export declare const MAX_PACK_OUTPUTS = 32;
|
|
13
|
-
/** The longest output file: the same cap serve applies to a skill path. */
|
|
14
|
-
export declare const MAX_OUTPUT_FILE = 512;
|
|
15
|
-
export type Thinking = (typeof THINKING_LEVELS)[number];
|
|
16
|
-
/** Skill names, in the order the run loads them. */
|
|
17
|
-
export type PackSkills = {
|
|
18
|
-
skills: string[];
|
|
19
|
-
};
|
|
20
|
-
/** One effort's row: its skills, and the thinking level a run at that effort gets, if the pack sets one. */
|
|
21
|
-
export type PackEffort = PackSkills & {
|
|
22
|
-
thinking?: Thinking;
|
|
23
|
-
};
|
|
24
|
-
/** One output type: its writer skills, the file it lands in, and the writer skills that replace them at an effort. */
|
|
25
|
-
export type PackOutput = PackSkills & {
|
|
26
|
-
file?: string;
|
|
27
|
-
effort?: Partial<Record<Effort, PackSkills>>;
|
|
28
|
-
};
|
|
29
|
-
/** A profile pack, version 1. */
|
|
30
|
-
export type Pack = {
|
|
31
|
-
version: 1;
|
|
32
|
-
name: string;
|
|
33
|
-
effort: Record<Effort, PackEffort>;
|
|
34
|
-
outputs: Record<string, PackOutput>;
|
|
35
|
-
default_output?: string;
|
|
36
|
-
};
|
|
37
|
-
/** What a run asks of a pack: its effort (medium when absent) and its output type (the pack's default when absent). */
|
|
38
|
-
export type PackAsk = {
|
|
39
|
-
effort?: Effort;
|
|
40
|
-
output?: string;
|
|
41
|
-
};
|
|
42
|
-
/** A pack read for one run: the effort, its thinking level if the pack sets one, every skill to load in order, and the
|
|
43
|
-
* output type with its file, if the run writes one. */
|
|
44
|
-
export type ResolvedPack = {
|
|
45
|
-
effort: Effort;
|
|
46
|
-
thinking?: Thinking;
|
|
47
|
-
skills: string[];
|
|
48
|
-
output?: {
|
|
49
|
-
type: string;
|
|
50
|
-
file?: string;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Every issue with `value` as a version 1 pack, none if it is one. Fields are paths into the pack
|
|
55
|
-
* (`effort.low.skills[0]`), under `at` when given (`profile.effort.low.skills[0]`); the pack itself is `at`. A skill
|
|
56
|
-
* list or `outputs` over its limit is `too_many`, and its items up to the limit are checked as any others; items past
|
|
57
|
-
* the limit are not checked, so an oversized pack makes a bounded number of issues.
|
|
58
|
-
*/
|
|
59
|
-
export declare function packIssues(value: unknown, { at }?: {
|
|
60
|
-
at?: string | undefined;
|
|
61
|
-
}): InputIssue[];
|
|
62
|
-
/**
|
|
63
|
-
* `pack` (one packIssues finds nothing wrong with) read for a run at `effort` asked for `output`: the effort row's
|
|
64
|
-
* skills, then the output's writer skills (its skills at that effort if it names some there, else its own), each skill
|
|
65
|
-
* once at its first place. With no output asked, the pack's default_output; with neither, no output and no writer.
|
|
66
|
-
* `thinking` is there only when the effort row sets one, so the caller keeps its own level otherwise. An effort that is
|
|
67
|
-
* not one, or an output type the pack does not name, is an issue on `effort` or `output`.
|
|
68
|
-
*/
|
|
69
|
-
export declare function resolvePack(pack: Pack, { effort, output }?: PackAsk): ResolvedPack | {
|
|
70
|
-
issues: InputIssue[];
|
|
71
|
-
};
|