@mcpcloud/runtime 0.7.0 → 0.12.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/dist/adapters/codeModeHost.d.ts +25 -0
- package/dist/compat-stdio.js +1 -1
- package/dist/compat-worker.js +1 -1
- package/dist/container-host.js +12 -2
- package/dist/engine/emscripten-module.cloudflare.cjs +21 -0
- package/dist/engine/emscripten-module.cloudflare.d.cts +3 -0
- package/dist/engine/emscripten-module.d.mts +3 -0
- package/dist/engine/emscripten-module.d.ts +11 -0
- package/dist/engine/emscripten-module.mjs +26 -0
- package/dist/engine/emscripten-module.wasm +0 -0
- package/dist/engine/ffi.d.mts +4 -0
- package/dist/engine/ffi.d.ts +85 -0
- package/dist/engine/ffi.mjs +1 -0
- package/dist/engine/manifest.json +51 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +61 -51
- package/dist/node.js +12 -2
- package/dist/projection.d.ts +9 -0
- package/dist/sandbox/bindings.d.ts +116 -0
- package/dist/sandbox/codeModeTool.d.ts +104 -0
- package/dist/sandbox/console.d.ts +51 -0
- package/dist/sandbox/createSandbox.d.ts +48 -0
- package/dist/sandbox/nodeEngine.d.ts +30 -0
- package/dist/sandbox/shape.d.ts +68 -0
- package/dist/sandbox/types.d.ts +143 -0
- package/dist/server.d.ts +13 -0
- package/dist/stdio.js +34 -24
- package/package.json +3 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox's public shapes: what you may configure, and what you get back.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the implementation so callers (and the dispatch worker,
|
|
5
|
+
* which will only ever hold a result) can import the types without pulling in
|
|
6
|
+
* the engine.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Ceilings applied to a single execution. Every one is required — there is no
|
|
10
|
+
* "unlimited" default, because an unbounded sandbox running agent-authored code
|
|
11
|
+
* is the thing this module exists to prevent.
|
|
12
|
+
*/
|
|
13
|
+
export interface SandboxLimits {
|
|
14
|
+
/**
|
|
15
|
+
* Interrupt-handler ticks before the execution is killed.
|
|
16
|
+
*
|
|
17
|
+
* This is the primary control and the metering unit (§3): it is deterministic,
|
|
18
|
+
* reproducible, and independent of how loaded the machine is — unlike
|
|
19
|
+
* wall-clock, which is neither.
|
|
20
|
+
*/
|
|
21
|
+
opcodeBudget: number;
|
|
22
|
+
/** Guest heap ceiling, well inside the 128 MB isolate limit. */
|
|
23
|
+
memoryBytes: number;
|
|
24
|
+
/** Guards runaway recursion, which memory alone does not catch quickly. */
|
|
25
|
+
stackBytes: number;
|
|
26
|
+
/**
|
|
27
|
+
* Wall-clock backstop, in milliseconds.
|
|
28
|
+
*
|
|
29
|
+
* Deliberately secondary. On workerd — our primary host — `Date.now()` does
|
|
30
|
+
* not advance during synchronous execution, so a deadline cannot fire in the
|
|
31
|
+
* middle of a tight loop. Opcodes catch that case; this catches an execution
|
|
32
|
+
* that is slow because it is waiting, once tool calls exist in P2.
|
|
33
|
+
*/
|
|
34
|
+
wallClockMs: number;
|
|
35
|
+
/**
|
|
36
|
+
* Upstream calls one execution may make.
|
|
37
|
+
*
|
|
38
|
+
* Not a cost control — §9.4's "10,000 calls costs $0.15" bounds the COST of a
|
|
39
|
+
* runaway, not the HARM. This bounds how much an injected or mistaken agent
|
|
40
|
+
* can do in one request, which is the thing that actually matters (§7.4).
|
|
41
|
+
*/
|
|
42
|
+
maxToolCalls: number;
|
|
43
|
+
}
|
|
44
|
+
/** Which ceiling an execution hit. Named so a caller can retry narrower. */
|
|
45
|
+
export type SandboxBudget = 'opcodes' | 'memory' | 'stack' | 'wall_clock'
|
|
46
|
+
/** One execution can issue thousands of upstream calls from a loop (§6). */
|
|
47
|
+
| 'tool_calls';
|
|
48
|
+
/**
|
|
49
|
+
* Why an execution failed.
|
|
50
|
+
*
|
|
51
|
+
* `budget_exhausted` is separated from `runtime_error` on purpose: they call for
|
|
52
|
+
* opposite responses. A guest exception means the code is wrong; a budget means
|
|
53
|
+
* the code may be fine and the input too large. §8.3 turns on that distinction —
|
|
54
|
+
* naming the budget lets an agent retry with a narrower query instead of
|
|
55
|
+
* rewriting working code.
|
|
56
|
+
*/
|
|
57
|
+
export type SandboxFailureKind = 'syntax_error' | 'runtime_error' | 'budget_exhausted' | 'timeout'
|
|
58
|
+
/**
|
|
59
|
+
* A tool call was refused by policy — not a code defect.
|
|
60
|
+
*
|
|
61
|
+
* Separate from `runtime_error` because §7.2's classes exist to drive opposite
|
|
62
|
+
* responses: a refusal means stop and escalate, while a runtime error means
|
|
63
|
+
* rewrite. Reporting a refusal as a code bug invites the agent to rewrite
|
|
64
|
+
* code that was fine, which is the expensive failure the taxonomy exists to
|
|
65
|
+
* prevent.
|
|
66
|
+
*/
|
|
67
|
+
| 'policy_denied';
|
|
68
|
+
/** One tool call the guest made, as the failure digest will render it (§7.3). */
|
|
69
|
+
export interface SandboxSpan {
|
|
70
|
+
/** Tool name as the guest called it. */
|
|
71
|
+
name: string;
|
|
72
|
+
/**
|
|
73
|
+
* Arguments, recorded as VALUES rather than shapes. They are small and
|
|
74
|
+
* agent-authored — the guest wrote them, so echoing them back leaks nothing
|
|
75
|
+
* it did not already know, and they are what a corrected call needs.
|
|
76
|
+
*/
|
|
77
|
+
args: unknown;
|
|
78
|
+
durationMs: number;
|
|
79
|
+
/** Structure of what came back. Never the content — see shape.ts. */
|
|
80
|
+
resultShape?: string;
|
|
81
|
+
/** Distributional facts about the result, when it is an array of records. */
|
|
82
|
+
facts?: string[];
|
|
83
|
+
error?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Payload size either side of the tool's JMESPath projection, when it has
|
|
86
|
+
* one. Present only if a projection ran, so an unprojected tool adds no noise.
|
|
87
|
+
* Feeds the same savings telemetry the direct-call path already reports.
|
|
88
|
+
*/
|
|
89
|
+
preProjectionBytes?: number;
|
|
90
|
+
postProjectionBytes?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Whether this call may have changed anything upstream. Unknown resolves to
|
|
93
|
+
* true: misclassifying a mutation as a read is the one error with
|
|
94
|
+
* irreversible consequences (§7.4).
|
|
95
|
+
*/
|
|
96
|
+
mutates: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* One `console.*` call the guest made (§7.5).
|
|
100
|
+
*
|
|
101
|
+
* Kept in the trace always, surfaced inline only when the execution failed — a
|
|
102
|
+
* successful run returned what was asked for, and its logs in context would
|
|
103
|
+
* reintroduce the cost Code Mode removes.
|
|
104
|
+
*/
|
|
105
|
+
export interface SandboxLogEntry {
|
|
106
|
+
level: string;
|
|
107
|
+
/**
|
|
108
|
+
* Already rendered: strings literal and capped, everything else summarized to
|
|
109
|
+
* a SHAPE. A logged object is usually a tool result the agent is inspecting,
|
|
110
|
+
* which is the content the token wall exists to keep out.
|
|
111
|
+
*/
|
|
112
|
+
message: string;
|
|
113
|
+
}
|
|
114
|
+
export interface SandboxSuccess {
|
|
115
|
+
ok: true;
|
|
116
|
+
/** Whatever the guest returned, marshalled through JSON. */
|
|
117
|
+
value: unknown;
|
|
118
|
+
/** Interrupt ticks consumed. The metering read (§3). */
|
|
119
|
+
opcodesUsed: number;
|
|
120
|
+
/** One per tool call, in call order. */
|
|
121
|
+
spans: SandboxSpan[];
|
|
122
|
+
/** `console.*` output, in call order. Never surfaced on success. */
|
|
123
|
+
logs: SandboxLogEntry[];
|
|
124
|
+
}
|
|
125
|
+
export interface SandboxFailure {
|
|
126
|
+
ok: false;
|
|
127
|
+
kind: SandboxFailureKind;
|
|
128
|
+
message: string;
|
|
129
|
+
/** Present only when `kind` is `budget_exhausted`. */
|
|
130
|
+
budget?: SandboxBudget;
|
|
131
|
+
/** Guest stack, when the engine produced one. Harness frames are stripped. */
|
|
132
|
+
stack?: string;
|
|
133
|
+
opcodesUsed: number;
|
|
134
|
+
/**
|
|
135
|
+
* Calls made before the failure. These are the partial results: the agent can
|
|
136
|
+
* see what already ran and write a follow-up that skips it, which is cheaper
|
|
137
|
+
* and more flexible than resuming a heap (§7.7).
|
|
138
|
+
*/
|
|
139
|
+
spans: SandboxSpan[];
|
|
140
|
+
/** `console.*` output, in call order — the mid-execution view (§7.5). */
|
|
141
|
+
logs: SandboxLogEntry[];
|
|
142
|
+
}
|
|
143
|
+
export type SandboxResult = SandboxSuccess | SandboxFailure;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
import type { CallerContext, RuntimeConfig, RuntimeEnv, ServerIdentity } from './config';
|
|
4
|
+
import type { CodeModeOptions } from './sandbox/codeModeTool';
|
|
4
5
|
import type { PromptDefinition, ResourceDefinition, ToolDefinition } from './types';
|
|
5
6
|
export type ToolHandler = (input: unknown, config: RuntimeConfig, caller: CallerContext) => Promise<CallToolResult>;
|
|
6
7
|
export interface RegisteredTool {
|
|
@@ -16,6 +17,18 @@ export interface DefineServerOptions {
|
|
|
16
17
|
prompts?: PromptDefinition[];
|
|
17
18
|
/** Resources served via `resources/list` / `resources/read` (#78). */
|
|
18
19
|
resources?: ResourceDefinition[];
|
|
20
|
+
/**
|
|
21
|
+
* Code Mode. Registers `codemode_execute` ALONGSIDE whatever discoveryMode
|
|
22
|
+
* already exposes — the search/execute pair the design is modelled on, not a
|
|
23
|
+
* replacement for either.
|
|
24
|
+
*
|
|
25
|
+
* Needs both a non-`off` mode and an engine. Codegen emits the mode from the
|
|
26
|
+
* server's setting; the host supplies the engine. A server whose operator
|
|
27
|
+
* turned Code Mode on still registers nothing on a host that cannot run it,
|
|
28
|
+
* which is the honest outcome — but it is also why the setting alone is not
|
|
29
|
+
* yet enough to make the tool appear on the Workers edge.
|
|
30
|
+
*/
|
|
31
|
+
codeMode?: CodeModeOptions;
|
|
19
32
|
}
|
|
20
33
|
export interface GeneratedServer {
|
|
21
34
|
/** Build a fresh McpServer (per request — handler closures are isolation-safe). */
|