@procedures/mcp-server 0.13.2 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/README.md +100 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/face.d.ts +20 -1
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +49 -3
- package/dist/face.js.map +1 -1
- package/dist/host.d.ts +64 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +73 -11
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/tasks.d.ts +131 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +276 -0
- package/dist/tasks.js.map +1 -0
- package/dist/transport/guard.d.ts +61 -0
- package/dist/transport/guard.d.ts.map +1 -0
- package/dist/transport/guard.js +58 -0
- package/dist/transport/guard.js.map +1 -0
- package/dist/transport/http.d.ts +17 -2
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +157 -37
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/mcp-transport.d.ts +19 -0
- package/dist/transport/mcp-transport.d.ts.map +1 -1
- package/dist/transport/mcp-transport.js +194 -76
- package/dist/transport/mcp-transport.js.map +1 -1
- package/dist/types.d.ts +43 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/face.ts +82 -4
- package/src/host.ts +133 -21
- package/src/index.ts +23 -1
- package/src/tasks.ts +318 -0
- package/src/transport/guard.ts +90 -0
- package/src/transport/http.ts +164 -36
- package/src/transport/mcp-transport.ts +213 -82
- package/src/types.ts +44 -4
package/dist/face.d.ts
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* - The tools are the procedures of the registry of the host that its policy exposes.
|
|
10
10
|
* - Without a token of its own, the face takes the token of the policy. Without origins of its
|
|
11
11
|
* own, it takes the permitted origins of the policy.
|
|
12
|
+
* - With `narrowing`, each call of the face has a narrower capability (CLI-43). Refer to
|
|
13
|
+
* `McpFaceOptions.narrowing`.
|
|
12
14
|
* - The types are structural: this package does not depend on `@procedures/peer`.
|
|
13
15
|
*/
|
|
14
16
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
15
|
-
import type
|
|
17
|
+
import { type CapabilityRequest, type HostPolicy, type ProcedureRegistry, type RequestHandler } from "@procedures/client";
|
|
16
18
|
import { McpServerTransport } from "./transport/mcp-transport.js";
|
|
17
19
|
import type { McpServerTransportOptions } from "./types.js";
|
|
18
20
|
/** The options of `mcpFace()`: the options of an MCP transport, with the path of its endpoint. */
|
|
@@ -23,6 +25,21 @@ export interface McpFaceOptions extends Omit<McpServerTransportOptions, "transpo
|
|
|
23
25
|
readonly token?: string | undefined;
|
|
24
26
|
/** The browser origins that can call the endpoint, besides loopback origins. The default is the list of the policy. */
|
|
25
27
|
readonly allowedOrigins?: string[] | undefined;
|
|
28
|
+
/** The host names that a request on a loopback address can name. The default is `browser.allowedHosts` of the policy. */
|
|
29
|
+
readonly allowedHosts?: readonly string[] | "*" | undefined;
|
|
30
|
+
/** The most sessions at one time (CLI-35). The default is no limit. */
|
|
31
|
+
readonly maxSessions?: number | undefined;
|
|
32
|
+
/** The largest body of a request, in bytes (CLI-35). The default is 4 MiB. */
|
|
33
|
+
readonly maxBodyBytes?: number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* A narrower capability for each call of the face (CLI-43), for example the read-only mode
|
|
36
|
+
* `{ effects: { writes: [] } }`. The face adds it as one more source of the narrowing key
|
|
37
|
+
* (`procedure-narrowing`, CLI-30). Thus the server applies the meet of all the sources: the
|
|
38
|
+
* capability of the policy, the request hook and the key of the caller. A narrowing can only
|
|
39
|
+
* narrow. The face lists only the tools that the narrowed capability permits. A narrowing that
|
|
40
|
+
* is not valid stops the factory with an error. Without it, the face does not narrow.
|
|
41
|
+
*/
|
|
42
|
+
readonly narrowing?: CapabilityRequest<unknown> | readonly CapabilityRequest<unknown>[] | undefined;
|
|
26
43
|
}
|
|
27
44
|
/** What the MCP face needs of its host: the handler of its calls, the registry and the policy. */
|
|
28
45
|
export interface McpFaceContext {
|
|
@@ -53,6 +70,8 @@ export interface McpFace {
|
|
|
53
70
|
* @example
|
|
54
71
|
* ```typescript
|
|
55
72
|
* const host = createProcedureHost({ registry, policy, faces: { http: true, mcp: mcpFace({ serverInfo }) }, listen });
|
|
73
|
+
* // A read-only MCP face next to the HTTP face of the same server
|
|
74
|
+
* const readOnly = mcpFace({ serverInfo, narrowing: { effects: { writes: [] } } });
|
|
56
75
|
* ```
|
|
57
76
|
*/
|
|
58
77
|
export declare function mcpFace(options?: McpFaceOptions): (context: McpFaceContext) => McpFace;
|
package/dist/face.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face.d.ts","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"face.d.ts","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAEf,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,kGAAkG;AAClG,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,yBAAyB,EAAE,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,CAAC;IACzJ,uDAAuD;IACvD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,oHAAoH;IACpH,QAAQ,C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AC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7F,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;CACxC;AAwCD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CA8C1F"}
|
package/dist/face.js
CHANGED
|
@@ -9,26 +9,69 @@
|
|
|
9
9
|
* - The tools are the procedures of the registry of the host that its policy exposes.
|
|
10
10
|
* - Without a token of its own, the face takes the token of the policy. Without origins of its
|
|
11
11
|
* own, it takes the permitted origins of the policy.
|
|
12
|
+
* - With `narrowing`, each call of the face has a narrower capability (CLI-43). Refer to
|
|
13
|
+
* `McpFaceOptions.narrowing`.
|
|
12
14
|
* - The types are structural: this package does not depend on `@procedures/peer`.
|
|
13
15
|
*/
|
|
16
|
+
import { NARROWING_METADATA_KEY, addNarrowing, capabilityRefusal, narrowWithin, narrowingOf, } from "@procedures/client";
|
|
14
17
|
import { McpServerTransport } from "./transport/mcp-transport.js";
|
|
18
|
+
/**
|
|
19
|
+
* This function reads the narrowing of a face with the decoder and the meet of the wire (CLI-30).
|
|
20
|
+
* It throws for a part that is not valid, because each call of the face then gets a refusal. The
|
|
21
|
+
* capability of the tool list is the meet of the policy capability and the narrowing, without the
|
|
22
|
+
* time: the time limits each call, not the tools.
|
|
23
|
+
*/
|
|
24
|
+
function faceNarrowing(narrowing, context) {
|
|
25
|
+
const wire = narrowingOf(narrowing);
|
|
26
|
+
// The sources as the decoder read them, frozen: a change of the options or of the metadata of a call does not change them
|
|
27
|
+
const sources = Object.freeze(wire.narrowings.map((source) => Object.freeze({ ...source })));
|
|
28
|
+
const untimed = sources.map((source) => ({
|
|
29
|
+
...(source.clearance !== undefined ? { clearance: source.clearance } : {}),
|
|
30
|
+
...(source.effects !== undefined ? { effects: source.effects } : {}),
|
|
31
|
+
}));
|
|
32
|
+
const listed = narrowWithin(context.policy.capabilityOf?.(), untimed, context.policy.clearanceOrder);
|
|
33
|
+
const refusal = [...wire.notes, ...listed.notes].find((note) => note.kind === "refused");
|
|
34
|
+
if (refusal)
|
|
35
|
+
throw new Error(`The narrowing of the MCP face is not valid: ${refusal.message}`);
|
|
36
|
+
const { capability } = listed;
|
|
37
|
+
const { handler: inner, registry } = context;
|
|
38
|
+
return {
|
|
39
|
+
handler: {
|
|
40
|
+
handle: (request) => inner.handle({ ...request, metadata: { ...request.metadata, [NARROWING_METADATA_KEY]: addNarrowing(request.metadata[NARROWING_METADATA_KEY], sources) } }),
|
|
41
|
+
...(inner.ambientCredentials ? { ambientCredentials: inner.ambientCredentials } : {}),
|
|
42
|
+
},
|
|
43
|
+
permits: (path) => {
|
|
44
|
+
const procedure = registry.get(path);
|
|
45
|
+
return procedure !== undefined && capabilityRefusal(procedure, capability) === undefined;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
15
49
|
/**
|
|
16
50
|
* This function gives the MCP face of a procedures host. The host calls the factory one time.
|
|
17
51
|
*
|
|
18
52
|
* @example
|
|
19
53
|
* ```typescript
|
|
20
54
|
* const host = createProcedureHost({ registry, policy, faces: { http: true, mcp: mcpFace({ serverInfo }) }, listen });
|
|
55
|
+
* // A read-only MCP face next to the HTTP face of the same server
|
|
56
|
+
* const readOnly = mcpFace({ serverInfo, narrowing: { effects: { writes: [] } } });
|
|
21
57
|
* ```
|
|
22
58
|
*/
|
|
23
59
|
export function mcpFace(options = {}) {
|
|
24
60
|
return (context) => {
|
|
25
|
-
const { path: givenPath, token: givenToken, allowedOrigins: givenOrigins, ...common } = options;
|
|
61
|
+
const { path: givenPath, token: givenToken, allowedOrigins: givenOrigins, allowedHosts: givenHosts, maxSessions, maxBodyBytes, narrowing: givenNarrowing, ...common } = options;
|
|
26
62
|
const path = givenPath ?? "/mcp";
|
|
27
63
|
const token = givenToken ?? context.policy.token;
|
|
28
64
|
const policyOrigins = context.policy.browser.allowedOrigins;
|
|
29
65
|
const allowedOrigins = givenOrigins ?? (Array.isArray(policyOrigins) ? [...policyOrigins] : undefined);
|
|
66
|
+
const allowedHosts = givenHosts ?? context.policy.browser.allowedHosts;
|
|
67
|
+
const narrowed = givenNarrowing !== undefined ? faceNarrowing(givenNarrowing, context) : undefined;
|
|
30
68
|
const toolFilter = { ...common.toolFilter, ...(context.policy.expose ? { include: context.policy.expose } : {}) };
|
|
31
|
-
|
|
69
|
+
if (narrowed) {
|
|
70
|
+
const included = toolFilter.include;
|
|
71
|
+
toolFilter.include = included ? (tool) => included(tool) && narrowed.permits(tool) : narrowed.permits;
|
|
72
|
+
}
|
|
73
|
+
const handler = narrowed?.handler ?? context.handler;
|
|
74
|
+
const transport = new McpServerTransport(handler, {
|
|
32
75
|
...common,
|
|
33
76
|
registry: context.registry,
|
|
34
77
|
toolFilter,
|
|
@@ -38,7 +81,10 @@ export function mcpFace(options = {}) {
|
|
|
38
81
|
path,
|
|
39
82
|
...(token !== undefined ? { token } : {}),
|
|
40
83
|
...(allowedOrigins ? { allowedOrigins } : {}),
|
|
41
|
-
...(
|
|
84
|
+
...(allowedHosts !== undefined ? { allowedHosts } : {}),
|
|
85
|
+
...(maxSessions !== undefined ? { maxSessions } : {}),
|
|
86
|
+
...(maxBodyBytes !== undefined ? { maxBodyBytes } : {}),
|
|
87
|
+
...(handler.ambientCredentials ? { ambientCredentials: handler.ambientCredentials } : {}),
|
|
42
88
|
},
|
|
43
89
|
});
|
|
44
90
|
return {
|
package/dist/face.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face.js","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"face.js","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,GAMZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,kBAAkB,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cedureServer` by hand.
|
|
16
16
|
* - The faces: stdio, Streamable HTTP, and SDK transports. The stdio face stops the host when its
|
|
17
|
-
* input ends.
|
|
17
|
+
* input ends. The HTTP face mounts on a listener of the app (`handleHttp`).
|
|
18
|
+
* - The runner (CLI-11): `declare(svc)` gives the host to a service of `@mark1russell7/service`.
|
|
19
|
+
* Then `run()` starts the host and stops it in stages, and the end of the stdio input is the
|
|
20
|
+
* trigger `stdin-close` of the runner.
|
|
18
21
|
* - What each tool call gets: the questions to the person (elicitation, with the consents of the
|
|
19
22
|
* operator), the progress, the envelopes of untrusted text, and the instructions of the server.
|
|
23
|
+
* - The tasks (CLI-35): one store for each face, with a limit of tasks that run at one time. A
|
|
24
|
+
* procedure with `metadata.taskSupport` runs as a task when the client asks for one.
|
|
20
25
|
*/
|
|
26
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
21
27
|
import type { Transport as SdkTransport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
22
28
|
import { ProcedureServer, type ElicitationPolicy, type HostPolicy, type HostPolicyOptions, type Interceptor, type ProcedureModule, type ProcedurePath, type ProcedureRegistry, type ProcedureServerOptions, type Duration } from "@procedures/client";
|
|
23
29
|
import { type McpTool, type McpToolFilter } from "@procedures/mcp";
|
|
24
30
|
import { McpServerTransport } from "./transport/mcp-transport.js";
|
|
25
31
|
import type { HttpTransportOptions, McpServerTransportState, McpToolContentHook, StdioTransportOptions } from "./types.js";
|
|
26
32
|
import type { UntrustedContentOptions } from "./untrusted.js";
|
|
33
|
+
import { type McpTaskStore, type McpTasksOptions } from "./tasks.js";
|
|
27
34
|
/** The stdio face of a host. */
|
|
28
35
|
export interface McpStdioFace extends Omit<StdioTransportOptions, "onEnd"> {
|
|
29
36
|
/** True (the default): the host stops when the input ends. */
|
|
@@ -37,7 +44,8 @@ export interface McpHostFaces {
|
|
|
37
44
|
stdio?: boolean | McpStdioFace | undefined;
|
|
38
45
|
/**
|
|
39
46
|
* The face over Streamable HTTP. Without a token of its own, it takes the token of the policy,
|
|
40
|
-
* and without origins of its own, the permitted origins of the policy.
|
|
47
|
+
* and without origins of its own, the permitted origins of the policy. With `mount: true`, mount
|
|
48
|
+
* `McpHost.handleHttp` on a listener. A face with a listener of its own is deprecated (CLI-11).
|
|
41
49
|
*/
|
|
42
50
|
http?: HttpTransportOptions | undefined;
|
|
43
51
|
/** SDK transports to connect: the in-memory transport of a test, or an embedding. */
|
|
@@ -108,12 +116,45 @@ export interface McpHostOptions {
|
|
|
108
116
|
} | undefined;
|
|
109
117
|
/** True: debug lines go to stderr. */
|
|
110
118
|
debug?: boolean | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* MCP tasks (CLI-35): a store, or the options of a new store (`maxRunning`, the default 8, and
|
|
121
|
+
* `ttl`). Each face shares the store. Without it, the host has no tasks.
|
|
122
|
+
*/
|
|
123
|
+
tasks?: McpTasksOptions | undefined;
|
|
111
124
|
}
|
|
112
125
|
/** The state of a host: if it operates, and the state of each face. */
|
|
113
126
|
export interface McpHostState {
|
|
114
127
|
readonly running: boolean;
|
|
115
128
|
readonly faces: readonly McpServerTransportState[];
|
|
116
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* A transport part of the runner: the shape of `TransportImpl` of `@mark1russell7/service`. The
|
|
132
|
+
* types are structural, so this package imports no code of the runner.
|
|
133
|
+
*/
|
|
134
|
+
export interface McpRunnerPart {
|
|
135
|
+
start(signal: AbortSignal, life: unknown): Promise<void> | void;
|
|
136
|
+
stopIntake(): Promise<void> | void;
|
|
137
|
+
drain(deadline: number, signal: AbortSignal): Promise<void> | void;
|
|
138
|
+
inFlight(): number;
|
|
139
|
+
close(): Promise<void> | void;
|
|
140
|
+
}
|
|
141
|
+
/** A storage of the server as a dependency of the runner: the shape of `DependencyHandle`. */
|
|
142
|
+
export type McpRunnerDependency = ReturnType<ProcedureServer["storageHandles"]>[number];
|
|
143
|
+
/**
|
|
144
|
+
* What `McpHost.declare()` uses of the builder of a service (`ServiceBuilder` of
|
|
145
|
+
* `@mark1russell7/service`). The types are structural.
|
|
146
|
+
*/
|
|
147
|
+
export interface McpServiceBuilder {
|
|
148
|
+
server(name: string, knobs: Readonly<Record<string, never>>, impl: McpRunnerPart): unknown;
|
|
149
|
+
dependency(name: string, spec: {
|
|
150
|
+
system: null;
|
|
151
|
+
knobs: Readonly<Record<string, never>>;
|
|
152
|
+
operations: Readonly<Record<string, {
|
|
153
|
+
idempotent: boolean;
|
|
154
|
+
}>>;
|
|
155
|
+
}, handle: McpRunnerDependency): unknown;
|
|
156
|
+
trigger(trigger: "stdin-close"): unknown;
|
|
157
|
+
}
|
|
117
158
|
/** An MCP host: its registry, its policy, its server and its faces. */
|
|
118
159
|
export interface McpHost {
|
|
119
160
|
readonly registry: ProcedureRegistry;
|
|
@@ -123,14 +164,33 @@ export interface McpHost {
|
|
|
123
164
|
readonly expose: ((path: ProcedurePath) => boolean) | undefined;
|
|
124
165
|
/** The MCP transports of the faces, in the order stdio, Streamable HTTP, SDK transports. */
|
|
125
166
|
readonly transports: readonly McpServerTransport[];
|
|
126
|
-
/**
|
|
167
|
+
/** The store of the tasks of each face, or undefined when the host has no tasks (CLI-35). */
|
|
168
|
+
readonly tasks: McpTaskStore | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* A promise that resolves when the host stopped: by `stop()`, at the end of the stdio input, or
|
|
171
|
+
* at the close of its part under `run()`.
|
|
172
|
+
*/
|
|
127
173
|
readonly closed: Promise<void>;
|
|
128
|
-
/** This function starts each face. */
|
|
174
|
+
/** This function starts each face. A host that `declare()` gave to a service starts under `run()`. */
|
|
129
175
|
start(): Promise<void>;
|
|
130
176
|
/** This function stops the server and each face. The calls in flight get the grace time. */
|
|
131
177
|
stop(options?: {
|
|
132
178
|
grace?: Duration | undefined;
|
|
133
179
|
}): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* This function declares the host on the builder of a service, for `run()` of
|
|
182
|
+
* `@mark1russell7/service` (CLI-11). The server is a transport part, and each storage is a
|
|
183
|
+
* dependency. A host with a stdio face declares the trigger `stdin-close`. Then the runner owns
|
|
184
|
+
* the stop: the end of the input starts the staged stop, and the stdio face does not stop the
|
|
185
|
+
* host by itself. A host declares one time.
|
|
186
|
+
*/
|
|
187
|
+
declare<S extends McpServiceBuilder>(svc: S): S;
|
|
188
|
+
/**
|
|
189
|
+
* This function answers a request of the Streamable HTTP face (`faces.http` with `mount: true`)
|
|
190
|
+
* and gives true. It gives false for another path, or without that face. Mount it on a listener,
|
|
191
|
+
* for example an `httpTransport` of `@mark1russell7/service/http`.
|
|
192
|
+
*/
|
|
193
|
+
handleHttp(req: IncomingMessage, res: ServerResponse): boolean;
|
|
134
194
|
/** The tools of the host at this time, from the registry and the expose rule. */
|
|
135
195
|
tools(): McpTool[];
|
|
136
196
|
/** The state of the host and of its faces. */
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAEL,eAAe,EAOf,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAwB,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAA6B,MAAM,8BAA8B,CAAC;AAC7F,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CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC;IAC/D,iFAAiF;IACjF,KAAK,IAAI,OAAO,EAAE,CAAC;IACnB,8CAA8C;IAC9C,KAAK,IAAI,YAAY,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAQ9C;AAaD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC,GAChE,CAAC,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,GAAG,SAAS,CAYhD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAyJnE"}
|
package/dist/host.js
CHANGED
|
@@ -14,13 +14,19 @@
|
|
|
14
14
|
* limit, the interceptors and the capability. The host does not build the options of
|
|
15
15
|
* `ProcedureServer` by hand.
|
|
16
16
|
* - The faces: stdio, Streamable HTTP, and SDK transports. The stdio face stops the host when its
|
|
17
|
-
* input ends.
|
|
17
|
+
* input ends. The HTTP face mounts on a listener of the app (`handleHttp`).
|
|
18
|
+
* - The runner (CLI-11): `declare(svc)` gives the host to a service of `@mark1russell7/service`.
|
|
19
|
+
* Then `run()` starts the host and stops it in stages, and the end of the stdio input is the
|
|
20
|
+
* trigger `stdin-close` of the runner.
|
|
18
21
|
* - What each tool call gets: the questions to the person (elicitation, with the consents of the
|
|
19
22
|
* operator), the progress, the envelopes of untrusted text, and the instructions of the server.
|
|
23
|
+
* - The tasks (CLI-35): one store for each face, with a limit of tasks that run at one time. A
|
|
24
|
+
* procedure with `metadata.taskSupport` runs as a task when the client asks for one.
|
|
20
25
|
*/
|
|
21
26
|
import { PROCEDURE_REGISTRY, ProcedureServer, capabilityRefusal, createRegistry, hostPolicy, narrowCapability, procedureServerOptions, registerModules, } from "@procedures/client";
|
|
22
27
|
import { proceduresToMcpTools } from "@procedures/mcp";
|
|
23
28
|
import { McpServerTransport, distinctTools, namedTools } from "./transport/mcp-transport.js";
|
|
29
|
+
import { taskStoreOf } from "./tasks.js";
|
|
24
30
|
/**
|
|
25
31
|
* This function sends `console.log` to stderr. Over stdio, stdout carries the protocol: a stray
|
|
26
32
|
* `console.log` of a procedure or a dependency corrupts it. The MCP SDK writes with
|
|
@@ -40,6 +46,8 @@ export function redirectConsoleToStderr() {
|
|
|
40
46
|
function isTransportList(value) {
|
|
41
47
|
return Array.isArray(value);
|
|
42
48
|
}
|
|
49
|
+
/** The operations of a storage as a dependency of the runner: a read can go again, a write cannot. */
|
|
50
|
+
const STORAGE_OPERATIONS = Object.freeze({ read: { idempotent: true }, write: { idempotent: false } });
|
|
43
51
|
/** The read-only capability of a host: no effect can write. */
|
|
44
52
|
const READ_ONLY_REQUEST = { effects: { writes: [] } };
|
|
45
53
|
/**
|
|
@@ -94,16 +102,26 @@ export function createMcpHost(options = {}) {
|
|
|
94
102
|
...(interceptors.length > 0 ? { interceptors } : {}),
|
|
95
103
|
});
|
|
96
104
|
const server = new ProcedureServer({ ...procedureServerOptions(policy, registry), ...options.serverOptions });
|
|
105
|
+
// One store of the tasks for each face. The stop of the host closes a store that the host made
|
|
106
|
+
const tasks = taskStoreOf(options.tasks);
|
|
97
107
|
let resolveClosed = () => undefined;
|
|
98
108
|
const closed = new Promise((resolve) => {
|
|
99
109
|
resolveClosed = resolve;
|
|
100
110
|
});
|
|
101
111
|
let stopping;
|
|
102
112
|
let running = false;
|
|
113
|
+
// True after declare(): the runner starts and stops the host
|
|
114
|
+
let managed = false;
|
|
115
|
+
// Both stop paths close a task store that the host made: stop(), and the close of the runner part
|
|
116
|
+
const closeTasks = async () => {
|
|
117
|
+
if (tasks?.owned)
|
|
118
|
+
await tasks.store.close().catch(() => undefined);
|
|
119
|
+
};
|
|
103
120
|
const stop = (stopOptions = {}) => {
|
|
104
121
|
stopping ??= server
|
|
105
122
|
.stop(stopOptions.grace !== undefined ? { grace: stopOptions.grace } : {})
|
|
106
|
-
.finally(() => {
|
|
123
|
+
.finally(async () => {
|
|
124
|
+
await closeTasks();
|
|
107
125
|
running = false;
|
|
108
126
|
resolveClosed();
|
|
109
127
|
});
|
|
@@ -123,6 +141,7 @@ export function createMcpHost(options = {}) {
|
|
|
123
141
|
...(options.json ? { json: options.json } : {}),
|
|
124
142
|
...(options.streamLimits ? { streamLimits: options.streamLimits } : {}),
|
|
125
143
|
...(options.debug !== undefined ? { debug: options.debug } : {}),
|
|
144
|
+
...(tasks ? { tasks: { store: tasks.store } } : {}),
|
|
126
145
|
};
|
|
127
146
|
const faces = options.faces ?? { stdio: true };
|
|
128
147
|
const transports = [];
|
|
@@ -134,24 +153,29 @@ export function createMcpHost(options = {}) {
|
|
|
134
153
|
stdio: {
|
|
135
154
|
...(stdio.stdin ? { stdin: stdio.stdin } : {}),
|
|
136
155
|
...(stdio.stdout ? { stdout: stdio.stdout } : {}),
|
|
137
|
-
|
|
156
|
+
// Under run(), the trigger stdin-close of the runner starts the stop
|
|
157
|
+
...(stdio.stopOnEnd !== false ? { onEnd: () => void (managed ? undefined : stop()) } : {}),
|
|
138
158
|
},
|
|
139
159
|
}));
|
|
140
160
|
}
|
|
161
|
+
let httpFace;
|
|
141
162
|
if (faces.http) {
|
|
142
163
|
// The HTTP face keeps the token and the origins of the policy (CLI-11 moves the checks to the host)
|
|
143
164
|
const policyOrigins = policy.browser.allowedOrigins;
|
|
144
165
|
const allowedOrigins = faces.http.allowedOrigins ?? (Array.isArray(policyOrigins) ? policyOrigins : undefined);
|
|
166
|
+
const allowedHosts = faces.http.allowedHosts ?? policy.browser.allowedHosts;
|
|
145
167
|
const token = faces.http.token ?? policy.token;
|
|
146
|
-
|
|
168
|
+
httpFace = new McpServerTransport(server, {
|
|
147
169
|
...common,
|
|
148
170
|
transport: "http",
|
|
149
171
|
httpOptions: {
|
|
150
172
|
...faces.http,
|
|
151
173
|
...(token !== undefined ? { token } : {}),
|
|
152
174
|
...(allowedOrigins ? { allowedOrigins: [...allowedOrigins] } : {}),
|
|
175
|
+
...(allowedHosts !== undefined ? { allowedHosts } : {}),
|
|
153
176
|
},
|
|
154
|
-
})
|
|
177
|
+
});
|
|
178
|
+
transports.push(httpFace);
|
|
155
179
|
}
|
|
156
180
|
const sdkTransports = faces.sdk === undefined ? [] : isTransportList(faces.sdk) ? faces.sdk : [faces.sdk];
|
|
157
181
|
for (const sdkTransport of sdkTransports) {
|
|
@@ -159,22 +183,60 @@ export function createMcpHost(options = {}) {
|
|
|
159
183
|
}
|
|
160
184
|
for (const transport of transports)
|
|
161
185
|
server.addTransport(transport);
|
|
186
|
+
/** This function starts the server and its faces: by `start()`, or by the part of the runner. */
|
|
187
|
+
const begin = async () => {
|
|
188
|
+
if (stopping)
|
|
189
|
+
throw new Error("This MCP host stopped. A host stops one time: create a new host.");
|
|
190
|
+
if (stdio && stdio.redirectConsole !== false)
|
|
191
|
+
redirectConsoleToStderr();
|
|
192
|
+
await server.start();
|
|
193
|
+
running = true;
|
|
194
|
+
};
|
|
162
195
|
return {
|
|
163
196
|
registry,
|
|
164
197
|
policy,
|
|
165
198
|
server,
|
|
166
199
|
expose: policy.expose,
|
|
167
200
|
transports,
|
|
201
|
+
tasks: tasks?.store,
|
|
168
202
|
closed,
|
|
169
203
|
async start() {
|
|
170
|
-
if (
|
|
171
|
-
throw new Error("This MCP host
|
|
172
|
-
|
|
173
|
-
redirectConsoleToStderr();
|
|
174
|
-
await server.start();
|
|
175
|
-
running = true;
|
|
204
|
+
if (managed)
|
|
205
|
+
throw new Error("This MCP host is declared on a service: run() of the service starts it.");
|
|
206
|
+
await begin();
|
|
176
207
|
},
|
|
177
208
|
stop,
|
|
209
|
+
declare(svc) {
|
|
210
|
+
if (managed)
|
|
211
|
+
throw new Error("This MCP host is declared on a service already. A host declares one time.");
|
|
212
|
+
if (running || stopping)
|
|
213
|
+
throw new Error("This MCP host started without a service. Declare it before it starts.");
|
|
214
|
+
managed = true;
|
|
215
|
+
// The storages connect before the server starts, and close after it (as the procedures host does)
|
|
216
|
+
for (const handle of server.storageHandles()) {
|
|
217
|
+
svc.dependency(handle.name, { system: null, knobs: {}, operations: STORAGE_OPERATIONS }, handle);
|
|
218
|
+
}
|
|
219
|
+
svc.server("mcp", {}, {
|
|
220
|
+
start: () => begin(),
|
|
221
|
+
stopIntake: () => server.stopIntake(),
|
|
222
|
+
drain: (deadline, signal) => server.drain(deadline, signal),
|
|
223
|
+
inFlight: () => server.inFlight(),
|
|
224
|
+
close: async () => {
|
|
225
|
+
try {
|
|
226
|
+
await server.close();
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
await closeTasks();
|
|
230
|
+
running = false;
|
|
231
|
+
resolveClosed();
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
if (stdio)
|
|
236
|
+
svc.trigger("stdin-close");
|
|
237
|
+
return svc;
|
|
238
|
+
},
|
|
239
|
+
handleHttp: (req, res) => httpFace?.handleHttp(req, res) ?? false,
|
|
178
240
|
tools: () => distinctTools(namedTools(proceduresToMcpTools(registry.getAll(), toolFilter), options.toolName)),
|
|
179
241
|
state: () => ({ running, faces: transports.map((transport) => transport.getState()) }),
|
|
180
242
|
};
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,GAUhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAoC,MAAM,iBAAiB,CAAC;AACzF,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CAAC;YACH,IAAI,KAAK;gBAAE,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACtC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,KAAK;QACjE,KAAK,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,oBAAoB,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7G,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;KACvF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,12 @@ export { McpServerTransport } from "./transport/mcp-transport.js";
|
|
|
12
12
|
export { createStdioTransport } from "./transport/stdio.js";
|
|
13
13
|
export { createSseTransport } from "./transport/sse.js";
|
|
14
14
|
export { createMcpHost, mcpExposeRule, redirectConsoleToStderr } from "./host.js";
|
|
15
|
-
export type { McpHost, McpHostOptions, McpHostFaces, McpStdioFace, McpHostServerOptions, McpHostParts, McpHostState } from "./host.js";
|
|
15
|
+
export type { McpHost, McpHostOptions, McpHostFaces, McpStdioFace, McpHostServerOptions, McpHostParts, McpHostState, McpRunnerPart, McpRunnerDependency, McpServiceBuilder, } from "./host.js";
|
|
16
16
|
export { DEFAULT_ELICIT_TIMEOUT_MS } from "./transport/mcp-transport.js";
|
|
17
|
+
export { McpTaskStore, MCP_TASK_LIMITS } from "./tasks.js";
|
|
18
|
+
export type { McpTaskInfo, McpTaskStoreOptions, McpTasksOptions } from "./tasks.js";
|
|
19
|
+
export { guardMcpRequest, assertLoopbackBind, MCP_HTTP_LIMITS } from "./transport/guard.js";
|
|
20
|
+
export type { McpRequestGuardOptions, McpGuardResult } from "./transport/guard.js";
|
|
17
21
|
export { mcpFace } from "./face.js";
|
|
18
22
|
export type { McpFace, McpFaceContext, McpFaceOptions } from "./face.js";
|
|
19
23
|
export { createUntrustedEnvelopes, defaultUntrustedNotice, DEFAULT_UNTRUSTED_TAG } from "./untrusted.js";
|
|
@@ -24,6 +28,6 @@ export type { ServeOptions, ServeSetup } from "./procedures/mcp/serve.js";
|
|
|
24
28
|
export { exposeRule, mergeSurfaces, importBundles, resolveBundleRegister } from "./surface.js";
|
|
25
29
|
export type { ToolSurface, BundleSurfaceModule } from "./surface.js";
|
|
26
30
|
export { mcpListToolsProcedure } from "./procedures/mcp/list-tools.js";
|
|
27
|
-
export type { McpTool, McpToolDefinition, McpToolFilter, McpServerInfo, McpTransportType, } from "@procedures/mcp";
|
|
28
|
-
export { proceduresToMcpTools, procedureToMcpTool, encodePath, decodePath, } from "@procedures/mcp";
|
|
31
|
+
export type { McpTool, McpToolDefinition, McpToolExecution, McpTaskSupport, McpToolFilter, McpServerInfo, McpTransportType, } from "@procedures/mcp";
|
|
32
|
+
export { proceduresToMcpTools, procedureToMcpTool, taskSupportOf, encodePath, decodePath, } from "@procedures/mcp";
|
|
29
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAClF,YAA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,EACZ,cAAc,EACd,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAClG,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,YAAY,EACV,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,10 @@ export { createSseTransport } from "./transport/sse.js";
|
|
|
15
15
|
// The host factory (CLI-10): one MCP host for each server of procedures
|
|
16
16
|
export { createMcpHost, mcpExposeRule, redirectConsoleToStderr } from "./host.js";
|
|
17
17
|
export { DEFAULT_ELICIT_TIMEOUT_MS } from "./transport/mcp-transport.js";
|
|
18
|
+
// MCP tasks (CLI-35): a long tool call runs as a task, with a limit of tasks that run at one time
|
|
19
|
+
export { McpTaskStore, MCP_TASK_LIMITS } from "./tasks.js";
|
|
20
|
+
// The checks of a request to the Streamable HTTP face (CLI-35), for the face and a listener of a host
|
|
21
|
+
export { guardMcpRequest, assertLoopbackBind, MCP_HTTP_LIMITS } from "./transport/guard.js";
|
|
18
22
|
// The MCP face of a procedures host (CLI-7): Streamable HTTP on a listener of the host
|
|
19
23
|
export { mcpFace } from "./face.js";
|
|
20
24
|
// The envelopes of the text from outside the host (CLI-10)
|
|
@@ -24,5 +28,5 @@ export { mcpServeProcedure, prepareServe, DEFAULT_SERVE_BUNDLE } from "./procedu
|
|
|
24
28
|
export { exposeRule, mergeSurfaces, importBundles, resolveBundleRegister } from "./surface.js";
|
|
25
29
|
export { mcpListToolsProcedure } from "./procedures/mcp/list-tools.js";
|
|
26
30
|
// Re-export mapping utilities
|
|
27
|
-
export { proceduresToMcpTools, procedureToMcpTool, encodePath, decodePath, } from "@procedures/mcp";
|
|
31
|
+
export { proceduresToMcpTools, procedureToMcpTool, taskSupportOf, encodePath, decodePath, } from "@procedures/mcp";
|
|
28
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,aAAa,CAAC;AAE5B,YAAY;AACZ,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,aAAa,CAAC;AAE5B,YAAY;AACZ,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAalF,OAAO,EAAE,yBAAyB,EAAE,MAAM,8B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