operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/dist/agent/agent.d.ts +8 -7
- package/dist/agent/compose-hooks.d.ts +10 -1
- package/dist/agent/compose-hooks.js +61 -6
- package/dist/agent/concurrency.js +1 -1
- package/dist/agent/context-report.d.ts +2 -2
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/run-support.d.ts +1 -1
- package/dist/agent/run-support.js +6 -5
- package/dist/agent/runner.d.ts +25 -22
- package/dist/agent/runner.js +217 -121
- package/dist/agent/session.d.ts +262 -156
- package/dist/agent/session.js +590 -418
- package/dist/agent/subagent-tools.js +3 -3
- package/dist/agent/subagent.js +28 -13
- package/dist/agent/toolset.d.ts +1 -0
- package/dist/agent/toolset.js +13 -7
- package/dist/agent/workflow/journal.d.ts +2 -2
- package/dist/agent/workflow/journal.js +2 -2
- package/dist/agent/workflow/manager.d.ts +1 -1
- package/dist/agent/workflow/manager.js +1 -1
- package/dist/agent/workflow/prompt.js +2 -2
- package/dist/agent/workflow/sandbox.d.ts +1 -1
- package/dist/agent/workflow/sandbox.js +1 -1
- package/dist/agent/workflow/tool.js +30 -43
- package/dist/agent/worktree.d.ts +8 -8
- package/dist/agent/worktree.js +15 -15
- package/dist/capabilities/assembler.d.ts +29 -5
- package/dist/capabilities/assembler.js +85 -9
- package/dist/capabilities/background/code-task.d.ts +43 -0
- package/dist/capabilities/background/code-task.js +75 -0
- package/dist/capabilities/background/command-task.d.ts +9 -2
- package/dist/capabilities/background/command-task.js +22 -6
- package/dist/capabilities/background/index.d.ts +6 -1
- package/dist/capabilities/background/index.js +26 -20
- package/dist/capabilities/background/manager.d.ts +57 -1
- package/dist/capabilities/background/manager.js +210 -45
- package/dist/capabilities/background/persist-disk.d.ts +1 -1
- package/dist/capabilities/background/persist-disk.js +1 -1
- package/dist/capabilities/background/persist.js +4 -2
- package/dist/capabilities/background/projections.d.ts +16 -0
- package/dist/capabilities/background/projections.js +86 -0
- package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
- package/dist/capabilities/background/stall-watchdog.js +85 -0
- package/dist/capabilities/background/task.d.ts +8 -7
- package/dist/capabilities/background/tools.js +33 -7
- package/dist/capabilities/capability-data.d.ts +52 -0
- package/dist/capabilities/capability-data.js +88 -0
- package/dist/capabilities/capability-state.d.ts +2 -4
- package/dist/capabilities/capability-state.js +5 -23
- package/dist/capabilities/capability.d.ts +203 -38
- package/dist/capabilities/compaction/index.js +10 -4
- package/dist/capabilities/compaction/service.d.ts +20 -5
- package/dist/capabilities/compaction/service.js +27 -11
- package/dist/capabilities/goal/goal-store.d.ts +76 -12
- package/dist/capabilities/goal/goal-store.js +137 -53
- package/dist/capabilities/goal/index.d.ts +1 -1
- package/dist/capabilities/goal/index.js +30 -7
- package/dist/capabilities/index.d.ts +9 -6
- package/dist/capabilities/index.js +4 -3
- package/dist/capabilities/plan/index.js +22 -5
- package/dist/capabilities/plan/plan-mode.d.ts +30 -9
- package/dist/capabilities/plan/plan-mode.js +57 -32
- package/dist/capabilities/plan/tools.js +1 -1
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +13 -1
- package/dist/capabilities/skills/index.js +30 -21
- package/dist/capabilities/skills/parser.d.ts +2 -2
- package/dist/capabilities/skills/parser.js +3 -3
- package/dist/capabilities/skills/registry.d.ts +5 -6
- package/dist/capabilities/skills/registry.js +6 -9
- package/dist/capabilities/skills/scanner.d.ts +3 -3
- package/dist/capabilities/skills/scanner.js +14 -14
- package/dist/capabilities/skills/service.d.ts +2 -1
- package/dist/capabilities/skills/service.js +3 -3
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +2 -1
- package/dist/capabilities/task/persist-disk.d.ts +1 -1
- package/dist/capabilities/task/persist-disk.js +1 -1
- package/dist/capabilities/task/persist.js +1 -1
- package/dist/capabilities/todo/index.js +11 -6
- package/dist/capabilities/todo/injector.js +2 -1
- package/dist/capabilities/todo/todo-store.d.ts +28 -7
- package/dist/capabilities/todo/todo-store.js +44 -11
- package/dist/capabilities/todo/tools.js +8 -3
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.js +7 -7
- package/dist/capabilities/user-hooks/index.js +2 -1
- package/dist/capabilities/workflow/index.d.ts +5 -3
- package/dist/capabilities/workflow/index.js +3 -2
- package/dist/commands/index.js +34 -32
- package/dist/config/index.d.ts +1 -1
- package/dist/config/provider-manager.js +0 -28
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/events/events.d.ts +43 -11
- package/dist/events/events.js +1 -0
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/projection.d.ts +49 -1
- package/dist/events/projection.js +144 -19
- package/dist/events/publisher.js +2 -21
- package/dist/home.d.ts +1 -1
- package/dist/home.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/llm/define-model.d.ts +4 -0
- package/dist/llm/define-model.js +63 -25
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/model.d.ts +2 -0
- package/dist/llm/provider.d.ts +17 -0
- package/dist/llm/provider.js +14 -0
- package/dist/llm/retry.js +1 -1
- package/dist/loop/context.d.ts +21 -1
- package/dist/loop/context.js +47 -9
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/index.d.ts +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/interruption.d.ts +9 -4
- package/dist/loop/interruption.js +11 -25
- package/dist/loop/run-turn.d.ts +16 -3
- package/dist/loop/run-turn.js +13 -4
- package/dist/loop/steer.d.ts +78 -12
- package/dist/loop/steer.js +101 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +135 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +29 -7
- package/dist/loop/types.d.ts +6 -0
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/capability.d.ts +13 -0
- package/dist/mcp/capability.js +36 -17
- package/dist/mcp/config-loader.d.ts +5 -5
- package/dist/mcp/config-loader.js +17 -17
- package/dist/mcp/credentials.d.ts +35 -0
- package/dist/mcp/credentials.js +2 -0
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +4 -3
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +108 -6
- package/dist/mcp/manager.js +262 -18
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +82 -16
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +31 -1
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/manager.d.ts +5 -3
- package/dist/permission/manager.js +7 -3
- package/dist/permission/policies.d.ts +2 -2
- package/dist/permission/policies.js +4 -4
- package/dist/plugins/fields.d.ts +14 -0
- package/dist/plugins/fields.js +30 -0
- package/dist/plugins/hooks.d.ts +2 -2
- package/dist/plugins/hooks.js +12 -12
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/manager.d.ts +8 -3
- package/dist/plugins/manager.js +18 -7
- package/dist/plugins/manifest.d.ts +2 -2
- package/dist/plugins/manifest.js +101 -91
- package/dist/plugins/marketplace.js +76 -57
- package/dist/plugins/store.d.ts +3 -3
- package/dist/plugins/store.js +6 -6
- package/dist/protocol/index.d.ts +1 -1
- package/dist/store/catalog-store.d.ts +4 -1
- package/dist/store/catalog-store.js +5 -1
- package/dist/store/checkpointing-store.d.ts +41 -0
- package/dist/store/checkpointing-store.js +86 -0
- package/dist/store/disk-store.d.ts +8 -0
- package/dist/store/disk-store.js +127 -5
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +2 -1
- package/dist/store/log-store.d.ts +9 -1
- package/dist/store/log-store.js +68 -4
- package/dist/store/migrate.d.ts +8 -2
- package/dist/store/migrate.js +9 -2
- package/dist/store/origin.d.ts +31 -6
- package/dist/store/origin.js +0 -14
- package/dist/store/pg.d.ts +1 -0
- package/dist/store/pg.js +37 -2
- package/dist/store/redis.d.ts +1 -0
- package/dist/store/redis.js +30 -0
- package/dist/store/repository.d.ts +13 -1
- package/dist/store/repository.js +45 -2
- package/dist/store/session-catalog.d.ts +4 -0
- package/dist/store/session-catalog.js +6 -0
- package/dist/store/storage.js +3 -0
- package/dist/store/store.d.ts +97 -34
- package/dist/store/store.js +64 -10
- package/dist/telemetry/appender.d.ts +43 -0
- package/dist/telemetry/appender.js +46 -0
- package/dist/telemetry/events.d.ts +142 -0
- package/dist/telemetry/events.js +141 -0
- package/dist/telemetry/index.d.ts +10 -0
- package/dist/telemetry/index.js +6 -0
- package/dist/telemetry/projection.d.ts +23 -0
- package/dist/telemetry/projection.js +185 -0
- package/dist/telemetry/redact.d.ts +20 -0
- package/dist/telemetry/redact.js +40 -0
- package/dist/telemetry/service.d.ts +49 -0
- package/dist/telemetry/service.js +137 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +123 -0
- package/dist/tool/background.d.ts +9 -6
- package/dist/tool/background.js +7 -1
- package/dist/tool/builtin/ask-user-question.js +6 -5
- package/dist/tool/builtin/bash.d.ts +6 -0
- package/dist/tool/builtin/bash.js +79 -42
- package/dist/tool/builtin/edit.js +82 -109
- package/dist/tool/builtin/glob.js +13 -13
- package/dist/tool/builtin/grep.js +13 -13
- package/dist/tool/builtin/read.js +25 -15
- package/dist/tool/builtin/write.js +49 -33
- package/dist/tool/define.d.ts +14 -8
- package/dist/tool/define.js +8 -2
- package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
- package/dist/tool/{machine-base.js → environment-base.js} +45 -119
- package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
- package/dist/tool/{machine-local.js → environment-local.js} +60 -81
- package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
- package/dist/tool/{machine-null.js → environment-null.js} +9 -9
- package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
- package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
- package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
- package/dist/tool/environment.js +2 -0
- package/dist/tool/file-freshness.d.ts +33 -19
- package/dist/tool/file-freshness.js +39 -30
- package/dist/tool/filesystem-tools.d.ts +1 -1
- package/dist/tool/filesystem-tools.js +1 -1
- package/dist/tool/git-context.d.ts +2 -2
- package/dist/tool/git-context.js +8 -8
- package/dist/tool/index.d.ts +12 -12
- package/dist/tool/index.js +12 -10
- package/dist/tool/policies/path-access.d.ts +4 -4
- package/dist/tool/policies/path-access.js +12 -12
- package/dist/tool/questions.d.ts +8 -0
- package/dist/tool/search/catalog.d.ts +37 -0
- package/dist/tool/search/catalog.js +182 -0
- package/dist/tool/search/deferral.d.ts +3 -2
- package/dist/tool/search/loaded.d.ts +32 -0
- package/dist/tool/search/loaded.js +96 -0
- package/dist/tool/search/search-tool.d.ts +2 -6
- package/dist/tool/search/search-tool.js +16 -15
- package/dist/tool/shell-env.js +4 -0
- package/dist/tool/support/bash-paths.js +38 -7
- package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
- package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
- package/dist/tool/support/git-worktree.d.ts +3 -3
- package/dist/tool/support/git-worktree.js +6 -6
- package/dist/tool/support/rg-locator.d.ts +6 -6
- package/dist/tool/support/rg-locator.js +6 -6
- package/dist/tool/support/ripgrep-run.d.ts +5 -5
- package/dist/tool/support/ripgrep-run.js +3 -3
- package/dist/tool/support/tool-path.d.ts +3 -3
- package/dist/tool/support/tool-path.js +7 -7
- package/dist/tool/types.d.ts +54 -10
- package/dist/tool/web/fetch-url.js +1 -1
- package/dist/tool/web/web-search.js +1 -1
- package/dist/tool/workspace-spec.d.ts +3 -3
- package/dist/tool/workspace-spec.js +27 -27
- package/dist/tracing/bridge.d.ts +9 -1
- package/dist/tracing/bridge.js +307 -77
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/otel.d.ts +28 -1
- package/dist/tracing/otel.js +150 -38
- package/dist/tracing/processor.d.ts +22 -0
- package/dist/tracing/processor.js +2 -0
- package/dist/tracing/spans.d.ts +54 -0
- package/dist/tracing/spans.js +5 -0
- package/package.json +6 -2
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
package/dist/loop/turn-step.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runToolCallBatch } from "./tool-call.js";
|
|
2
2
|
import { streamWithRetry } from "../llm/retry.js";
|
|
3
3
|
import { APIContextOverflowError, isContextOverflowMessage } from "../llm/errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { describeUnknownTool, prepareToolCatalog, withToolLoads } from "../tool/search/catalog.js";
|
|
5
5
|
export async function executeStep(deps) {
|
|
6
6
|
const { turnId, signal, model, currentStep, hooks } = deps;
|
|
7
7
|
const messages = deps.context.messages; // backing array (reads/slices share this ref)
|
|
@@ -30,12 +30,20 @@ export async function executeStep(deps) {
|
|
|
30
30
|
// Compaction runs in beforeStep. Recompute afterwards so full compaction
|
|
31
31
|
// unloads removed load points immediately, while a SearchTool result from the
|
|
32
32
|
// preceding step activates its schemas for this request.
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
const snapshot = deps.refreshTools ? await deps.refreshTools() : deps;
|
|
34
|
+
signal.throwIfAborted();
|
|
35
|
+
const prepared = prepareToolCatalog(deps.context, snapshot);
|
|
36
|
+
for (const warning of prepared.warnings)
|
|
37
|
+
deps.logger?.log("warn", warning);
|
|
38
|
+
const activeTools = prepared.tools;
|
|
39
|
+
deps.onToolsPrepared?.(activeTools);
|
|
40
|
+
const toolSchemas = prepared.requestTools;
|
|
35
41
|
const toolMap = new Map(activeTools.map((tool) => [tool.schema.name, tool]));
|
|
36
42
|
let request = {
|
|
37
43
|
system,
|
|
38
|
-
messages
|
|
44
|
+
messages: prepared.deferEnabled
|
|
45
|
+
? withToolLoads(deps.context, new Set(toolSchemas.map((schema) => schema.name)))
|
|
46
|
+
: messages,
|
|
39
47
|
tools: toolSchemas.length > 0 ? toolSchemas : undefined,
|
|
40
48
|
...(deps.params ? { params: deps.params } : {}),
|
|
41
49
|
// Per conversation line, not per session: each address carries its own prefix, so keying
|
|
@@ -62,6 +70,7 @@ export async function executeStep(deps) {
|
|
|
62
70
|
request = beforeModel.request;
|
|
63
71
|
}
|
|
64
72
|
signal.throwIfAborted();
|
|
73
|
+
deps.onRequestPrepared?.(request);
|
|
65
74
|
const stepId = `${turnId}.${currentStep}`;
|
|
66
75
|
const outputGuardrail = deps.createOutputGuardrailMonitor?.({
|
|
67
76
|
turnId,
|
|
@@ -71,6 +80,19 @@ export async function executeStep(deps) {
|
|
|
71
80
|
});
|
|
72
81
|
const call = { signal: outputGuardrail?.signal ?? signal };
|
|
73
82
|
deps.dispatchEvent?.({ type: "turn.step.started", turnId, step: currentStep, stepId });
|
|
83
|
+
// The final request, after both hooks — the only place the system prompt reaches the stream.
|
|
84
|
+
// `messages` is snapshotted: `request.messages` may alias the live context array, which this
|
|
85
|
+
// very step appends to below.
|
|
86
|
+
deps.dispatchEvent?.({
|
|
87
|
+
type: "model.request",
|
|
88
|
+
turnId,
|
|
89
|
+
step: currentStep,
|
|
90
|
+
stepId,
|
|
91
|
+
...(request.system !== undefined ? { system: request.system } : {}),
|
|
92
|
+
messages: [...request.messages],
|
|
93
|
+
toolNames: (request.tools ?? []).map((tool) => tool.name),
|
|
94
|
+
...(request.params !== undefined ? { params: request.params } : {}),
|
|
95
|
+
});
|
|
74
96
|
let message;
|
|
75
97
|
let stopReason;
|
|
76
98
|
let stopTurnAfterUsage = false;
|
|
@@ -110,7 +132,7 @@ export async function executeStep(deps) {
|
|
|
110
132
|
});
|
|
111
133
|
},
|
|
112
134
|
// A dropped failed attempt is a transcript record, not an event (#8) — replay must not resurrect it.
|
|
113
|
-
onDropPartial: (failed) => deps.context.
|
|
135
|
+
onDropPartial: (failed) => deps.context.audit({ type: "custom", name: "dropped_partial", data: failed }),
|
|
114
136
|
});
|
|
115
137
|
message = retryResult.message;
|
|
116
138
|
if (hooks?.afterModelResponse) {
|
|
@@ -140,7 +162,7 @@ export async function executeStep(deps) {
|
|
|
140
162
|
// The adapter reduced the transport error to a message string, hence the text match and
|
|
141
163
|
// the synthetic status code 0.
|
|
142
164
|
if (stopReason === "error" && isContextOverflowMessage(message.errorMessage ?? "")) {
|
|
143
|
-
deps.context.
|
|
165
|
+
deps.context.audit({ type: "custom", name: "overflow_dropped", data: message });
|
|
144
166
|
throw new APIContextOverflowError(0, message.errorMessage ?? "context overflow", null);
|
|
145
167
|
}
|
|
146
168
|
// Preserve usage even when an optimistic/final output guardrail rejects the message.
|
|
@@ -169,7 +191,7 @@ export async function executeStep(deps) {
|
|
|
169
191
|
let effectiveStopReason = stopTurnAfterUsage && stopReason === "tool_use" ? "end_turn" : stopReason;
|
|
170
192
|
let handoff;
|
|
171
193
|
if (effectiveStopReason === "tool_use") {
|
|
172
|
-
const batch = await runToolCallBatch({ turnId, stepNumber: currentStep, address: deps.address, signal, model,
|
|
194
|
+
const batch = await runToolCallBatch({ turnId, stepNumber: currentStep, address: deps.address, signal, model, environment: deps.environment, background: deps.background, responder: deps.responder, fileLedger: deps.fileLedger, hostContext: deps.hostContext, tools: toolMap, describeUnknownTool: (name) => describeUnknownTool(prepared, name), hooks, dispatchEvent: deps.dispatchEvent, logger: deps.logger, answers: deps.answers }, message);
|
|
173
195
|
// Each toolResult enters history and is surfaced via `message.appended` (by the journal),
|
|
174
196
|
// parallel to — not replacing — the `tool.result` runtime event from the tool-call layer.
|
|
175
197
|
for (const result of batch.results)
|
package/dist/loop/types.d.ts
CHANGED
|
@@ -122,6 +122,12 @@ export interface AfterStepContext extends ContextStepHookContext {
|
|
|
122
122
|
export interface StoppedStepContext extends StepHookContext {
|
|
123
123
|
readonly usage: Usage;
|
|
124
124
|
readonly stopReason: TerminalStepStopReason;
|
|
125
|
+
/**
|
|
126
|
+
* False when the frame that stopped is a subagent's or a workflow agent's — one the Runner
|
|
127
|
+
* spawned under another frame. Absent when the loop runs outside a Runner, which has only
|
|
128
|
+
* the one frame: treat absent as root.
|
|
129
|
+
*/
|
|
130
|
+
readonly isRootAgent?: boolean;
|
|
125
131
|
}
|
|
126
132
|
export interface BeforeStepResult {
|
|
127
133
|
readonly block?: boolean;
|
package/dist/mcp/auth-tool.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type Tool } from "../index.ts";
|
|
2
|
-
import { type McpOAuthService } from "./oauth/index.ts";
|
|
2
|
+
import { type McpOAuthClientSettings, type McpOAuthService } from "./oauth/index.ts";
|
|
3
3
|
export declare const MCP_OAUTH_AUTHORIZATION_URL_UPDATE = "mcp_oauth_authorization_url";
|
|
4
4
|
export interface CreateMcpAuthToolOptions {
|
|
5
5
|
readonly serverName: string;
|
|
6
6
|
readonly serverUrl: string;
|
|
7
7
|
readonly oauthService: McpOAuthService;
|
|
8
|
+
/** The server's pre-registered client / scopes, from its config. */
|
|
9
|
+
readonly oauthSettings?: McpOAuthClientSettings;
|
|
8
10
|
readonly reconnect: (signal?: AbortSignal) => Promise<void>;
|
|
9
11
|
readonly timeoutMs?: number;
|
|
10
12
|
}
|
package/dist/mcp/auth-tool.js
CHANGED
|
@@ -14,7 +14,7 @@ This server requires an OAuth login that has not yet been completed. Calling thi
|
|
|
14
14
|
|
|
15
15
|
Takes no arguments. Treat the URL as sensitive — do not modify it or strip query parameters.`;
|
|
16
16
|
export function createMcpAuthTool(options) {
|
|
17
|
-
const { serverName, serverUrl, oauthService, reconnect, timeoutMs } = options;
|
|
17
|
+
const { serverName, serverUrl, oauthService, oauthSettings, reconnect, timeoutMs } = options;
|
|
18
18
|
const name = qualifyMcpToolName(serverName, "authenticate");
|
|
19
19
|
return {
|
|
20
20
|
schema: {
|
|
@@ -32,7 +32,7 @@ export function createMcpAuthTool(options) {
|
|
|
32
32
|
onUpdate?.({ kind: "status", text: `Discovering OAuth metadata for ${serverName}…` });
|
|
33
33
|
let flow;
|
|
34
34
|
try {
|
|
35
|
-
flow = await oauthService.beginAuthorization(serverName, serverUrl);
|
|
35
|
+
flow = await oauthService.beginAuthorization(serverName, serverUrl, oauthSettings ?? {});
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
38
|
if (error instanceof AlreadyAuthorizedError) {
|
package/dist/mcp/capability.d.ts
CHANGED
|
@@ -3,5 +3,18 @@ import type { MCPServer } from "./server.ts";
|
|
|
3
3
|
export interface MCPCapabilityOptions {
|
|
4
4
|
readonly injectResources?: boolean;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* MCP servers the caller BUILT, rather than configured: for an `MCPServer` implementation that no
|
|
8
|
+
* `McpServerConfig` can describe — in-process, a custom protocol, a test double. The instances are
|
|
9
|
+
* yours; connecting them at session open and closing them at session close is this capability's
|
|
10
|
+
* job (see `connectAll` / `closeAll`).
|
|
11
|
+
*
|
|
12
|
+
* The split from {@link mcpServersCapability} is recipe vs finished good, and it decides what is
|
|
13
|
+
* possible, not just what is convenient: a controller reconnects by rebuilding its server from the
|
|
14
|
+
* config it holds, so a configured server gets status, reconnect, keep-alive and OAuth. An
|
|
15
|
+
* instance handed in from outside cannot be rebuilt, so it gets none of that — it publishes
|
|
16
|
+
* the raw server list as its `service`, and `session.mcp?.list() ?? []` / `reconnectMcpServer()`
|
|
17
|
+
* do not cover it. Its tools reach the model exactly the same way.
|
|
18
|
+
*/
|
|
6
19
|
export declare function mcpCapability(servers: readonly MCPServer[], options?: MCPCapabilityOptions): Capability;
|
|
7
20
|
//# sourceMappingURL=capability.d.ts.map
|
package/dist/mcp/capability.js
CHANGED
|
@@ -21,16 +21,35 @@ class McpResourcesInjector extends BoundaryInjector {
|
|
|
21
21
|
return { text: lines.join("\n"), variant: "mcp_resources" };
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* MCP servers the caller BUILT, rather than configured: for an `MCPServer` implementation that no
|
|
26
|
+
* `McpServerConfig` can describe — in-process, a custom protocol, a test double. The instances are
|
|
27
|
+
* yours; connecting them at session open and closing them at session close is this capability's
|
|
28
|
+
* job (see `connectAll` / `closeAll`).
|
|
29
|
+
*
|
|
30
|
+
* The split from {@link mcpServersCapability} is recipe vs finished good, and it decides what is
|
|
31
|
+
* possible, not just what is convenient: a controller reconnects by rebuilding its server from the
|
|
32
|
+
* config it holds, so a configured server gets status, reconnect, keep-alive and OAuth. An
|
|
33
|
+
* instance handed in from outside cannot be rebuilt, so it gets none of that — it publishes
|
|
34
|
+
* the raw server list as its `service`, and `session.mcp?.list() ?? []` / `reconnectMcpServer()`
|
|
35
|
+
* do not cover it. Its tools reach the model exactly the same way.
|
|
36
|
+
*/
|
|
24
37
|
export function mcpCapability(servers, options = {}) {
|
|
25
38
|
let resources = [];
|
|
26
39
|
const capability = {
|
|
27
40
|
name: "mcp",
|
|
41
|
+
contract: "detachable",
|
|
28
42
|
toolProviders: servers.map((server) => mcpToolProvider(server)),
|
|
29
|
-
service: servers,
|
|
30
43
|
...(options.injectResources ? { injectors: [new McpResourcesInjector(() => resources)] } : {}),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
service: servers,
|
|
45
|
+
openSession: (ctx) => connectAll(ctx),
|
|
46
|
+
closeSession: closeAll,
|
|
47
|
+
};
|
|
48
|
+
// Connect every server in parallel, fault-isolated — session open would otherwise cost
|
|
49
|
+
// the SUM of each server's startup (matching `mcpServersCapability`, which already does).
|
|
50
|
+
async function connectAll(ctx) {
|
|
51
|
+
{
|
|
52
|
+
const events = ctx.events;
|
|
34
53
|
const perServer = await Promise.all(servers.map(async (server) => {
|
|
35
54
|
try {
|
|
36
55
|
await server.connect();
|
|
@@ -38,7 +57,7 @@ export function mcpCapability(servers, options = {}) {
|
|
|
38
57
|
catch (error) {
|
|
39
58
|
const tail = server.stderrSnapshot?.().trimEnd();
|
|
40
59
|
const base = error instanceof Error ? error.message : String(error);
|
|
41
|
-
|
|
60
|
+
events?.emit({
|
|
42
61
|
type: "warning",
|
|
43
62
|
address: "main",
|
|
44
63
|
sessionId: ctx.sessionId,
|
|
@@ -54,7 +73,7 @@ export function mcpCapability(servers, options = {}) {
|
|
|
54
73
|
parts.push(reason.error.message);
|
|
55
74
|
if (reason.stderr !== undefined && reason.stderr.length > 0)
|
|
56
75
|
parts.push(`stderr: ${reason.stderr.trimEnd()}`);
|
|
57
|
-
|
|
76
|
+
events?.emit({ type: "warning", address: "main", sessionId: ctx.sessionId, message: parts.join("\n") });
|
|
58
77
|
});
|
|
59
78
|
if (!options.injectResources || !hasResources(server))
|
|
60
79
|
return [];
|
|
@@ -74,18 +93,18 @@ export function mcpCapability(servers, options = {}) {
|
|
|
74
93
|
}));
|
|
75
94
|
// Flattened in `servers` order, so the injected listing doesn't reshuffle per run.
|
|
76
95
|
resources = perServer.flat();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
catch {
|
|
84
|
-
// best-effort teardown; the assembler already guards + times out stop().
|
|
85
|
-
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function closeAll() {
|
|
99
|
+
for (const server of [...servers].reverse()) {
|
|
100
|
+
try {
|
|
101
|
+
await server.close();
|
|
86
102
|
}
|
|
87
|
-
|
|
88
|
-
|
|
103
|
+
catch {
|
|
104
|
+
// best-effort teardown; the scope already guards dispose failures.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
89
108
|
return capability;
|
|
90
109
|
}
|
|
91
110
|
//# sourceMappingURL=capability.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../index.ts";
|
|
2
2
|
import { type McpServerConfig } from "../config/schema.ts";
|
|
3
|
-
export declare function loadProjectMcpServers(
|
|
3
|
+
export declare function loadProjectMcpServers(environment: Environment, cwd: string): Promise<Record<string, McpServerConfig>>;
|
|
4
4
|
export type McpConfigTier = "user" | "project" | "local";
|
|
5
5
|
export interface McpConfigLayerOptions {
|
|
6
|
-
/** Working directory the project root is discovered from. Defaults to the
|
|
6
|
+
/** Working directory the project root is discovered from. Defaults to the environment cwd. */
|
|
7
7
|
readonly cwd?: string;
|
|
8
|
-
/** User-tier directory. Defaults to `<
|
|
8
|
+
/** User-tier directory. Defaults to `<environment home>/.<appName>`. */
|
|
9
9
|
readonly homeDir?: string;
|
|
10
10
|
readonly appName?: string;
|
|
11
11
|
}
|
|
@@ -24,5 +24,5 @@ export interface LoadedMcpServers {
|
|
|
24
24
|
* < local (`<root>/mcp.local.json` + `.mcp.local.json`). Stdio `cwd` is resolved against the
|
|
25
25
|
* project root. The interop `mcp.json` stays JSON (own config is TOML — see ConfigStore).
|
|
26
26
|
*/
|
|
27
|
-
export declare function loadMcpServers(
|
|
27
|
+
export declare function loadMcpServers(environment: Environment, options?: McpConfigLayerOptions): Promise<LoadedMcpServers>;
|
|
28
28
|
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { McpServerConfigSchema } from "../config/schema.js";
|
|
4
|
-
import { readTextFile } from "../tool/support/
|
|
4
|
+
import { readTextFile } from "../tool/support/environment-ops.js";
|
|
5
5
|
const PROJECT_MCP_FILENAMES = ["mcp.json", ".mcp.json"];
|
|
6
6
|
const McpJsonFileSchema = z.object({
|
|
7
7
|
mcpServers: z.record(z.string(), McpServerConfigSchema).default({}),
|
|
8
8
|
});
|
|
9
|
-
async function findProjectRoot(
|
|
10
|
-
let current =
|
|
9
|
+
async function findProjectRoot(environment, cwd) {
|
|
10
|
+
let current = environment.normpath(cwd);
|
|
11
11
|
// Bounded by reaching the filesystem root (dirname fixpoint).
|
|
12
12
|
for (;;) {
|
|
13
|
-
if (await pathExists(
|
|
13
|
+
if (await pathExists(environment, path.join(current, ".git")))
|
|
14
14
|
return current;
|
|
15
15
|
const parent = path.dirname(current);
|
|
16
16
|
if (parent === current)
|
|
17
|
-
return
|
|
17
|
+
return environment.normpath(cwd);
|
|
18
18
|
current = parent;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
async function pathExists(
|
|
21
|
+
async function pathExists(environment, p) {
|
|
22
22
|
try {
|
|
23
|
-
await
|
|
23
|
+
await environment.fileInfo(p);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
catch {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export async function loadProjectMcpServers(
|
|
31
|
-
const root = await findProjectRoot(
|
|
30
|
+
export async function loadProjectMcpServers(environment, cwd) {
|
|
31
|
+
const root = await findProjectRoot(environment, cwd);
|
|
32
32
|
const merged = {};
|
|
33
33
|
for (const filename of PROJECT_MCP_FILENAMES) {
|
|
34
34
|
const file = path.join(root, filename);
|
|
35
|
-
const parsed = await readMcpJsonFile(
|
|
35
|
+
const parsed = await readMcpJsonFile(environment, file);
|
|
36
36
|
if (parsed === undefined)
|
|
37
37
|
continue;
|
|
38
38
|
Object.assign(merged, parsed.mcpServers);
|
|
@@ -46,11 +46,11 @@ const LOCAL_MCP_FILENAMES = ["mcp.local.json", ".mcp.local.json"];
|
|
|
46
46
|
* < local (`<root>/mcp.local.json` + `.mcp.local.json`). Stdio `cwd` is resolved against the
|
|
47
47
|
* project root. The interop `mcp.json` stays JSON (own config is TOML — see ConfigStore).
|
|
48
48
|
*/
|
|
49
|
-
export async function loadMcpServers(
|
|
49
|
+
export async function loadMcpServers(environment, options = {}) {
|
|
50
50
|
const appName = options.appName ?? "agents";
|
|
51
|
-
const cwd = options.cwd ??
|
|
52
|
-
const root = await findProjectRoot(
|
|
53
|
-
const homeDir = options.homeDir ?? path.join(
|
|
51
|
+
const cwd = options.cwd ?? environment.getcwd();
|
|
52
|
+
const root = await findProjectRoot(environment, cwd);
|
|
53
|
+
const homeDir = options.homeDir ?? path.join(environment.gethome(), `.${appName}`);
|
|
54
54
|
const tiers = [
|
|
55
55
|
{ tier: "user", files: [path.join(homeDir, "mcp.json"), path.join(homeDir, ".mcp.json")] },
|
|
56
56
|
// Project tier reads the cross-tool `<root>/mcp.json` + `<root>/.mcp.json`, plus the
|
|
@@ -66,7 +66,7 @@ export async function loadMcpServers(machine, options = {}) {
|
|
|
66
66
|
for (const { tier, files } of tiers) {
|
|
67
67
|
let loaded = false;
|
|
68
68
|
for (const file of files) {
|
|
69
|
-
const parsed = await readMcpJsonFile(
|
|
69
|
+
const parsed = await readMcpJsonFile(environment, file);
|
|
70
70
|
if (parsed === undefined)
|
|
71
71
|
continue;
|
|
72
72
|
Object.assign(merged, parsed.mcpServers);
|
|
@@ -76,10 +76,10 @@ export async function loadMcpServers(machine, options = {}) {
|
|
|
76
76
|
}
|
|
77
77
|
return { servers: normalizeStdioCwd(merged, root), layers };
|
|
78
78
|
}
|
|
79
|
-
async function readMcpJsonFile(
|
|
79
|
+
async function readMcpJsonFile(environment, file) {
|
|
80
80
|
let text;
|
|
81
81
|
try {
|
|
82
|
-
text = await readTextFile(
|
|
82
|
+
text = await readTextFile(environment, file);
|
|
83
83
|
}
|
|
84
84
|
catch {
|
|
85
85
|
return undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an http MCP server's credentials come from when the host — not a config file — decides.
|
|
3
|
+
*
|
|
4
|
+
* A config can carry its own (`headers`, `bearerTokenEnvVar`) and a local host has the OAuth
|
|
5
|
+
* service, whose sign-in is a browser redirect to 127.0.0.1. Neither fits a server: a config is
|
|
6
|
+
* the same for every tenant, the process environment has no tenant boundary, and there is no
|
|
7
|
+
* browser. A provider is the host asking, per session and per connect, "what do I send to this
|
|
8
|
+
* server?" — which is all a vault is from the engine's side. Storing, refreshing and choosing
|
|
9
|
+
* the credential stay with the host; the engine never persists or logs what it is given, and
|
|
10
|
+
* because the MCP client runs in the host process, a credential never enters the sandbox.
|
|
11
|
+
*
|
|
12
|
+
* Precedence for one http server: the config's own `headers` / `bearerTokenEnvVar`, then the
|
|
13
|
+
* provider, then the OAuth service. A provider that returns nothing passes the server on.
|
|
14
|
+
*/
|
|
15
|
+
export interface McpCredentialRequest {
|
|
16
|
+
readonly serverName: string;
|
|
17
|
+
readonly url: string;
|
|
18
|
+
/** The session the connection belongs to; empty for a set connected outside any session. */
|
|
19
|
+
readonly sessionId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface McpCredential {
|
|
22
|
+
/** Sent on every request of this connection, over anything the transport sets itself. */
|
|
23
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
export interface McpCredentialProvider {
|
|
26
|
+
/** Asked on every connect and reconnect, so a refreshed token is picked up by the next one. */
|
|
27
|
+
credentialsFor(request: McpCredentialRequest): McpCredential | undefined | Promise<McpCredential | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* The server refused, with a 401, the credential `credentialsFor` just gave. Refresh or rotate
|
|
30
|
+
* it; the connect is retried once with whatever `credentialsFor` returns next. Without this,
|
|
31
|
+
* a 401 fails the connect like any other error.
|
|
32
|
+
*/
|
|
33
|
+
invalidate?(request: McpCredentialRequest): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=credentials.d.ts.map
|
package/dist/mcp/filter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RunContext } from "../index.ts";
|
|
2
2
|
import type { MCPTool } from "./types.ts";
|
|
3
3
|
export interface MCPToolFilterStatic {
|
|
4
4
|
readonly allowedToolNames?: readonly string[];
|
|
@@ -6,7 +6,7 @@ export interface MCPToolFilterStatic {
|
|
|
6
6
|
}
|
|
7
7
|
export interface MCPToolFilterContext {
|
|
8
8
|
readonly serverName: string;
|
|
9
|
-
readonly ctx:
|
|
9
|
+
readonly ctx: RunContext;
|
|
10
10
|
}
|
|
11
11
|
export type MCPToolFilterCallable = (context: MCPToolFilterContext, tool: MCPTool) => boolean | Promise<boolean>;
|
|
12
12
|
export type MCPToolFilter = MCPToolFilterStatic | MCPToolFilterCallable;
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_M
|
|
|
8
8
|
export { mcpToolProvider, wrapMcpTool } from "./provider.ts";
|
|
9
9
|
export { mcpCapability } from "./capability.ts";
|
|
10
10
|
export type { MCPCapabilityOptions } from "./capability.ts";
|
|
11
|
-
export { serverFromConfig, mcpServersCapability, DEFAULT_RECONNECT_POLICY } from "./manager.ts";
|
|
12
|
-
export type {
|
|
11
|
+
export { serverFromConfig, mcpOAuthSettings, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.ts";
|
|
12
|
+
export type { McpCredential, McpCredentialProvider, McpCredentialRequest } from "./credentials.ts";
|
|
13
|
+
export type { McpServerStatus, McpTransportKind, McpServerView, McpServersHandle, McpServersCapabilityOptions, ServerFromConfigOptions, McpTransportFactory, McpStatusListener, ReconnectPolicy, KeepAlivePolicy, McpTimer, } from "./manager.ts";
|
|
13
14
|
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.ts";
|
|
14
15
|
export type { CreateMcpAuthToolOptions } from "./auth-tool.ts";
|
|
15
16
|
export { MockMCPTransport } from "./mock-transport.ts";
|
|
@@ -19,5 +20,5 @@ export type { MCPStdioConfig, MCPHttpConfig } from "./sdk-transport.ts";
|
|
|
19
20
|
export { loadProjectMcpServers, loadMcpServers } from "./config-loader.ts";
|
|
20
21
|
export type { McpConfigTier, McpConfigLayerOptions, McpConfigLayer, LoadedMcpServers } from "./config-loader.ts";
|
|
21
22
|
export { McpOAuthService, McpOAuthClientProvider, AlreadyAuthorizedError, JsonFileStore, MemoryMcpCredentialStore, startCallbackServer, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, mcpOAuthStoreKey, } from "./oauth/index.ts";
|
|
22
|
-
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, McpOAuthProviderOptions, McpCredentialStore, CallbackServer, CallbackResult, } from "./oauth/index.ts";
|
|
23
|
+
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, McpOAuthProviderOptions, McpOAuthClientSettings, McpCredentialStore, CallbackServerOptions, CallbackServer, CallbackResult, } from "./oauth/index.ts";
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { qualifyMcpToolName, sanitizeMcpNamePart, isMcpToolName } from "./tool-n
|
|
|
4
4
|
export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_MAX_IMAGE_PART_BYTES } from "./output.js";
|
|
5
5
|
export { mcpToolProvider, wrapMcpTool } from "./provider.js";
|
|
6
6
|
export { mcpCapability } from "./capability.js";
|
|
7
|
-
export { serverFromConfig, mcpServersCapability, DEFAULT_RECONNECT_POLICY } from "./manager.js";
|
|
7
|
+
export { serverFromConfig, mcpOAuthSettings, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.js";
|
|
8
8
|
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.js";
|
|
9
9
|
export { MockMCPTransport } from "./mock-transport.js";
|
|
10
10
|
export { mcpStdioTransport, mcpStreamableHttpTransport, mergeStdioEnv, isTerminalTransportError, buildMcpHttpHeaders, } from "./sdk-transport.js";
|
package/dist/mcp/manager.d.ts
CHANGED
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
import { TransportMCPServer } from "./server.ts";
|
|
2
|
-
import type { MCPTransport } from "./types.ts";
|
|
3
|
-
import type { McpOAuthService } from "./oauth/index.ts";
|
|
4
|
-
import type { Capability } from "../index.ts";
|
|
2
|
+
import type { MCPTool, MCPTransport } from "./types.ts";
|
|
3
|
+
import type { McpOAuthClientSettings, McpOAuthService } from "./oauth/index.ts";
|
|
4
|
+
import type { Capability, ToolProvider } from "../index.ts";
|
|
5
|
+
import type { EventSink } from "../events/index.ts";
|
|
5
6
|
import type { McpServerConfig } from "../config/schema.ts";
|
|
7
|
+
import type { McpCredential, McpCredentialProvider } from "./credentials.ts";
|
|
6
8
|
export type McpServerStatus = "pending" | "connected" | "failed" | "disabled" | "needs-auth";
|
|
9
|
+
/** How a server is reached. `stdio` is a CHILD PROCESS of the host; `http` is a network call. */
|
|
10
|
+
export type McpTransportKind = "stdio" | "http";
|
|
11
|
+
/**
|
|
12
|
+
* Raised when a configured server asks for a transport its host does not offer.
|
|
13
|
+
*
|
|
14
|
+
* The case this exists for is `stdio` on a server host. An stdio server is not reached over a
|
|
15
|
+
* wire at all: it is spawned as a child of whatever process holds the MCP client — the harness —
|
|
16
|
+
* and so it stays on THAT process's environment even when every tool the session runs has been
|
|
17
|
+
* pushed out to a sandbox. On a single-tenant local host that is exactly right. On a server it
|
|
18
|
+
* is four problems at once:
|
|
19
|
+
*
|
|
20
|
+
* - LIFECYCLE. `HarnessParts.mcpServers` is "one set of connections per process", which holds
|
|
21
|
+
* inside one process and stops holding the moment the server runs as more than one replica:
|
|
22
|
+
* each replica spawns its own children, and a rolling restart takes them with it.
|
|
23
|
+
* - FAULT DOMAIN. A leaking or crashing `npx`-launched server takes down a process that is
|
|
24
|
+
* carrying every other tenant's sessions.
|
|
25
|
+
* - CREDENTIALS. stdio secrets travel in `config.env` — process environment, which has no
|
|
26
|
+
* tenant boundary. The http path has `McpOAuthService` and a swappable credential store
|
|
27
|
+
* precisely because it was designed for that boundary; stdio has no counterpart.
|
|
28
|
+
* - ISOLATION. A host that moved execution into a sandbox did so to contain it. An stdio
|
|
29
|
+
* server reopens an unsandboxed execution surface beside it, one that reads the HOST's disk
|
|
30
|
+
* rather than the workspace the agent's own tools operate on.
|
|
31
|
+
*
|
|
32
|
+
* So this is a host-declared admission rule, not a kernel prohibition. A single-tenant
|
|
33
|
+
* self-deployment is a legitimate case, and there stdio is no worse than it is in a CLI. The
|
|
34
|
+
* host states which transports it is willing to run; core refuses the rest, by name.
|
|
35
|
+
*/
|
|
36
|
+
export declare class McpTransportNotPermittedError extends Error {
|
|
37
|
+
readonly serverName: string;
|
|
38
|
+
readonly transport: McpTransportKind;
|
|
39
|
+
readonly allowed: readonly McpTransportKind[];
|
|
40
|
+
constructor(serverName: string, transport: McpTransportKind, allowed: readonly McpTransportKind[]);
|
|
41
|
+
}
|
|
7
42
|
export interface McpServerView {
|
|
8
43
|
readonly name: string;
|
|
9
|
-
readonly transport:
|
|
44
|
+
readonly transport: McpTransportKind;
|
|
10
45
|
readonly status: McpServerStatus;
|
|
11
46
|
readonly error?: string;
|
|
12
47
|
}
|
|
@@ -26,26 +61,93 @@ export interface McpTimer {
|
|
|
26
61
|
setTimeout(fn: () => void, ms: number): unknown;
|
|
27
62
|
clearTimeout(handle: unknown): void;
|
|
28
63
|
}
|
|
29
|
-
|
|
64
|
+
/** `credential` is what an {@link McpCredentialProvider} gave for this connect, if anything. */
|
|
65
|
+
export type McpTransportFactory = (name: string, config: McpServerConfig, credential?: McpCredential) => MCPTransport;
|
|
30
66
|
export interface ServerFromConfigOptions {
|
|
31
67
|
readonly oauthService?: McpOAuthService;
|
|
32
68
|
readonly cacheToolsList?: boolean;
|
|
33
69
|
readonly transport?: MCPTransport;
|
|
70
|
+
/** A provider's answer for this connect. Takes the place of the OAuth service. */
|
|
71
|
+
readonly credential?: McpCredential;
|
|
34
72
|
}
|
|
35
73
|
export declare function serverFromConfig(name: string, config: McpServerConfig, opts?: ServerFromConfigOptions): TransportMCPServer;
|
|
74
|
+
/** The OAuth client/scopes a server config pins (Codex `.mcp.json` `oauth` / `scopes`). */
|
|
75
|
+
export declare function mcpOAuthSettings(config: McpServerConfig): McpOAuthClientSettings;
|
|
36
76
|
export interface McpServersCapabilityOptions {
|
|
37
77
|
readonly oauthService?: McpOAuthService;
|
|
78
|
+
/** Credentials the host hands out per connect. See {@link McpCredentialProvider}. */
|
|
79
|
+
readonly credentials?: McpCredentialProvider;
|
|
80
|
+
/**
|
|
81
|
+
* Transports this host is willing to run. Omitted means both — the local default, and what
|
|
82
|
+
* every existing caller gets. A server host passes `["http"]`; see
|
|
83
|
+
* {@link McpTransportNotPermittedError} for why that is the host's call rather than core's.
|
|
84
|
+
*/
|
|
85
|
+
readonly allowedTransports?: readonly McpTransportKind[];
|
|
38
86
|
readonly cacheToolsList?: boolean;
|
|
39
87
|
readonly transportFactory?: McpTransportFactory;
|
|
40
88
|
readonly reconnectPolicy?: ReconnectPolicy;
|
|
41
89
|
readonly keepAlive?: KeepAlivePolicy;
|
|
42
90
|
readonly timer?: McpTimer;
|
|
91
|
+
/**
|
|
92
|
+
* A set of servers this session VIEWS but does not own — the host's process-shared set, passed
|
|
93
|
+
* in rather than looked up, so who shares with whom is a composition decision made in one
|
|
94
|
+
* place. Omit it and the session sees only what it owns.
|
|
95
|
+
*/
|
|
96
|
+
readonly sharedServers?: McpServersHandle;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What `connect` binds the controllers to: the sink that receives status warnings and the
|
|
100
|
+
* session id stamped on them. Both are what the caller ALREADY resolved — a harness-level
|
|
101
|
+
* connect has no session and no sink of its own, and passes neither, so its warnings surface
|
|
102
|
+
* through `onStatusChange` instead.
|
|
103
|
+
*/
|
|
104
|
+
export interface McpConnectContext {
|
|
105
|
+
readonly sessionId: string;
|
|
106
|
+
readonly events?: EventSink | undefined;
|
|
43
107
|
}
|
|
44
108
|
export interface McpServersHandle {
|
|
45
109
|
list(): readonly McpServerView[];
|
|
110
|
+
/** Tools a connected server exposes. Empty for an unknown or disconnected server. */
|
|
111
|
+
listTools(name: string): Promise<readonly MCPTool[]>;
|
|
46
112
|
reconnect(name: string): Promise<void>;
|
|
47
113
|
onStatusChange(listener: McpStatusListener): () => void;
|
|
114
|
+
/** One runnable-tool provider per server (what a session hands the model). */
|
|
115
|
+
toolProviders(): readonly ToolProvider[];
|
|
116
|
+
/** Connect every server in parallel, fault-isolated (a failure is a status, never a throw). */
|
|
117
|
+
connect(ctx: McpConnectContext): Promise<void>;
|
|
48
118
|
shutdown(): Promise<void>;
|
|
49
119
|
}
|
|
50
|
-
|
|
120
|
+
/**
|
|
121
|
+
* The controller set behind a group of configured servers — buildable on its own so a HARNESS
|
|
122
|
+
* can hold one set of connections for every session it serves (`HarnessParts.mcpServers`), or a session can
|
|
123
|
+
* own a private set (`mcpServersCapability`). Nothing connects until `handle.connect()`.
|
|
124
|
+
*
|
|
125
|
+
* Transport admission is checked HERE, while the set is being built, and not where the
|
|
126
|
+
* transport is actually constructed. That is deliberate: `transportFromConfig` runs inside
|
|
127
|
+
* `attempt()`, whose whole job is to be fault-isolated — it turns a throw into a `failed`
|
|
128
|
+
* status and a warning, which is right for "the server is down" and wrong for "this host will
|
|
129
|
+
* not run that". A misconfiguration should be a startup error the deployer cannot miss, not one
|
|
130
|
+
* more warning in a stream, so it is raised before a single controller exists.
|
|
131
|
+
*/
|
|
132
|
+
export declare function createMcpServers(configs: Record<string, McpServerConfig>, options?: McpServersCapabilityOptions): McpServersHandle;
|
|
133
|
+
/**
|
|
134
|
+
* The session-tier MCP capability. It covers both topologies, deciding between them from what the
|
|
135
|
+
* host handed it rather than from which function the caller picked:
|
|
136
|
+
*
|
|
137
|
+
* - The host passed shared servers (`options.sharedServers`)? This is a VIEW over them. It
|
|
138
|
+
* connects nothing and shuts nothing down — the harness owns those connections; this
|
|
139
|
+
* capability only hands the model their tools, publishes them as its `mcp` service (so `session.mcp?.list() ?? []` and friends work) and mirrors status changes into this
|
|
140
|
+
* session's event stream as warnings.
|
|
141
|
+
* - It didn't? Then `configs` is all this session sees, and those controllers are built,
|
|
142
|
+
* connected and shut down with the session, owned by it outright.
|
|
143
|
+
*
|
|
144
|
+
* Both at once is the interesting case: `configs` (from `SessionCapabilityContext.mcpServers` — a
|
|
145
|
+
* REPL kernel keyed by conversation id, say) is then an OVERLAY on the shared set. A name in
|
|
146
|
+
* `configs` SHADOWS the shared server of the same name for this session — the two would
|
|
147
|
+
* otherwise produce identical `mcp__<name>__<tool>` tool names. Shadowing is a view-level
|
|
148
|
+
* decision: the shared connection itself keeps running for every other session.
|
|
149
|
+
*
|
|
150
|
+
* Either way only what this session OWNS is connected and shut down here; see `merge` below.
|
|
151
|
+
*/
|
|
152
|
+
export declare function mcpServersCapability(configs?: Record<string, McpServerConfig>, options?: McpServersCapabilityOptions): Capability;
|
|
51
153
|
//# sourceMappingURL=manager.d.ts.map
|