@wardby/cli 0.7.0 → 0.8.0
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/.env.example +5 -5
- package/README.md +6 -1
- package/deploy/local/docker-compose.quickstart-coding.yml +6 -0
- package/dist/claude-coding-worker/driver.d.ts +12 -0
- package/dist/claude-coding-worker/driver.js +29 -7
- package/dist/claude-coding-worker/main.js +5 -1
- package/dist/claude-coding-worker/sdk.js +17 -1
- package/dist/claude-plugin/command.d.ts +61 -0
- package/dist/claude-plugin/command.js +376 -0
- package/dist/cli-help.d.ts +1 -1
- package/dist/cli-help.js +2 -1
- package/dist/cli.js +47 -3
- package/dist/coding/code-host.d.ts +16 -0
- package/dist/coding/code-host.js +60 -0
- package/dist/coding/mcp-token.d.ts +12 -0
- package/dist/coding/mcp-token.js +26 -0
- package/dist/coding/protocol.js +2 -0
- package/dist/coding/redact.js +6 -1
- package/dist/coding/transcript/recorder.d.ts +5 -4
- package/dist/coding/transcript/recorder.js +1 -1
- package/dist/coding-worker/debug-trace.d.ts +3 -1
- package/dist/coding-worker/debug-trace.js +4 -2
- package/dist/coding-worker/driver.js +8 -1
- package/dist/coding-worker/main.js +5 -1
- package/dist/coding-worker/mcp-config.d.ts +27 -0
- package/dist/coding-worker/mcp-config.js +32 -0
- package/dist/coding-worker/sdk.d.ts +36 -0
- package/dist/coding-worker/sdk.js +28 -1
- package/dist/coding-worker/types.d.ts +4 -0
- package/dist/config/mcp-call-limit.d.ts +8 -0
- package/dist/config/mcp-call-limit.js +18 -0
- package/dist/config/mcp-servers.d.ts +8 -0
- package/dist/config/mcp-servers.js +12 -0
- package/dist/config/test-simulators.d.ts +10 -0
- package/dist/config/test-simulators.js +28 -0
- package/dist/config/tool-timeout.d.ts +1 -0
- package/dist/config/tool-timeout.js +18 -0
- package/dist/core/coding-mcp.d.ts +36 -0
- package/dist/core/coding-mcp.js +253 -0
- package/dist/core/coding-repository.d.ts +46 -0
- package/dist/core/coding-repository.js +92 -0
- package/dist/core/delegation-slots.d.ts +27 -0
- package/dist/core/delegation-slots.js +44 -0
- package/dist/core/dispatch.d.ts +6 -2
- package/dist/core/dispatch.js +36 -11
- package/dist/core/error-code.js +1 -0
- package/dist/core/grants.d.ts +28 -3
- package/dist/core/grants.js +46 -4
- package/dist/core/host-events.js +7 -3
- package/dist/core/host-status.js +2 -2
- package/dist/core/issue-status.js +4 -3
- package/dist/core/mark-ready.d.ts +1 -1
- package/dist/core/mark-ready.js +1 -1
- package/dist/core/mcp-client/client.d.ts +47 -0
- package/dist/core/mcp-client/client.js +141 -0
- package/dist/core/mcp-client/jsonrpc.d.ts +15 -0
- package/dist/core/mcp-client/jsonrpc.js +54 -0
- package/dist/core/mcp-client/results.d.ts +13 -0
- package/dist/core/mcp-client/results.js +42 -0
- package/dist/core/mcp-servers.d.ts +90 -0
- package/dist/core/mcp-servers.js +230 -0
- package/dist/core/mcp-tools.d.ts +108 -0
- package/dist/core/mcp-tools.js +287 -0
- package/dist/core/merge-order-check.js +38 -19
- package/dist/core/notification-dispatcher.js +2 -1
- package/dist/core/related-pull-requests.js +26 -10
- package/dist/core/review-fix.js +2 -2
- package/dist/core/review-host-tools.js +3 -1
- package/dist/core/runner.d.ts +66 -16
- package/dist/core/runner.js +281 -73
- package/dist/core/secret-broker-config.d.ts +2 -0
- package/dist/core/secret-broker-config.js +1 -1
- package/dist/core/secret-guard.d.ts +5 -2
- package/dist/core/secret-guard.js +22 -7
- package/dist/core/secrets.d.ts +11 -1
- package/dist/core/secrets.js +27 -1
- package/dist/core/serializable-retry.d.ts +18 -0
- package/dist/core/serializable-retry.js +43 -0
- package/dist/core/tool-admin.d.ts +5 -1
- package/dist/core/tool-admin.js +7 -2
- package/dist/core/tool-names.d.ts +13 -0
- package/dist/core/tool-names.js +20 -0
- package/dist/core/webhooks.d.ts +4 -0
- package/dist/core/webhooks.js +68 -49
- package/dist/core/workflow-run-events.js +2 -1
- package/dist/generated/prisma/browser.d.ts +31 -0
- package/dist/generated/prisma/client.d.ts +31 -0
- package/dist/generated/prisma/commonInputTypes.d.ts +50 -50
- package/dist/generated/prisma/internal/class.d.ts +66 -0
- package/dist/generated/prisma/internal/class.js +4 -4
- package/dist/generated/prisma/internal/prismaNamespace.d.ts +530 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +75 -2
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +79 -0
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +75 -2
- package/dist/generated/prisma/models/Agent.d.ts +271 -0
- package/dist/generated/prisma/models/AgentMcpServer.d.ts +1412 -0
- package/dist/generated/prisma/models/AgentMcpServer.js +1 -0
- package/dist/generated/prisma/models/AgentRepository.d.ts +40 -1
- package/dist/generated/prisma/models/AuthUser.d.ts +1 -1
- package/dist/generated/prisma/models/CodingAgentProfile.d.ts +0 -7
- package/dist/generated/prisma/models/CodingProxySession.d.ts +119 -2
- package/dist/generated/prisma/models/CodingRun.d.ts +76 -1
- package/dist/generated/prisma/models/HostProvider.d.ts +2176 -0
- package/dist/generated/prisma/models/HostProvider.js +1 -0
- package/dist/generated/prisma/models/HostProviderCredential.d.ts +1285 -0
- package/dist/generated/prisma/models/HostProviderCredential.js +1 -0
- package/dist/generated/prisma/models/HostProviderOperation.d.ts +1470 -0
- package/dist/generated/prisma/models/HostProviderOperation.js +1 -0
- package/dist/generated/prisma/models/HostProviderTrustedAccount.d.ts +1145 -0
- package/dist/generated/prisma/models/HostProviderTrustedAccount.js +1 -0
- package/dist/generated/prisma/models/McpServer.d.ts +1500 -0
- package/dist/generated/prisma/models/McpServer.js +1 -0
- package/dist/generated/prisma/models/NativeGatewayCall.d.ts +39 -1
- package/dist/generated/prisma/models/Principal.d.ts +167 -0
- package/dist/generated/prisma/models/ResourceGrant.d.ts +1 -1
- package/dist/generated/prisma/models/Secret.d.ts +387 -0
- package/dist/generated/prisma/models/Tool.d.ts +223 -1
- package/dist/generated/prisma/models.d.ts +6 -0
- package/dist/help/search.js +12 -3
- package/dist/help-index.json +719 -47
- package/dist/import/create.js +16 -1
- package/dist/import/neutral-schema.d.ts +1 -0
- package/dist/import/neutral-schema.js +2 -0
- package/dist/mcp/auth/grants-cli.d.ts +6 -4
- package/dist/mcp/auth/grants-cli.js +42 -3
- package/dist/mcp/auth/resource-server.d.ts +3 -1
- package/dist/mcp/auth/resource-server.js +17 -2
- package/dist/mcp/context.d.ts +3 -0
- package/dist/mcp/index.js +11 -0
- package/dist/mcp/tools/agents.js +100 -15
- package/dist/mcp/tools/grants.js +66 -28
- package/dist/mcp/tools/host-providers.d.ts +2 -0
- package/dist/mcp/tools/host-providers.js +215 -0
- package/dist/mcp/tools/mcp-servers.d.ts +26 -0
- package/dist/mcp/tools/mcp-servers.js +481 -0
- package/dist/mcp/tools/repositories.js +50 -10
- package/dist/mcp/tools/runs.js +178 -18
- package/dist/mcp/tools/secret-elicitation.d.ts +2 -0
- package/dist/mcp/tools/secret-elicitation.js +25 -2
- package/dist/mcp/tools/secrets.js +38 -4
- package/dist/mcp/tools/tools.d.ts +6 -4
- package/dist/mcp/tools/tools.js +40 -8
- package/dist/mcp/tools/trigger.js +28 -6
- package/dist/mcp/transport/http-limits.d.ts +2 -0
- package/dist/mcp/transport/http-limits.js +6 -2
- package/dist/mcp/webhooks/ingress.js +10 -0
- package/dist/native-worker/gateway-server.d.ts +14 -0
- package/dist/native-worker/gateway-server.js +28 -7
- package/dist/native-worker/gateway.d.ts +2 -0
- package/dist/native-worker/gateway.js +5 -1
- package/dist/native-worker/http-server.d.ts +4 -0
- package/dist/native-worker/http-server.js +51 -0
- package/dist/native-worker/ledger.d.ts +6 -2
- package/dist/native-worker/ledger.js +5 -4
- package/dist/native-worker/protocol.d.ts +1 -0
- package/dist/native-worker/protocol.js +4 -1
- package/dist/providers/coding-proxy/capability-hash.d.ts +2 -0
- package/dist/providers/coding-proxy/capability-hash.js +5 -0
- package/dist/providers/coding-proxy/mcp-route.d.ts +34 -0
- package/dist/providers/coding-proxy/mcp-route.js +166 -0
- package/dist/providers/coding-proxy/memory-ledger.d.ts +2 -0
- package/dist/providers/coding-proxy/memory-ledger.js +15 -0
- package/dist/providers/coding-proxy/prisma-ledger.d.ts +1 -0
- package/dist/providers/coding-proxy/prisma-ledger.js +30 -2
- package/dist/providers/coding-proxy/proxy.d.ts +7 -1
- package/dist/providers/coding-proxy/proxy.js +134 -34
- package/dist/providers/coding-proxy/runtime.d.ts +6 -0
- package/dist/providers/coding-proxy/runtime.js +32 -1
- package/dist/providers/coding-proxy/server.d.ts +3 -0
- package/dist/providers/coding-proxy/server.js +10 -0
- package/dist/providers/coding-proxy/types.d.ts +13 -0
- package/dist/providers/executor/composition.js +5 -0
- package/dist/providers/executor/container.d.ts +33 -1
- package/dist/providers/executor/container.js +76 -7
- package/dist/providers/host-tools/invoke.d.ts +37 -0
- package/dist/providers/host-tools/invoke.js +117 -0
- package/dist/providers/host-tools/operations.d.ts +65 -0
- package/dist/providers/host-tools/operations.js +149 -0
- package/dist/providers/host-tools/registry.d.ts +79 -0
- package/dist/providers/host-tools/registry.js +362 -0
- package/dist/providers/host-tools/request-guard.d.ts +17 -0
- package/dist/providers/host-tools/request-guard.js +99 -0
- package/dist/providers/host-tools/self-test.d.ts +64 -0
- package/dist/providers/host-tools/self-test.js +142 -0
- package/dist/providers/jobs/docker-isolation.d.ts +2 -2
- package/dist/providers/jobs/docker-isolation.js +30 -8
- package/dist/providers/jobs/docker.d.ts +8 -0
- package/dist/providers/jobs/docker.js +33 -9
- package/dist/providers/jobs/kubernetes-isolation.d.ts +3 -1
- package/dist/providers/jobs/kubernetes-isolation.js +15 -2
- package/dist/providers/jobs/kubernetes.d.ts +5 -0
- package/dist/providers/jobs/kubernetes.js +6 -1
- package/dist/providers/jobs/types.d.ts +6 -0
- package/dist/providers/review-host/types.d.ts +6 -4
- package/dist/providers/review-host/types.js +1 -1
- package/dist/providers/vcs/git.d.ts +6 -2
- package/dist/providers/vcs/git.js +15 -4
- package/dist/providers/vcs/github.d.ts +2 -71
- package/dist/providers/vcs/github.js +8 -11
- package/dist/providers/vcs/index.d.ts +1 -1
- package/dist/providers/vcs/index.js +1 -1
- package/dist/providers/vcs/remote.d.ts +4 -0
- package/dist/providers/vcs/remote.js +7 -1
- package/dist/providers/vcs/routing.d.ts +12 -6
- package/dist/providers/vcs/routing.js +21 -6
- package/dist/providers/vcs/types.d.ts +71 -3
- package/dist/quickstart/index.d.ts +5 -0
- package/dist/quickstart/index.js +21 -0
- package/dist/quickstart-images.json +1 -1
- package/dist/sandbox/eval-core.d.ts +12 -2
- package/dist/sandbox/eval-core.js +20 -4
- package/dist/sandbox/host-functions.d.ts +4 -0
- package/dist/sandbox/host-functions.js +7 -2
- package/dist/sandbox/limits.d.ts +4 -1
- package/dist/sandbox/limits.js +4 -1
- package/dist/sandbox/run-in-sandbox.d.ts +6 -0
- package/dist/sandbox/run-in-sandbox.js +14 -2
- package/dist/sandbox/safe-fetch.d.ts +2 -0
- package/dist/sandbox/safe-fetch.js +1 -1
- package/dist/sandbox/secret-broker.d.ts +1 -0
- package/dist/sandbox/secret-broker.js +1 -1
- package/dist/sandbox/tool-timeout.d.ts +32 -0
- package/dist/sandbox/tool-timeout.js +52 -0
- package/dist/sandbox/user-tool.d.ts +8 -1
- package/dist/sandbox/user-tool.js +9 -3
- package/dist/viewer/graph.js +2 -1
- package/dist/wardby-bin.js +5 -0
- package/docs/README.md +11 -1
- package/docs/agent-recipes.md +37 -4
- package/docs/architecture-runtime.md +1 -1
- package/docs/claude-code-plugin.md +164 -0
- package/docs/code-review-agents.md +6 -0
- package/docs/coding-agent-setup.md +77 -1
- package/docs/coding-worker-byo-images.md +4 -2
- package/docs/coding-worker-isolation.md +78 -7
- package/docs/debugging-agent-runs.md +242 -0
- package/docs/getting-started-gke.md +5 -4
- package/docs/getting-started-identity-provider.md +43 -37
- package/docs/getting-started.md +8 -0
- package/docs/host-providers.md +294 -0
- package/docs/mcp-servers.md +254 -0
- package/docs/native-sandbox.md +25 -9
- package/docs/security-deployment.md +110 -31
- package/docs/tool-secrets.md +3 -0
- package/docs/viewer-api.md +6 -0
- package/docs/viewer-api.openapi.yml +1 -1
- package/help/admin-viewer.md +4 -0
- package/help/agent-recipes.md +33 -2
- package/help/brokered-secrets.md +3 -0
- package/help/build-claude-code-image.md +1 -1
- package/help/claude-code-run-pane.md +40 -0
- package/help/errors/coding-mcp-pins-unavailable.md +35 -0
- package/help/errors/database-auth-invalid.md +1 -1
- package/help/errors/host-provider-error.md +40 -0
- package/help/errors/host-tool-failed.md +36 -0
- package/help/errors/mcp-call-limit.md +22 -0
- package/help/errors/mcp-call-timeout.md +22 -0
- package/help/errors/mcp-server-auth-failed.md +22 -0
- package/help/errors/mcp-server-credentials-unavailable.md +45 -0
- package/help/errors/mcp-server-error.md +28 -0
- package/help/errors/mcp-server-unreachable.md +22 -0
- package/help/errors/mcp-servers-off.md +21 -0
- package/help/errors/mcp-tool-not-allowed.md +26 -0
- package/help/errors/mcp-tool-removed.md +22 -0
- package/help/errors/mcp-unavailable.md +25 -0
- package/help/errors/native-sandbox-capacity.md +1 -1
- package/help/errors/native-sandbox-deadline-exceeded.md +1 -1
- package/help/errors/native-sandbox-docker-failed.md +1 -1
- package/help/errors/native-sandbox-gateway-error.md +1 -1
- package/help/errors/native-sandbox-gateway-unavailable.md +1 -1
- package/help/errors/native-sandbox-image-not-pinned.md +1 -1
- package/help/errors/native-sandbox-isolation-mismatch.md +1 -1
- package/help/errors/native-sandbox-network-unenforced.md +1 -1
- package/help/errors/native-sandbox-requires-catalog.md +1 -1
- package/help/errors/native-sandbox-unavailable.md +1 -1
- package/help/errors/native-sandbox-warm-delivery-failed.md +1 -1
- package/help/errors/native-sandbox-worker-exited.md +1 -1
- package/help/errors/native-sandbox-worker-lost.md +1 -1
- package/help/errors/native-sandbox-worker-unready.md +1 -1
- package/help/errors/repository-not-listed.md +36 -0
- package/help/errors/repository-required.md +36 -0
- package/help/errors/tool-timeout.md +38 -0
- package/help/host-providers.md +40 -0
- package/help/identity-and-access.md +4 -1
- package/help/mcp-servers.md +73 -0
- package/help/mcp.md +7 -2
- package/help/native-capabilities.md +27 -1
- package/help/native-sandbox.md +1 -1
- package/help/operating-agents.md +16 -0
- package/help/related-pull-requests.md +7 -3
- package/help/repo-instructions-and-skills.md +3 -1
- package/help/resume-runs-locally.md +3 -0
- package/help/stop-run.md +1 -1
- package/help/troubleshooting/coding-workers.md +9 -1
- package/help/troubleshooting/debugging-agent-runs.md +29 -0
- package/package.json +2 -1
- package/prisma/migrations/20261102000000_host_providers/migration.sql +56 -0
- package/prisma/migrations/20261104000000_coding_agent_repository_list/migration.sql +5 -0
- package/prisma/migrations/20261106000000_tool_timeout/migration.sql +4 -0
- package/prisma/migrations/20261107000000_mcp_servers/migration.sql +33 -0
- package/prisma/migrations/20261108000000_coding_mcp/migration.sql +5 -0
- package/prisma/migrations/20261109000000_task_run_index/migration.sql +3 -0
- package/prisma/schema.prisma +159 -14
- package/scripts/git-askpass.sh +1 -1
package/dist/mcp/tools/runs.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { requireAgentAccess } from "../auth/access.js";
|
|
1
|
+
import { agentAccessResolver, readableAgentsWhere, requireAgentAccess } from "../auth/access.js";
|
|
2
|
+
import { requireScope } from "../auth/resource-server.js";
|
|
3
|
+
import { McpError } from "../errors.js";
|
|
4
|
+
import { loadGraphRuns } from "../../viewer/graph.js";
|
|
5
|
+
import { loadJiraConfig } from "../../config/providers.js";
|
|
2
6
|
import { findReadableRun } from "./run-access.js";
|
|
3
|
-
import { publicCodingRunResult, sanitizeDependencyCacheReport } from "../../coding/protocol.js";
|
|
7
|
+
import { publicCodingRunResult, redactTokenShapedValues, sanitizeDependencyCacheReport, } from "../../coding/protocol.js";
|
|
4
8
|
import { countPlanRefusals, summarizeRegistryFetches } from "../../coding/registry/report.js";
|
|
5
9
|
import { summarizePackageAudit } from "../../coding/registry/audit-mode.js";
|
|
6
10
|
import { storedServiceLabels } from "../../coding/services/catalog.js";
|
|
7
11
|
import { textResult } from "./text-result.js";
|
|
8
12
|
import { loadBudgetEvents } from "../../core/budget-events.js";
|
|
13
|
+
import { loadAgentSecretValues, maskNamedSecrets } from "../../core/secret-guard.js";
|
|
14
|
+
import { logger } from "../../core/logger.js";
|
|
15
|
+
const runsLog = logger.child({ module: "mcp-runs" });
|
|
9
16
|
/**
|
|
10
17
|
* Run visibility (resource-sharing grants spec §3.5, A6): a run's output is
|
|
11
18
|
* the triggerer's and the agent owner's, never every reader's. The owner
|
|
@@ -17,45 +24,191 @@ function withOperatorMode(run) {
|
|
|
17
24
|
const mode = run.nativeExecutionMode;
|
|
18
25
|
return { ...run, nativeExecutionMode: mode == null ? null : mode === "sandbox" ? "sandbox" : "control-plane" };
|
|
19
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* A coding run's request as its readers may see it. It can be text a caller or an issue wrote, so
|
|
29
|
+
* the agent's secret values and token-shaped values are masked here on every read. A secret that
|
|
30
|
+
* can't be read means the text can't be checked, so it is withheld; the log carries the error name only.
|
|
31
|
+
*/
|
|
32
|
+
async function requestForReader(ctx, run, request) {
|
|
33
|
+
try {
|
|
34
|
+
const named = await loadAgentSecretValues(ctx.db, ctx.providers.secrets, run.agentId);
|
|
35
|
+
return { request: redactTokenShapedValues(maskNamedSecrets(request, named)) };
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
runsLog.warn({ runId: run.id, errorName: err instanceof Error ? err.name : typeof err }, "could not read the agent's secrets to check a run's request; withholding it");
|
|
39
|
+
return { requestUnavailable: true };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The issue-tracker sites issue links are built from (the admin viewer's own source); none when unset or invalid. */
|
|
43
|
+
function issueSites() {
|
|
44
|
+
try {
|
|
45
|
+
const jira = loadJiraConfig();
|
|
46
|
+
return jira ? { jira: jira.siteUrl } : {};
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What started each run and what it produced, in the admin viewer API's shapes (docs/viewer-api.md):
|
|
54
|
+
* `triggerInfo` (the pull request, issue, schedule or lead behind it), `outcomes` (pull requests opened,
|
|
55
|
+
* comments, checks) and `serviceReadiness` (each coding-run service's state). Only ids and links:
|
|
56
|
+
* repositories, numbers, issue keys, URLs, states and times, never free text. A service's failure
|
|
57
|
+
* `reason` is left out, since it can quote what the service printed.
|
|
58
|
+
*/
|
|
59
|
+
async function runGraphFields(ctx, runIds) {
|
|
60
|
+
const graph = await loadGraphRuns(ctx.db, runIds, issueSites());
|
|
61
|
+
return new Map(graph.map((run) => [
|
|
62
|
+
run.id,
|
|
63
|
+
{
|
|
64
|
+
triggerInfo: run.trigger,
|
|
65
|
+
outcomes: run.outcomes,
|
|
66
|
+
serviceReadiness: run.services.map(({ name, state, attempts, readyAt, failedAt }) => ({
|
|
67
|
+
name,
|
|
68
|
+
state,
|
|
69
|
+
attempts,
|
|
70
|
+
readyAt,
|
|
71
|
+
failedAt,
|
|
72
|
+
})),
|
|
73
|
+
},
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
76
|
+
/** Statuses `active: true` keeps, and that `since` always keeps. */
|
|
77
|
+
const ACTIVE_STATUSES = ["pending", "running"];
|
|
78
|
+
/** Rows returned without an agentId: a default and a cap, since it spans every agent the caller can see. */
|
|
79
|
+
const ACROSS_AGENTS_DEFAULT_LIMIT = 50;
|
|
80
|
+
const ACROSS_AGENTS_MAX_LIMIT = 200;
|
|
81
|
+
/** The `active` and `since` filters, as clauses to AND onto the visibility rule. */
|
|
82
|
+
function runFilters(args) {
|
|
83
|
+
const filters = [];
|
|
84
|
+
if (args.active === true)
|
|
85
|
+
filters.push({ status: { in: ACTIVE_STATUSES } });
|
|
86
|
+
if (args.since !== undefined) {
|
|
87
|
+
const since = new Date(args.since);
|
|
88
|
+
if (Number.isNaN(since.getTime()))
|
|
89
|
+
throw new McpError(400, "since must be an ISO date or time");
|
|
90
|
+
filters.push({
|
|
91
|
+
OR: [{ startedAt: { gte: since } }, { finishedAt: { gte: since } }, { status: { in: ACTIVE_STATUSES } }],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return filters;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Runs across every agent the caller can read, under the same rule as one agent's listing: all runs of
|
|
98
|
+
* agents they own, only the runs they triggered on the rest. With `all` (admin:view, checked by the
|
|
99
|
+
* caller), every run in the deployment, as the admin viewer shows. Rows name their agent and leave
|
|
100
|
+
* out finalText, which can be long and is one get_run away.
|
|
101
|
+
*/
|
|
102
|
+
async function listRunsAcrossAgents(ctx, filters, opts) {
|
|
103
|
+
const [where, accessOf] = await Promise.all([
|
|
104
|
+
opts.all ? Promise.resolve({}) : readableAgentsWhere(ctx),
|
|
105
|
+
agentAccessResolver(ctx),
|
|
106
|
+
]);
|
|
107
|
+
const agents = await ctx.db.agent.findMany({
|
|
108
|
+
where,
|
|
109
|
+
select: { id: true, ownerId: true, name: true, budgetUsd: true },
|
|
110
|
+
});
|
|
111
|
+
const owned = agents.filter((agent) => opts.all || accessOf(agent) === "owner").map((agent) => agent.id);
|
|
112
|
+
const others = agents.filter((agent) => !opts.all && accessOf(agent) !== "owner").map((agent) => agent.id);
|
|
113
|
+
const byId = new Map(agents.map((agent) => [agent.id, agent]));
|
|
114
|
+
// A limit that isn't a finite number falls back to the default rather than reaching the query as NaN.
|
|
115
|
+
const requested = Number.isFinite(opts.limit) ? Math.floor(opts.limit) : ACROSS_AGENTS_DEFAULT_LIMIT;
|
|
116
|
+
const take = Math.min(Math.max(1, requested), ACROSS_AGENTS_MAX_LIMIT);
|
|
117
|
+
const status = opts.status;
|
|
118
|
+
const runs = await ctx.db.run.findMany({
|
|
119
|
+
where: {
|
|
120
|
+
OR: [{ agentId: { in: owned } }, { agentId: { in: others }, triggeredById: ctx.principal.id }],
|
|
121
|
+
...(status ? { status: status } : {}),
|
|
122
|
+
...(filters.length > 0 ? { AND: filters } : {}),
|
|
123
|
+
},
|
|
124
|
+
omit: { finalText: true, pricingSnapshot: true },
|
|
125
|
+
take,
|
|
126
|
+
orderBy: { startedAt: "desc" },
|
|
127
|
+
});
|
|
128
|
+
const graph = await runGraphFields(ctx, runs.map((run) => run.id));
|
|
129
|
+
return runs.map((run) => {
|
|
130
|
+
const agent = byId.get(run.agentId);
|
|
131
|
+
return {
|
|
132
|
+
...run,
|
|
133
|
+
agentName: agent?.name ?? null,
|
|
134
|
+
agentBudgetUsd: agent ? Number(agent.budgetUsd) : null,
|
|
135
|
+
...(graph.get(run.id) ?? { triggerInfo: null, outcomes: [], serviceReadiness: [] }),
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/** Same rule as get_run: a pending coding run with queuedAt is waiting for a concurrency slot (CODING_MAX_CONCURRENT), not stuck. */
|
|
140
|
+
async function withQueuedAt(ctx, runs) {
|
|
141
|
+
const pendingIds = runs.filter((run) => run.status === "pending").map((run) => run.id);
|
|
142
|
+
const queued = pendingIds.length > 0
|
|
143
|
+
? await ctx.db.codingRun.findMany({
|
|
144
|
+
where: { runId: { in: pendingIds }, queuedAt: { not: null } },
|
|
145
|
+
select: { runId: true, queuedAt: true },
|
|
146
|
+
})
|
|
147
|
+
: [];
|
|
148
|
+
const queuedAtByRun = new Map(queued.map((row) => [row.runId, row.queuedAt?.toISOString()]));
|
|
149
|
+
return runs.map((run) => {
|
|
150
|
+
const codingQueuedAt = queuedAtByRun.get(run.id);
|
|
151
|
+
return codingQueuedAt ? { ...withOperatorMode(run), codingQueuedAt } : withOperatorMode(run);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
20
154
|
export function registerRunTools(mcp) {
|
|
21
155
|
mcp.registerTool({
|
|
22
156
|
name: "list_runs",
|
|
23
157
|
scope: "agents:read",
|
|
158
|
+
description: "Lists runs, newest first. With agentId, that agent's runs; without it, runs across every agent you can see " +
|
|
159
|
+
"(each row adds agentName, agentBudgetUsd, triggerInfo, outcomes and serviceReadiness, and leaves out finalText " +
|
|
160
|
+
`and pricingSnapshot; default limit ${ACROSS_AGENTS_DEFAULT_LIMIT}, ` +
|
|
161
|
+
`at most ${ACROSS_AGENTS_MAX_LIMIT}). You see all runs of agents you own and only the runs you triggered on others. ` +
|
|
162
|
+
"active: true keeps pending and running runs; since (ISO time) keeps runs that started or finished then or later, " +
|
|
163
|
+
"plus any still pending or running. all: true (no agentId) lists every run in the deployment (admins only, admin:view). " +
|
|
164
|
+
"Use get_run for one run's detail.",
|
|
24
165
|
inputSchema: {
|
|
25
166
|
type: "object",
|
|
26
|
-
properties: {
|
|
27
|
-
|
|
167
|
+
properties: {
|
|
168
|
+
agentId: { type: "string" },
|
|
169
|
+
status: { type: "string" },
|
|
170
|
+
active: { type: "boolean" },
|
|
171
|
+
since: { type: "string", description: "ISO date or time" },
|
|
172
|
+
all: { type: "boolean" },
|
|
173
|
+
limit: { type: "number" },
|
|
174
|
+
},
|
|
28
175
|
},
|
|
29
176
|
handler: async (args, ctx) => {
|
|
177
|
+
const filters = runFilters(args);
|
|
178
|
+
if (args.all === true) {
|
|
179
|
+
if (args.agentId !== undefined)
|
|
180
|
+
throw new McpError(400, "all lists every agent's runs; leave out agentId");
|
|
181
|
+
if (!ctx.operator)
|
|
182
|
+
requireScope(ctx, ctx.canonicalUri, "admin:view");
|
|
183
|
+
}
|
|
184
|
+
if (args.agentId === undefined) {
|
|
185
|
+
const runs = await listRunsAcrossAgents(ctx, filters, {
|
|
186
|
+
status: args.status,
|
|
187
|
+
limit: args.limit,
|
|
188
|
+
all: args.all === true,
|
|
189
|
+
});
|
|
190
|
+
return textResult(await withQueuedAt(ctx, runs));
|
|
191
|
+
}
|
|
30
192
|
const { access } = await requireAgentAccess(ctx, args.agentId, "read");
|
|
31
193
|
const runs = await ctx.db.run.findMany({
|
|
32
194
|
where: {
|
|
33
195
|
agentId: args.agentId,
|
|
34
196
|
...(args.status ? { status: args.status } : {}),
|
|
35
197
|
...(access === "owner" ? {} : { triggeredById: ctx.principal.id }),
|
|
198
|
+
...(filters.length > 0 ? { AND: filters } : {}),
|
|
36
199
|
},
|
|
37
200
|
take: args.limit,
|
|
38
201
|
orderBy: { startedAt: "desc" },
|
|
39
202
|
});
|
|
40
|
-
|
|
41
|
-
// for a concurrency slot (CODING_MAX_CONCURRENT), not stuck.
|
|
42
|
-
const pendingIds = runs.filter((run) => run.status === "pending").map((run) => run.id);
|
|
43
|
-
const queued = pendingIds.length > 0
|
|
44
|
-
? await ctx.db.codingRun.findMany({
|
|
45
|
-
where: { runId: { in: pendingIds }, queuedAt: { not: null } },
|
|
46
|
-
select: { runId: true, queuedAt: true },
|
|
47
|
-
})
|
|
48
|
-
: [];
|
|
49
|
-
const queuedAtByRun = new Map(queued.map((row) => [row.runId, row.queuedAt?.toISOString()]));
|
|
50
|
-
return textResult(runs.map((run) => {
|
|
51
|
-
const codingQueuedAt = queuedAtByRun.get(run.id);
|
|
52
|
-
return codingQueuedAt ? { ...withOperatorMode(run), codingQueuedAt } : withOperatorMode(run);
|
|
53
|
-
}));
|
|
203
|
+
return textResult(await withQueuedAt(ctx, runs));
|
|
54
204
|
},
|
|
55
205
|
});
|
|
56
206
|
mcp.registerTool({
|
|
57
207
|
name: "get_run",
|
|
58
208
|
scope: "agents:read",
|
|
209
|
+
description: "One run in full: status, cost, request, result, errors and budget events, plus triggerInfo (what started it: " +
|
|
210
|
+
"a pull request review or mention, an issue, a schedule or a lead run), outcomes (pull requests opened, comments, " +
|
|
211
|
+
"checks) and serviceReadiness. A run's pull-request outcome matching another run's triggerInfo links the two.",
|
|
59
212
|
inputSchema: { type: "object", properties: { runId: { type: "string" } }, required: ["runId"] },
|
|
60
213
|
handler: async (args, ctx) => {
|
|
61
214
|
// Its triggerer keeps seeing it even after losing access to the agent;
|
|
@@ -65,6 +218,7 @@ export function registerRunTools(mcp) {
|
|
|
65
218
|
where: { runId: run.id },
|
|
66
219
|
select: {
|
|
67
220
|
result: true,
|
|
221
|
+
request: true,
|
|
68
222
|
queuedAt: true,
|
|
69
223
|
failureCategory: true,
|
|
70
224
|
diagnosticId: true,
|
|
@@ -123,8 +277,14 @@ export function registerRunTools(mcp) {
|
|
|
123
277
|
: undefined;
|
|
124
278
|
// Well-formed refusals only, with group, lead and agent budget filled as the run error's are.
|
|
125
279
|
const budgetEvents = await loadBudgetEvents(ctx.db, run.id);
|
|
280
|
+
// What started the run and what it produced, as the admin viewer shows them.
|
|
281
|
+
const graph = (await runGraphFields(ctx, [run.id])).get(run.id);
|
|
282
|
+
// What the run was asked to do: the trigger's or lead's task, without the agent's standing instructions.
|
|
283
|
+
const request = codingRun?.request ? await requestForReader(ctx, run, codingRun.request) : {};
|
|
126
284
|
return textResult({
|
|
127
285
|
...withOperatorMode(run),
|
|
286
|
+
...request,
|
|
287
|
+
...(graph ?? {}),
|
|
128
288
|
...(budgetEvents.length > 0 ? { budgetEvents } : {}),
|
|
129
289
|
...(codingRun?.budgetReservedUsd != null ? { budgetReservedUsd: Number(codingRun.budgetReservedUsd) } : {}),
|
|
130
290
|
...(codingRun?.budgetBaseUsd != null ? { budgetBaseUsd: Number(codingRun.budgetBaseUsd) } : {}),
|
|
@@ -38,6 +38,8 @@ export interface SecretElicitationPayload {
|
|
|
38
38
|
* removal is refused if the secret's config has changed since (or the link has none).
|
|
39
39
|
*/
|
|
40
40
|
brokerHash?: string;
|
|
41
|
+
/** The caller passed the hosts:admin check when the link was minted. */
|
|
42
|
+
hostManager?: boolean;
|
|
41
43
|
}
|
|
42
44
|
export type SecretElicitationOutcome = {
|
|
43
45
|
ok: true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSecret, listSecrets, setSecretBroker } from "../../core/secrets.js";
|
|
1
|
+
import { createSecret, hostProvidersUsingSecret, listSecrets, setSecretBroker, } from "../../core/secrets.js";
|
|
2
2
|
import { parseSecretBrokerConfig, SECRET_BROKER_CHANGED, } from "../../core/secret-broker-config.js";
|
|
3
3
|
/**
|
|
4
4
|
* A link only does what it was minted for: a create link can't confirm an
|
|
@@ -19,6 +19,18 @@ function kindOf(outcome) {
|
|
|
19
19
|
return outcome.kind ?? "create";
|
|
20
20
|
}
|
|
21
21
|
const ELICITATION_TTL_MS = 600_000;
|
|
22
|
+
const HOST_PROVIDER_LINK_STALE = "host_provider_secret_link_stale: a host provider now uses this secret; request a new link with hosts:admin";
|
|
23
|
+
/**
|
|
24
|
+
* A link minted before the secret joined a host provider carries no hosts:admin check.
|
|
25
|
+
* Refused without recording an outcome, so a fresh link from a host manager still works.
|
|
26
|
+
*/
|
|
27
|
+
async function isStaleForHostProvider(db, payload) {
|
|
28
|
+
if (payload.hostManager)
|
|
29
|
+
return false;
|
|
30
|
+
const { ownerId, secretName: name } = payload;
|
|
31
|
+
const secret = await db.secret.findUnique({ where: { ownerId_name: { ownerId, name } }, select: { id: true } });
|
|
32
|
+
return secret !== null && (await hostProvidersUsingSecret(db, secret.id)).providers.length > 0;
|
|
33
|
+
}
|
|
22
34
|
/** Sweeps every expired entry, not just the one being looked up, so a set-and-never-polled-again entry doesn't linger forever. */
|
|
23
35
|
async function pruneExpired(db, now) {
|
|
24
36
|
await db.secretElicitationOutcome.deleteMany({ where: { expiresAt: { lte: now } } });
|
|
@@ -58,6 +70,9 @@ export async function fulfillSecretElicitation(payload, value, cipher, db, broke
|
|
|
58
70
|
});
|
|
59
71
|
if (existing && kindOf(existing.outcome) === "create")
|
|
60
72
|
return existing.outcome;
|
|
73
|
+
if (await isStaleForHostProvider(db, payload)) {
|
|
74
|
+
return { ok: false, kind: "create", error: HOST_PROVIDER_LINK_STALE };
|
|
75
|
+
}
|
|
61
76
|
let outcome;
|
|
62
77
|
try {
|
|
63
78
|
const secret = await createSecret(secretName, value, ownerId, cipher, db, {
|
|
@@ -89,7 +104,12 @@ export async function fulfillSecretElicitation(payload, value, cipher, db, broke
|
|
|
89
104
|
await recordOutcome(db, ownerId, secretName, outcome, now);
|
|
90
105
|
return outcome;
|
|
91
106
|
}
|
|
92
|
-
const CORRECTABLE_ERRORS = [
|
|
107
|
+
const CORRECTABLE_ERRORS = [
|
|
108
|
+
"secret_broker_value_invalid",
|
|
109
|
+
"secret_broker_config_invalid",
|
|
110
|
+
"bridge_input_limit",
|
|
111
|
+
"host_provider_webhook_secret_short",
|
|
112
|
+
];
|
|
93
113
|
function isCorrectableInput(message) {
|
|
94
114
|
return CORRECTABLE_ERRORS.some((code) => message.startsWith(code));
|
|
95
115
|
}
|
|
@@ -115,6 +135,9 @@ export async function fulfillUnbrokerElicitation(payload, cipher, db) {
|
|
|
115
135
|
});
|
|
116
136
|
if (existing && kindOf(existing.outcome) === "unbroker")
|
|
117
137
|
return existing.outcome;
|
|
138
|
+
if (await isStaleForHostProvider(db, payload)) {
|
|
139
|
+
return { ok: false, kind: "unbroker", error: HOST_PROVIDER_LINK_STALE };
|
|
140
|
+
}
|
|
118
141
|
let outcome;
|
|
119
142
|
try {
|
|
120
143
|
await setSecretBroker(db, cipher, {
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* value/ciphertext at the source); this file adds ownership on top.
|
|
5
5
|
*/
|
|
6
6
|
import { inputRequired, inputResponse } from "@modelcontextprotocol/server";
|
|
7
|
-
import { createSecret, listSecrets, attachSecret, detachSecret, deleteSecret, setSecretBroker, } from "../../core/secrets.js";
|
|
7
|
+
import { createSecret, listSecrets, attachSecret, detachSecret, deleteSecret, hostProvidersUsingSecret, setSecretBroker, WEBHOOK_SECRET_ATTACHED, } from "../../core/secrets.js";
|
|
8
|
+
import { mcpServersUsingSecret } from "../../core/mcp-servers.js";
|
|
8
9
|
import { brokerConfigHash, parseSecretBrokerConfig } from "../../core/secret-broker-config.js";
|
|
9
10
|
import { McpError } from "../errors.js";
|
|
10
11
|
import { requireOwnedSecret } from "../auth/ownership.js";
|
|
12
|
+
import { requireScope } from "../auth/resource-server.js";
|
|
11
13
|
import { requireAgentAccess, requireBindable, requireBindingOwner } from "../auth/access.js";
|
|
12
14
|
import { clearUnbrokerOutcome, getSecretElicitationOutcome, } from "./secret-elicitation.js";
|
|
13
15
|
import { allowedSecretNames, brokerCompatibilityWarnings } from "./secret-broker-compat.js";
|
|
@@ -27,7 +29,9 @@ function mapSecretError(err) {
|
|
|
27
29
|
const message = err instanceof Error ? err.message : String(err);
|
|
28
30
|
if (message.startsWith("secret_not_found"))
|
|
29
31
|
throw new McpError(404, message);
|
|
30
|
-
if (message.startsWith("secret_broker_config_invalid") ||
|
|
32
|
+
if (message.startsWith("secret_broker_config_invalid") ||
|
|
33
|
+
message.startsWith("secret_broker_value_invalid") ||
|
|
34
|
+
message.startsWith("host_provider_webhook_secret_short")) {
|
|
31
35
|
throw new McpError(400, message);
|
|
32
36
|
}
|
|
33
37
|
throw err;
|
|
@@ -70,11 +74,26 @@ async function findOwnSecret(ctx, name) {
|
|
|
70
74
|
throw new McpError(404, `secret_not_found: no secret named "${name}"`);
|
|
71
75
|
return secret;
|
|
72
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A host provider's secret needs hosts:admin as well as secrets:write: replacing a credential
|
|
79
|
+
* or its broker config changes what the provider does. True when the caller passed that check,
|
|
80
|
+
* and its links say so; checked before any link is minted, and again when one is submitted.
|
|
81
|
+
*/
|
|
82
|
+
async function requireHostsAdminIfProviderSecret(ctx, name) {
|
|
83
|
+
const secret = await ctx.db.secret.findUnique({
|
|
84
|
+
where: { ownerId_name: { ownerId: ctx.principal.id, name } },
|
|
85
|
+
select: { id: true },
|
|
86
|
+
});
|
|
87
|
+
if (!secret || (await hostProvidersUsingSecret(ctx.db, secret.id)).providers.length === 0)
|
|
88
|
+
return false;
|
|
89
|
+
requireScope(ctx, ctx.canonicalUri, "hosts:admin");
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
73
92
|
export function registerSecretsTools(mcp, opts) {
|
|
74
93
|
mcp.registerTool({
|
|
75
94
|
name: "create_secret",
|
|
76
95
|
scope: "secrets:write",
|
|
77
|
-
description: 'Creates a secret. Omit "value" to enter it securely via a one-time browser link instead of passing it as a plaintext argument. Pass "broker" ({ hosts, pathPrefixes?, placement }) to make it brokered: tools can then only send it to those hosts with fetch(url, { secrets: [name] }) and can never read it. See the help article "brokered-secrets".',
|
|
96
|
+
description: 'Creates a secret. Omit "value" to enter it securely via a one-time browser link instead of passing it as a plaintext argument. Pass "broker" ({ hosts, pathPrefixes?, placement }) to make it brokered: tools can then only send it to those hosts with fetch(url, { secrets: [name] }) and can never read it. A secret a host provider uses also needs hosts:admin. See the help article "brokered-secrets".',
|
|
78
97
|
inputSchema: {
|
|
79
98
|
type: "object",
|
|
80
99
|
properties: {
|
|
@@ -85,6 +104,7 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
85
104
|
required: ["name"],
|
|
86
105
|
},
|
|
87
106
|
handler: async (args, ctx) => {
|
|
107
|
+
const hostManager = await requireHostsAdminIfProviderSecret(ctx, args.name);
|
|
88
108
|
const broker = args.broker === undefined ? undefined : parseBrokerArg(args.broker);
|
|
89
109
|
if (args.value !== undefined) {
|
|
90
110
|
let secret;
|
|
@@ -131,6 +151,7 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
131
151
|
secretName: args.name,
|
|
132
152
|
kind: "create",
|
|
133
153
|
...(broker ? { broker } : {}),
|
|
154
|
+
...(hostManager ? { hostManager } : {}),
|
|
134
155
|
};
|
|
135
156
|
const token = await mcp.mintRequestState(payload);
|
|
136
157
|
const url = await opts.buildElicitationUrl(token);
|
|
@@ -157,7 +178,7 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
157
178
|
mcp.registerTool({
|
|
158
179
|
name: "set_secret_broker",
|
|
159
180
|
scope: "secrets:write",
|
|
160
|
-
description: 'Sets or changes a secret\'s broker config ({ hosts, pathPrefixes?, placement }), so tools can only send it to those hosts with fetch(url, { secrets: [name] }) and never read it. broker: null removes brokering, which must be confirmed by a person in the browser link this returns. Every change is audited. See the help article "brokered-secrets".',
|
|
181
|
+
description: 'Sets or changes a secret\'s broker config ({ hosts, pathPrefixes?, placement }), so tools can only send it to those hosts with fetch(url, { secrets: [name] }) and never read it. broker: null removes brokering, which must be confirmed by a person in the browser link this returns. Every change is audited. A secret a host provider uses also needs hosts:admin. See the help article "brokered-secrets".',
|
|
161
182
|
inputSchema: {
|
|
162
183
|
type: "object",
|
|
163
184
|
properties: {
|
|
@@ -171,6 +192,7 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
171
192
|
},
|
|
172
193
|
handler: async (args, ctx) => {
|
|
173
194
|
const ownerId = ctx.principal.id;
|
|
195
|
+
const hostManager = await requireHostsAdminIfProviderSecret(ctx, args.name);
|
|
174
196
|
if (args.broker !== null) {
|
|
175
197
|
const broker = parseBrokerArg(args.broker);
|
|
176
198
|
await findOwnSecret(ctx, args.name);
|
|
@@ -222,6 +244,7 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
222
244
|
secretName: args.name,
|
|
223
245
|
kind: "unbroker",
|
|
224
246
|
brokerHash: brokerConfigHash(parseSecretBrokerConfig(secret.broker)),
|
|
247
|
+
...(hostManager ? { hostManager } : {}),
|
|
225
248
|
};
|
|
226
249
|
const token = await mcp.mintRequestState(payload);
|
|
227
250
|
const url = await opts.buildElicitationUrl(token);
|
|
@@ -276,6 +299,8 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
276
299
|
await attachSecret(args.agentId, args.name, ownerId, ctx.db, args.alias ?? args.name);
|
|
277
300
|
}
|
|
278
301
|
catch (err) {
|
|
302
|
+
if (err instanceof Error && err.message === WEBHOOK_SECRET_ATTACHED)
|
|
303
|
+
throw new McpError(409, err.message);
|
|
279
304
|
throw new McpError(404, err instanceof Error ? err.message : String(err));
|
|
280
305
|
}
|
|
281
306
|
return textResult({ attached: true });
|
|
@@ -306,6 +331,15 @@ export function registerSecretsTools(mcp, opts) {
|
|
|
306
331
|
inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
307
332
|
handler: async (args, ctx) => {
|
|
308
333
|
await requireOwnedSecret(ctx.db, args.id, ctx.principal.id);
|
|
334
|
+
const { providers } = await hostProvidersUsingSecret(ctx.db, args.id);
|
|
335
|
+
if (providers.length > 0) {
|
|
336
|
+
throw new McpError(409, `This secret is used by host provider ${providers.map((p) => `"${p}"`).join(", ")}; re-register it or delete_host_provider first.`);
|
|
337
|
+
}
|
|
338
|
+
const secret = await ctx.db.secret.findUnique({ where: { id: args.id }, select: { name: true } });
|
|
339
|
+
const servers = secret ? await mcpServersUsingSecret(ctx.db, ctx.principal.id, secret.name) : [];
|
|
340
|
+
if (servers.length > 0) {
|
|
341
|
+
throw new McpError(409, `Secret "${secret.name}" is used by MCP server(s) ${servers.join(", ")}; update or delete them first.`);
|
|
342
|
+
}
|
|
309
343
|
await deleteSecret(args.id, ctx.db);
|
|
310
344
|
return textResult({ deleted: args.id });
|
|
311
345
|
},
|
|
@@ -21,6 +21,7 @@ export declare function projectTool(tool: Tool, principalId: string): {
|
|
|
21
21
|
name: string;
|
|
22
22
|
updatedAt: Date;
|
|
23
23
|
code: string;
|
|
24
|
+
timeoutMs: number | null;
|
|
24
25
|
createdAt: Date;
|
|
25
26
|
id: string;
|
|
26
27
|
ownerId: string | null;
|
|
@@ -28,16 +29,17 @@ export declare function projectTool(tool: Tool, principalId: string): {
|
|
|
28
29
|
jsonSchema: import("@prisma/client/runtime/client").JsonValue;
|
|
29
30
|
paramsZod: string;
|
|
30
31
|
} | {
|
|
32
|
+
public: boolean;
|
|
31
33
|
id: string;
|
|
32
34
|
name: string;
|
|
33
35
|
description: string;
|
|
34
|
-
|
|
35
|
-
ownerIsCaller?: undefined;
|
|
36
|
+
timeoutMs: number | null;
|
|
36
37
|
} | {
|
|
38
|
+
public: boolean;
|
|
39
|
+
ownerIsCaller: boolean;
|
|
37
40
|
id: string;
|
|
38
41
|
name: string;
|
|
39
42
|
description: string;
|
|
40
|
-
|
|
41
|
-
ownerIsCaller: boolean;
|
|
43
|
+
timeoutMs: number | null;
|
|
42
44
|
};
|
|
43
45
|
export declare function registerToolAuthoringTools(mcp: WardbyMcpServer): void;
|
package/dist/mcp/tools/tools.js
CHANGED
|
@@ -13,9 +13,11 @@ import { Prisma } from "#prisma";
|
|
|
13
13
|
import { deriveJsonSchema, validateParams } from "../../sandbox/zod-params.js";
|
|
14
14
|
import { cachedZod4Compatibility, toolSubject, withZod3ToolWarnings, zod3SampleArgsWarning, zod3ToolWarnings, zod3WindowWarning, } from "../../core/zod3-window.js";
|
|
15
15
|
import { runInSandbox } from "../../sandbox/run-in-sandbox.js";
|
|
16
|
+
import { effectiveToolTimeoutMs, toolTimeoutProblem } from "../../sandbox/tool-timeout.js";
|
|
17
|
+
import { loadToolMaxTimeoutMs } from "../../config/tool-timeout.js";
|
|
16
18
|
import { ToolCapabilitiesPatchSchema } from "../../sandbox/tool-capabilities.js";
|
|
17
19
|
import { buildSharedDatastoreAccessor } from "../../core/datastores.js";
|
|
18
|
-
import { findSameNamedAttachedTool, reservedToolNameReason } from "../../core/tool-names.js";
|
|
20
|
+
import { findSameNamedAttachedTool, findSameNamedMcpTool, reservedToolNameReason, sameNamedMcpToolMessage, } from "../../core/tool-names.js";
|
|
19
21
|
import { ToolAttachedError, deleteToolGuarded, hasToolChanges, prepareToolUpdate, updateToolGuarded, } from "../../core/tool-admin.js";
|
|
20
22
|
import { McpError } from "../errors.js";
|
|
21
23
|
import { requireOwnedTool, requireStrictlyOwnedTool, assertStrictlyOwnedTool, visibleToPrincipal, canRead, } from "../auth/ownership.js";
|
|
@@ -46,9 +48,16 @@ async function describeAgents(agents, ctx) {
|
|
|
46
48
|
export function projectTool(tool, principalId) {
|
|
47
49
|
if (tool.ownerId !== null && tool.ownerId === principalId)
|
|
48
50
|
return tool;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
// timeoutMs is not code: anyone who sees the tool sees how long its calls may take.
|
|
52
|
+
const shown = { id: tool.id, name: tool.name, description: tool.description, timeoutMs: tool.timeoutMs };
|
|
53
|
+
return tool.ownerId === null ? { ...shown, public: true } : { ...shown, public: false, ownerIsCaller: false };
|
|
54
|
+
}
|
|
55
|
+
const TIMEOUT_MS_DESCRIPTION = "The tool's time limit per call, in milliseconds (at least 1000). Omitted: the default of 10000. Capped by the server's WARDBY_TOOL_MAX_TIMEOUT_MS (default 300000); a larger value is refused. Each fetch times out just before it, and sleep() is capped at it.";
|
|
56
|
+
/** Refuses (400) a timeoutMs this server can't store, naming its ceiling. */
|
|
57
|
+
function assertToolTimeout(timeoutMs) {
|
|
58
|
+
const problem = toolTimeoutProblem(timeoutMs, loadToolMaxTimeoutMs());
|
|
59
|
+
if (problem)
|
|
60
|
+
throw new McpError(400, problem);
|
|
52
61
|
}
|
|
53
62
|
/**
|
|
54
63
|
* Non-blocking: which of the secrets just granted to this attachment are
|
|
@@ -83,11 +92,14 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
83
92
|
description: { type: "string" },
|
|
84
93
|
paramsZod: { type: "string" },
|
|
85
94
|
code: { type: "string" },
|
|
95
|
+
timeoutMs: { type: "integer", description: TIMEOUT_MS_DESCRIPTION },
|
|
86
96
|
},
|
|
87
97
|
required: ["name", "description", "paramsZod", "code"],
|
|
88
98
|
},
|
|
89
99
|
handler: async (args, ctx) => {
|
|
90
100
|
assertToolNameAllowed(args.name);
|
|
101
|
+
if (args.timeoutMs !== undefined)
|
|
102
|
+
assertToolTimeout(args.timeoutMs);
|
|
91
103
|
const schemaResult = await deriveJsonSchema(args.paramsZod);
|
|
92
104
|
if (!schemaResult.ok) {
|
|
93
105
|
return textResult({ ok: false, errorKind: schemaResult.errorKind, errorMessage: schemaResult.errorMessage });
|
|
@@ -101,6 +113,7 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
101
113
|
code: args.code,
|
|
102
114
|
jsonSchema: schemaResult.value,
|
|
103
115
|
ownerId: ctx.principal.id,
|
|
116
|
+
...(args.timeoutMs !== undefined ? { timeoutMs: args.timeoutMs } : {}),
|
|
104
117
|
},
|
|
105
118
|
});
|
|
106
119
|
const warnings = await zod3ToolWarnings(toolSubject(tool.name), args.paramsZod);
|
|
@@ -117,7 +130,7 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
117
130
|
mcp.registerTool({
|
|
118
131
|
name: "update_tool",
|
|
119
132
|
scope: "tools:write",
|
|
120
|
-
description: "Replaces a tool's description, paramsZod and/or
|
|
133
|
+
description: "Replaces a tool's description, paramsZod, code and/or timeoutMs (null: back to the default limit) in place (its name can't change: agents' prompts call it by name). Owner-only: public tools can't be changed over MCP. Refused while the tool is attached to any agent you don't own, including owner-less ones and agents shared with you, since the change would reach another owner's agent; detach it there first or create a new tool. Runs already started keep the version they loaded for their whole lifetime; the next run picks up the new one.",
|
|
121
134
|
inputSchema: {
|
|
122
135
|
type: "object",
|
|
123
136
|
additionalProperties: false,
|
|
@@ -126,14 +139,25 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
126
139
|
description: { type: "string" },
|
|
127
140
|
paramsZod: { type: "string" },
|
|
128
141
|
code: { type: "string" },
|
|
142
|
+
timeoutMs: {
|
|
143
|
+
type: ["integer", "null"],
|
|
144
|
+
description: `${TIMEOUT_MS_DESCRIPTION} Pass null to go back to the default.`,
|
|
145
|
+
},
|
|
129
146
|
},
|
|
130
147
|
required: ["toolId"],
|
|
131
148
|
},
|
|
132
149
|
handler: async (args, ctx) => {
|
|
133
|
-
const changes = {
|
|
150
|
+
const changes = {
|
|
151
|
+
description: args.description,
|
|
152
|
+
paramsZod: args.paramsZod,
|
|
153
|
+
code: args.code,
|
|
154
|
+
timeoutMs: args.timeoutMs,
|
|
155
|
+
};
|
|
134
156
|
if (!hasToolChanges(changes)) {
|
|
135
|
-
throw new McpError(400, "update_tool needs at least one of description, paramsZod or
|
|
157
|
+
throw new McpError(400, "update_tool needs at least one of description, paramsZod, code or timeoutMs.");
|
|
136
158
|
}
|
|
159
|
+
if (args.timeoutMs !== undefined && args.timeoutMs !== null)
|
|
160
|
+
assertToolTimeout(args.timeoutMs);
|
|
137
161
|
// Checked once up front so a non-owner never gets as far as a sandbox
|
|
138
162
|
// compile, and again (with the attachments) inside the transaction.
|
|
139
163
|
await requireStrictlyOwnedTool(ctx.db, args.toolId, ctx.principal.id);
|
|
@@ -196,7 +220,7 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
196
220
|
mcp.registerTool({
|
|
197
221
|
name: "dry_run_tool",
|
|
198
222
|
scope: "tools:write",
|
|
199
|
-
description: "Test-runs tool code against sample args without persisting it. Fetch is denied by default, same as a freshly attached tool — pass allowedHosts to test code that calls fetch(). For this release a paramsZod is still compiled with Zod 3; a `warnings` list in the result means the next release, which compiles it with Zod 4 only, will reject it or treat the sample args differently.",
|
|
223
|
+
description: "Test-runs tool code against sample args without persisting it, with the same time limit a run would give it (timeoutMs, as on create_tool). Fetch is denied by default, same as a freshly attached tool — pass allowedHosts to test code that calls fetch(). For this release a paramsZod is still compiled with Zod 3; a `warnings` list in the result means the next release, which compiles it with Zod 4 only, will reject it or treat the sample args differently.",
|
|
200
224
|
inputSchema: {
|
|
201
225
|
type: "object",
|
|
202
226
|
properties: {
|
|
@@ -204,10 +228,13 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
204
228
|
code: { type: "string" },
|
|
205
229
|
sampleArgs: { type: "object" },
|
|
206
230
|
allowedHosts: { type: "array", items: { type: "string" } },
|
|
231
|
+
timeoutMs: { type: "integer", description: TIMEOUT_MS_DESCRIPTION },
|
|
207
232
|
},
|
|
208
233
|
required: ["paramsZod", "code", "sampleArgs"],
|
|
209
234
|
},
|
|
210
235
|
handler: async (args, ctx) => {
|
|
236
|
+
if (args.timeoutMs !== undefined)
|
|
237
|
+
assertToolTimeout(args.timeoutMs);
|
|
211
238
|
const hosts = ToolCapabilitiesPatchSchema.pick({ allowedHosts: true }).safeParse({
|
|
212
239
|
allowedHosts: args.allowedHosts,
|
|
213
240
|
});
|
|
@@ -254,6 +281,7 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
254
281
|
sharedDatastore: buildSharedDatastoreAccessor(ctx.principal.id, ctx.providers.datastore, ctx.db),
|
|
255
282
|
toolName: "dry_run_tool",
|
|
256
283
|
allowedFetchHosts: hosts.data.allowedHosts ?? [],
|
|
284
|
+
timeoutMs: effectiveToolTimeoutMs(args.timeoutMs, loadToolMaxTimeoutMs()),
|
|
257
285
|
});
|
|
258
286
|
return textResult({ jsonSchema, result: sandboxResult, ...warnings });
|
|
259
287
|
},
|
|
@@ -334,6 +362,10 @@ export function registerToolAuthoringTools(mcp) {
|
|
|
334
362
|
: " (a tool owned by another principal)";
|
|
335
363
|
throw new McpError(409, `Agent "${args.agentId}" already has a different tool named "${tool.name}" attached${which}; detach it first.`);
|
|
336
364
|
}
|
|
365
|
+
// Nor a name one of the agent's MCP servers already gives the model.
|
|
366
|
+
const mcpClash = await findSameNamedMcpTool(tx, args.agentId, tool.name);
|
|
367
|
+
if (mcpClash)
|
|
368
|
+
throw new McpError(409, sameNamedMcpToolMessage(args.agentId, tool.name, mcpClash.serverName));
|
|
337
369
|
// Re-granting an attachment this owner never vouched for: what is
|
|
338
370
|
// not restated is reset, never silently adopted.
|
|
339
371
|
const keepUnstated = existing?.capabilitiesGrantedById === agent.ownerId;
|