@procedures/mcp-server 0.8.0 → 0.9.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/CHANGELOG.md +29 -0
- package/README.md +211 -292
- package/dist/.tsbuildinfo +1 -1
- package/dist/host.d.ts +168 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +182 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/procedures/mcp/serve.d.ts +18 -0
- package/dist/procedures/mcp/serve.d.ts.map +1 -1
- package/dist/procedures/mcp/serve.js +36 -31
- package/dist/procedures/mcp/serve.js.map +1 -1
- package/dist/transport/http.d.ts +4 -0
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +9 -3
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/mcp-transport.d.ts +26 -0
- package/dist/transport/mcp-transport.d.ts.map +1 -1
- package/dist/transport/mcp-transport.js +184 -19
- package/dist/transport/mcp-transport.js.map +1 -1
- package/dist/transport/stdio.d.ts +4 -2
- package/dist/transport/stdio.d.ts.map +1 -1
- package/dist/transport/stdio.js +4 -3
- package/dist/transport/stdio.js.map +1 -1
- package/dist/types.d.ts +70 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/untrusted.d.ts +56 -0
- package/dist/untrusted.d.ts.map +1 -0
- package/dist/untrusted.js +68 -0
- package/dist/untrusted.js.map +1 -0
- package/package.json +4 -4
- package/src/host.ts +346 -0
- package/src/index.ts +15 -0
- package/src/procedures/mcp/serve.ts +54 -36
- package/src/transport/http.ts +9 -3
- package/src/transport/mcp-transport.ts +206 -21
- package/src/transport/stdio.ts +5 -3
- package/src/types.ts +82 -2
- package/src/untrusted.ts +109 -0
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP host: one factory for each MCP server of procedures (CLI-10).
|
|
3
|
+
*
|
|
4
|
+
* Before, each MCP server built the same parts by hand. The parts are the redirect of
|
|
5
|
+
* `console.log`, the tool surface, the read-only narrowing and the host policy. The options of
|
|
6
|
+
* `ProcedureServer` and the `McpServerTransport` are parts too. The dev-tools server (`mark mcp`), `mcp.serve` and the Graph host each had a
|
|
7
|
+
* copy. `createMcpHost()` builds them from one set of options:
|
|
8
|
+
*
|
|
9
|
+
* - The procedures: a registry, modules, or both.
|
|
10
|
+
* - The tools: a surface (namespaces less some keys), a list of keys or patterns, or a function.
|
|
11
|
+
* - `readOnly`: the tools are only the procedures that change nothing, and each call has that
|
|
12
|
+
* capability.
|
|
13
|
+
* - The host policy (`hostPolicy()` of the core): the call policy (strict by default), the time
|
|
14
|
+
* limit, the interceptors and the capability. The host does not build the options of
|
|
15
|
+
* `ProcedureServer` by hand.
|
|
16
|
+
* - The faces: stdio, Streamable HTTP, and SDK transports. The stdio face stops the host when its
|
|
17
|
+
* input ends.
|
|
18
|
+
* - What each tool call gets: the questions to the person (elicitation, with the consents of the
|
|
19
|
+
* operator), the progress, the envelopes of untrusted text, and the instructions of the server.
|
|
20
|
+
*/
|
|
21
|
+
import type { Transport as SdkTransport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
22
|
+
import { ProcedureServer, type ElicitationPolicy, type HostPolicy, type HostPolicyOptions, type Interceptor, type ProcedureModule, type ProcedurePath, type ProcedureRegistry, type ProcedureServerOptions, type Duration } from "@procedures/client";
|
|
23
|
+
import { type McpTool, type McpToolFilter } from "@procedures/mcp";
|
|
24
|
+
import { McpServerTransport } from "./transport/mcp-transport.js";
|
|
25
|
+
import type { HttpTransportOptions, McpServerTransportState, McpToolContentHook, StdioTransportOptions } from "./types.js";
|
|
26
|
+
import type { UntrustedContentOptions } from "./untrusted.js";
|
|
27
|
+
/** The stdio face of a host. */
|
|
28
|
+
export interface McpStdioFace extends Omit<StdioTransportOptions, "onEnd"> {
|
|
29
|
+
/** True (the default): the host stops when the input ends. */
|
|
30
|
+
stopOnEnd?: boolean | undefined;
|
|
31
|
+
/** True (the default): `console.log` writes to stderr from `start()` on, so stdout carries only the protocol. */
|
|
32
|
+
redirectConsole?: boolean | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** The faces of a host. Each face is one `McpServerTransport` on the same server. */
|
|
35
|
+
export interface McpHostFaces {
|
|
36
|
+
/** The face over the standard input and output. `true`: `process.stdin` and `process.stdout`. */
|
|
37
|
+
stdio?: boolean | McpStdioFace | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 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.
|
|
41
|
+
*/
|
|
42
|
+
http?: HttpTransportOptions | undefined;
|
|
43
|
+
/** SDK transports to connect: the in-memory transport of a test, or an embedding. */
|
|
44
|
+
sdk?: SdkTransport | readonly SdkTransport[] | undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The options of `ProcedureServer` that the host policy does not give. */
|
|
47
|
+
export type McpHostServerOptions = Omit<ProcedureServerOptions, "registry" | "expose" | "strictCalls" | "interceptors" | "capability" | "clearanceOrder" | "resources" | "admitItem" | "token" | "principalOf" | "events">;
|
|
48
|
+
/** What a function of interceptors gets: the registry and the expose rule of the host. */
|
|
49
|
+
export interface McpHostParts {
|
|
50
|
+
readonly registry: ProcedureRegistry;
|
|
51
|
+
readonly expose: ((path: ProcedurePath) => boolean) | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The options of `createMcpHost()`. */
|
|
54
|
+
export interface McpHostOptions {
|
|
55
|
+
/** The registry of the procedures. Without it: a new registry of `modules`, or the global registry. */
|
|
56
|
+
registry?: ProcedureRegistry | undefined;
|
|
57
|
+
/** Modules of procedures. With `registry`, the host registers them in it. */
|
|
58
|
+
modules?: readonly ProcedureModule[] | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The tools: a surface (namespaces less some keys), keys and patterns (`git.status`, `git.*`,
|
|
61
|
+
* `*`), or a function of the path. Without it: each procedure of the registry.
|
|
62
|
+
*/
|
|
63
|
+
surface?: HostPolicyOptions["expose"];
|
|
64
|
+
/** Keys that are not tools, also when the surface matches them. */
|
|
65
|
+
exclude?: readonly string[] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* True: the tools are only the procedures that change nothing (`effects.writes` is empty), and
|
|
68
|
+
* each call has that capability (`narrowCapability`).
|
|
69
|
+
*/
|
|
70
|
+
readOnly?: boolean | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* More of the host policy: `strictCalls`, `timeout`, `interceptors`, `capability`, `resources`,
|
|
73
|
+
* `token`, `browser`. Strict calls are the safe default of an MCP host: a procedure of code
|
|
74
|
+
* without `metadata.calls` calls only tools. To turn them off, give `strictCalls: false`.
|
|
75
|
+
*/
|
|
76
|
+
policy?: Omit<HostPolicyOptions, "expose" | "exclude" | "readOnly"> | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Interceptors that need the parts of the host: a list, or a function of the registry and the
|
|
79
|
+
* expose rule (the check of a program before it starts). They come after `policy.interceptors`.
|
|
80
|
+
*/
|
|
81
|
+
interceptors?: readonly Interceptor[] | ((parts: McpHostParts) => readonly Interceptor[]) | undefined;
|
|
82
|
+
/** The options of `ProcedureServer` that the policy does not give: `autoRegister`, `collections`, `idempotency`. */
|
|
83
|
+
serverOptions?: McpHostServerOptions | undefined;
|
|
84
|
+
/** The name of the server for the MCP client. The default is `"procedure-server"`. */
|
|
85
|
+
name?: string | undefined;
|
|
86
|
+
/** The version of the server for the MCP client. The default is `"1.0.0"`. */
|
|
87
|
+
version?: string | undefined;
|
|
88
|
+
/** The instructions of the server: the MCP client gives them to the model. */
|
|
89
|
+
instructions?: string | undefined;
|
|
90
|
+
/** The faces of the host. The default is `{ stdio: true }`. */
|
|
91
|
+
faces?: McpHostFaces | undefined;
|
|
92
|
+
/** The rules of the questions to the person (CLI-12): `ask`, `operatorConsent`, `timeout`. */
|
|
93
|
+
elicitation?: ElicitationPolicy | undefined;
|
|
94
|
+
/** The envelopes of the output fields with text from outside the host (`metadata.untrusted`). */
|
|
95
|
+
untrusted?: UntrustedContentOptions | undefined;
|
|
96
|
+
/** The content hook: other text blocks for a successful result that is a value. */
|
|
97
|
+
content?: McpToolContentHook | undefined;
|
|
98
|
+
/** The JSON of the default text blocks: `"pretty"` (the default) or `"compact"` on one line. */
|
|
99
|
+
json?: "pretty" | "compact" | undefined;
|
|
100
|
+
/** More filters of the tools: tags, internal procedures. The surface gives the main rule. */
|
|
101
|
+
toolFilter?: Omit<McpToolFilter, "include"> | undefined;
|
|
102
|
+
/** The name of the tool of a procedure, for example `(path) => path.join("_")`. The default is `git.status`. */
|
|
103
|
+
toolName?: ((path: readonly string[]) => string) | undefined;
|
|
104
|
+
/** The limits of a stream that can continue without an end. */
|
|
105
|
+
streamLimits?: {
|
|
106
|
+
items?: number;
|
|
107
|
+
time?: Duration;
|
|
108
|
+
} | undefined;
|
|
109
|
+
/** True: debug lines go to stderr. */
|
|
110
|
+
debug?: boolean | undefined;
|
|
111
|
+
}
|
|
112
|
+
/** The state of a host: if it operates, and the state of each face. */
|
|
113
|
+
export interface McpHostState {
|
|
114
|
+
readonly running: boolean;
|
|
115
|
+
readonly faces: readonly McpServerTransportState[];
|
|
116
|
+
}
|
|
117
|
+
/** An MCP host: its registry, its policy, its server and its faces. */
|
|
118
|
+
export interface McpHost {
|
|
119
|
+
readonly registry: ProcedureRegistry;
|
|
120
|
+
readonly policy: HostPolicy;
|
|
121
|
+
readonly server: ProcedureServer;
|
|
122
|
+
/** The expose rule of the host: the procedures that are tools. Undefined: each procedure. */
|
|
123
|
+
readonly expose: ((path: ProcedurePath) => boolean) | undefined;
|
|
124
|
+
/** The MCP transports of the faces, in the order stdio, Streamable HTTP, SDK transports. */
|
|
125
|
+
readonly transports: readonly McpServerTransport[];
|
|
126
|
+
/** A promise that resolves when the host stopped: by `stop()`, or at the end of the stdio input. */
|
|
127
|
+
readonly closed: Promise<void>;
|
|
128
|
+
/** This function starts each face. */
|
|
129
|
+
start(): Promise<void>;
|
|
130
|
+
/** This function stops the server and each face. The calls in flight get the grace time. */
|
|
131
|
+
stop(options?: {
|
|
132
|
+
grace?: Duration | undefined;
|
|
133
|
+
}): Promise<void>;
|
|
134
|
+
/** The tools of the host at this time, from the registry and the expose rule. */
|
|
135
|
+
tools(): McpTool[];
|
|
136
|
+
/** The state of the host and of its faces. */
|
|
137
|
+
state(): McpHostState;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* This function sends `console.log` to stderr. Over stdio, stdout carries the protocol: a stray
|
|
141
|
+
* `console.log` of a procedure or a dependency corrupts it. The MCP SDK writes with
|
|
142
|
+
* `process.stdout.write`, so it is not affected. A second call changes nothing.
|
|
143
|
+
*/
|
|
144
|
+
export declare function redirectConsoleToStderr(): void;
|
|
145
|
+
/**
|
|
146
|
+
* The expose rule of a host: the surface less the excluded keys, and with `readOnly` only the
|
|
147
|
+
* procedures that the read-only capability permits. The rule reads the registry at each call,
|
|
148
|
+
* so a procedure that is registered later gets the same rule.
|
|
149
|
+
*/
|
|
150
|
+
export declare function mcpExposeRule(registry: ProcedureRegistry, options: Pick<McpHostOptions, "surface" | "exclude" | "readOnly">): ((path: ProcedurePath) => boolean) | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* This function builds an MCP host. It starts nothing: `start()` starts the faces. A host
|
|
153
|
+
* stops one time.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const host = createMcpHost({
|
|
158
|
+
* registry: createRegistry(graphModule),
|
|
159
|
+
* surface: { namespaces: ["graph"] },
|
|
160
|
+
* readOnly: process.argv.includes("--read-only"),
|
|
161
|
+
* name: "graph",
|
|
162
|
+
* version: "0.1.0",
|
|
163
|
+
* });
|
|
164
|
+
* await host.start();
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function createMcpHost(options?: McpHostOptions): McpHost;
|
|
168
|
+
//# sourceMappingURL=host.d.ts.map
|
|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ChE,4FAA4F;IAC5F,QAAQ,CAAC,UAAU,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACnD,oGAAoG;IACpG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,sCAAsC;IACtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,4FAA4F;IAC5F,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,iFAAiF;IACjF,KAAK,IAAI,OAAO,EAAE,CAAC;IACnB,8CAA8C;IAC9C,KAAK,IAAI,YAAY,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAQ9C;AAUD;;;;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,CAyGnE"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP host: one factory for each MCP server of procedures (CLI-10).
|
|
3
|
+
*
|
|
4
|
+
* Before, each MCP server built the same parts by hand. The parts are the redirect of
|
|
5
|
+
* `console.log`, the tool surface, the read-only narrowing and the host policy. The options of
|
|
6
|
+
* `ProcedureServer` and the `McpServerTransport` are parts too. The dev-tools server (`mark mcp`), `mcp.serve` and the Graph host each had a
|
|
7
|
+
* copy. `createMcpHost()` builds them from one set of options:
|
|
8
|
+
*
|
|
9
|
+
* - The procedures: a registry, modules, or both.
|
|
10
|
+
* - The tools: a surface (namespaces less some keys), a list of keys or patterns, or a function.
|
|
11
|
+
* - `readOnly`: the tools are only the procedures that change nothing, and each call has that
|
|
12
|
+
* capability.
|
|
13
|
+
* - The host policy (`hostPolicy()` of the core): the call policy (strict by default), the time
|
|
14
|
+
* limit, the interceptors and the capability. The host does not build the options of
|
|
15
|
+
* `ProcedureServer` by hand.
|
|
16
|
+
* - The faces: stdio, Streamable HTTP, and SDK transports. The stdio face stops the host when its
|
|
17
|
+
* input ends.
|
|
18
|
+
* - What each tool call gets: the questions to the person (elicitation, with the consents of the
|
|
19
|
+
* operator), the progress, the envelopes of untrusted text, and the instructions of the server.
|
|
20
|
+
*/
|
|
21
|
+
import { PROCEDURE_REGISTRY, ProcedureServer, capabilityRefusal, createRegistry, hostPolicy, narrowCapability, procedureServerOptions, registerModules, } from "@procedures/client";
|
|
22
|
+
import { proceduresToMcpTools } from "@procedures/mcp";
|
|
23
|
+
import { McpServerTransport, namedTools } from "./transport/mcp-transport.js";
|
|
24
|
+
/**
|
|
25
|
+
* This function sends `console.log` to stderr. Over stdio, stdout carries the protocol: a stray
|
|
26
|
+
* `console.log` of a procedure or a dependency corrupts it. The MCP SDK writes with
|
|
27
|
+
* `process.stdout.write`, so it is not affected. A second call changes nothing.
|
|
28
|
+
*/
|
|
29
|
+
export function redirectConsoleToStderr() {
|
|
30
|
+
const marked = console.log;
|
|
31
|
+
if (marked.mcpRedirected)
|
|
32
|
+
return;
|
|
33
|
+
const log = (...args) => {
|
|
34
|
+
console.error(...args);
|
|
35
|
+
};
|
|
36
|
+
log.mcpRedirected = true;
|
|
37
|
+
console.log = log;
|
|
38
|
+
}
|
|
39
|
+
/** True when the SDK option of the faces is a list of transports. */
|
|
40
|
+
function isTransportList(value) {
|
|
41
|
+
return Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
/** The read-only capability of a host: no effect can write. */
|
|
44
|
+
const READ_ONLY_REQUEST = { effects: { writes: [] } };
|
|
45
|
+
/**
|
|
46
|
+
* The expose rule of a host: the surface less the excluded keys, and with `readOnly` only the
|
|
47
|
+
* procedures that the read-only capability permits. The rule reads the registry at each call,
|
|
48
|
+
* so a procedure that is registered later gets the same rule.
|
|
49
|
+
*/
|
|
50
|
+
export function mcpExposeRule(registry, options) {
|
|
51
|
+
const base = hostPolicy({
|
|
52
|
+
...(options.surface !== undefined ? { expose: options.surface } : {}),
|
|
53
|
+
...(options.exclude !== undefined ? { exclude: options.exclude } : {}),
|
|
54
|
+
}).expose;
|
|
55
|
+
if (options.readOnly !== true)
|
|
56
|
+
return base;
|
|
57
|
+
const capability = narrowCapability(undefined, READ_ONLY_REQUEST);
|
|
58
|
+
return (path) => {
|
|
59
|
+
if (base && !base(path))
|
|
60
|
+
return false;
|
|
61
|
+
const procedure = registry.get(path);
|
|
62
|
+
return procedure !== undefined && capabilityRefusal(procedure, capability) === undefined;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* This function builds an MCP host. It starts nothing: `start()` starts the faces. A host
|
|
67
|
+
* stops one time.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const host = createMcpHost({
|
|
72
|
+
* registry: createRegistry(graphModule),
|
|
73
|
+
* surface: { namespaces: ["graph"] },
|
|
74
|
+
* readOnly: process.argv.includes("--read-only"),
|
|
75
|
+
* name: "graph",
|
|
76
|
+
* version: "0.1.0",
|
|
77
|
+
* });
|
|
78
|
+
* await host.start();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function createMcpHost(options = {}) {
|
|
82
|
+
const registry = options.registry ?? (options.modules ? createRegistry(...options.modules) : PROCEDURE_REGISTRY);
|
|
83
|
+
if (options.registry && options.modules)
|
|
84
|
+
registerModules(registry, [...options.modules]);
|
|
85
|
+
const expose = mcpExposeRule(registry, options);
|
|
86
|
+
const parts = { registry, expose };
|
|
87
|
+
const hostInterceptors = typeof options.interceptors === "function" ? options.interceptors(parts) : (options.interceptors ?? []);
|
|
88
|
+
const interceptors = [...(options.policy?.interceptors ?? []), ...hostInterceptors];
|
|
89
|
+
const policy = hostPolicy({
|
|
90
|
+
strictCalls: true,
|
|
91
|
+
...options.policy,
|
|
92
|
+
...(expose ? { expose } : {}),
|
|
93
|
+
...(options.readOnly === true ? { readOnly: true } : {}),
|
|
94
|
+
...(interceptors.length > 0 ? { interceptors } : {}),
|
|
95
|
+
});
|
|
96
|
+
const server = new ProcedureServer({ ...procedureServerOptions(policy, registry), ...options.serverOptions });
|
|
97
|
+
let resolveClosed = () => undefined;
|
|
98
|
+
const closed = new Promise((resolve) => {
|
|
99
|
+
resolveClosed = resolve;
|
|
100
|
+
});
|
|
101
|
+
let stopping;
|
|
102
|
+
let running = false;
|
|
103
|
+
const stop = (stopOptions = {}) => {
|
|
104
|
+
stopping ??= server
|
|
105
|
+
.stop(stopOptions.grace !== undefined ? { grace: stopOptions.grace } : {})
|
|
106
|
+
.finally(() => {
|
|
107
|
+
running = false;
|
|
108
|
+
resolveClosed();
|
|
109
|
+
});
|
|
110
|
+
return stopping;
|
|
111
|
+
};
|
|
112
|
+
// What each face shares: the tools, the server info and what each call gets
|
|
113
|
+
const toolFilter = { ...options.toolFilter, ...(policy.expose ? { include: policy.expose } : {}) };
|
|
114
|
+
const common = {
|
|
115
|
+
registry,
|
|
116
|
+
serverInfo: { name: options.name ?? "procedure-server", version: options.version ?? "1.0.0" },
|
|
117
|
+
toolFilter,
|
|
118
|
+
...(options.toolName ? { toolName: options.toolName } : {}),
|
|
119
|
+
...(options.instructions !== undefined ? { instructions: options.instructions } : {}),
|
|
120
|
+
...(options.elicitation ? { elicitation: options.elicitation } : {}),
|
|
121
|
+
...(options.untrusted ? { untrusted: options.untrusted } : {}),
|
|
122
|
+
...(options.content ? { content: options.content } : {}),
|
|
123
|
+
...(options.json ? { json: options.json } : {}),
|
|
124
|
+
...(options.streamLimits ? { streamLimits: options.streamLimits } : {}),
|
|
125
|
+
...(options.debug !== undefined ? { debug: options.debug } : {}),
|
|
126
|
+
};
|
|
127
|
+
const faces = options.faces ?? { stdio: true };
|
|
128
|
+
const transports = [];
|
|
129
|
+
const stdio = faces.stdio === true ? {} : faces.stdio === false ? undefined : faces.stdio;
|
|
130
|
+
if (stdio) {
|
|
131
|
+
transports.push(new McpServerTransport(server, {
|
|
132
|
+
...common,
|
|
133
|
+
transport: "stdio",
|
|
134
|
+
stdio: {
|
|
135
|
+
...(stdio.stdin ? { stdin: stdio.stdin } : {}),
|
|
136
|
+
...(stdio.stdout ? { stdout: stdio.stdout } : {}),
|
|
137
|
+
...(stdio.stopOnEnd !== false ? { onEnd: () => void stop() } : {}),
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
if (faces.http) {
|
|
142
|
+
// The HTTP face keeps the token and the origins of the policy (CLI-11 moves the checks to the host)
|
|
143
|
+
const policyOrigins = policy.browser.allowedOrigins;
|
|
144
|
+
const allowedOrigins = faces.http.allowedOrigins ?? (Array.isArray(policyOrigins) ? policyOrigins : undefined);
|
|
145
|
+
const token = faces.http.token ?? policy.token;
|
|
146
|
+
transports.push(new McpServerTransport(server, {
|
|
147
|
+
...common,
|
|
148
|
+
transport: "http",
|
|
149
|
+
httpOptions: {
|
|
150
|
+
...faces.http,
|
|
151
|
+
...(token !== undefined ? { token } : {}),
|
|
152
|
+
...(allowedOrigins ? { allowedOrigins: [...allowedOrigins] } : {}),
|
|
153
|
+
},
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
const sdkTransports = faces.sdk === undefined ? [] : isTransportList(faces.sdk) ? faces.sdk : [faces.sdk];
|
|
157
|
+
for (const sdkTransport of sdkTransports) {
|
|
158
|
+
transports.push(new McpServerTransport(server, { ...common, sdkTransport }));
|
|
159
|
+
}
|
|
160
|
+
for (const transport of transports)
|
|
161
|
+
server.addTransport(transport);
|
|
162
|
+
return {
|
|
163
|
+
registry,
|
|
164
|
+
policy,
|
|
165
|
+
server,
|
|
166
|
+
expose: policy.expose,
|
|
167
|
+
transports,
|
|
168
|
+
closed,
|
|
169
|
+
async start() {
|
|
170
|
+
if (stopping)
|
|
171
|
+
throw new Error("This MCP host stopped. A host stops one time: create a new host.");
|
|
172
|
+
if (stdio && stdio.redirectConsole !== false)
|
|
173
|
+
redirectConsoleToStderr();
|
|
174
|
+
await server.start();
|
|
175
|
+
running = true;
|
|
176
|
+
},
|
|
177
|
+
stop,
|
|
178
|
+
tools: () => namedTools(proceduresToMcpTools(registry.getAll(), toolFilter), options.toolName),
|
|
179
|
+
state: () => ({ running, faces: transports.map((transport) => transport.getState()) }),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,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,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAyI9E;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAkC,CAAC;IAC1D,IAAI,MAAM,CAAC,aAAa;QAAE,OAAO;IACjC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;QACvC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC;IACD,GAAmC,CAAC,aAAa,GAAG,IAAI,CAAC;IAC1D,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AACpB,CAAC;AAED,qEAAqE;AACrE,SAAS,eAAe,CAAC,KAA6C;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ED
|
@@ -11,7 +11,12 @@ export * from "./module.js";
|
|
|
11
11
|
export { McpServerTransport } from "./transport/mcp-transport.js";
|
|
12
12
|
export { createStdioTransport } from "./transport/stdio.js";
|
|
13
13
|
export { createSseTransport } from "./transport/sse.js";
|
|
14
|
-
export
|
|
14
|
+
export { createMcpHost, mcpExposeRule, redirectConsoleToStderr } from "./host.js";
|
|
15
|
+
export type { McpHost, McpHostOptions, McpHostFaces, McpStdioFace, McpHostServerOptions, McpHostParts, McpHostState } from "./host.js";
|
|
16
|
+
export { DEFAULT_ELICIT_TIMEOUT_MS } from "./transport/mcp-transport.js";
|
|
17
|
+
export { createUntrustedEnvelopes, defaultUntrustedNotice, DEFAULT_UNTRUSTED_TAG } from "./untrusted.js";
|
|
18
|
+
export type { UntrustedContentOptions, UntrustedWrapContext, UntrustedEnvelopes } from "./untrusted.js";
|
|
19
|
+
export type { McpServerTransportOptions, McpServerTransportState, SseTransportOptions, HttpTransportOptions, StdioTransportOptions, McpTextBlock, McpToolContent, McpToolContentInput, McpToolContentHook, } from "./types.js";
|
|
15
20
|
export { mcpServeProcedure, prepareServe, DEFAULT_SERVE_BUNDLE } from "./procedures/mcp/serve.js";
|
|
16
21
|
export type { ServeOptions, ServeSetup } from "./procedures/mcp/serve.js";
|
|
17
22
|
export { exposeRule, mergeSurfaces, importBundles, resolveBundleRegister } from "./surface.js";
|
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,YAAY,EACV,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,
|
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AiB,EACjB,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,11 @@ export * from "./module.js";
|
|
|
12
12
|
export { McpServerTransport } from "./transport/mcp-transport.js";
|
|
13
13
|
export { createStdioTransport } from "./transport/stdio.js";
|
|
14
14
|
export { createSseTransport } from "./transport/sse.js";
|
|
15
|
+
// The host factory (CLI-10): one MCP host for each server of procedures
|
|
16
|
+
export { createMcpHost, mcpExposeRule, redirectConsoleToStderr } from "./host.js";
|
|
17
|
+
export { DEFAULT_ELICIT_TIMEOUT_MS } from "./transport/mcp-transport.js";
|
|
18
|
+
// The envelopes of the text from outside the host (CLI-10)
|
|
19
|
+
export { createUntrustedEnvelopes, defaultUntrustedNotice, DEFAULT_UNTRUSTED_TAG } from "./untrusted.js";
|
|
15
20
|
// Procedures
|
|
16
21
|
export { mcpServeProcedure, prepareServe, DEFAULT_SERVE_BUNDLE } from "./procedures/mcp/serve.js";
|
|
17
22
|
export { exposeRule, mergeSurfaces, importBundles, resolveBundleRegister } from "./surface.js";
|
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;
|
|
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;AAElF,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,2DAA2D;AAC3D,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAgBzG,aAAa;AACb,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAElG,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAWvE,8BAA8B;AAC9B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC"}
|
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
* (default: `@procedures/bundle-mcp`, resolved from the current folder). Without a list,
|
|
10
10
|
* nothing is exposed. The nested calls follow the call policy (`strictCalls`), and each tool call
|
|
11
11
|
* has a time limit.
|
|
12
|
+
*
|
|
13
|
+
* The server comes from `createMcpHost()` (CLI-10), so its options come from `hostPolicy()` of the
|
|
14
|
+
* core, as for the dev-tools server. Before, `mcp.serve` built them by hand.
|
|
12
15
|
*/
|
|
13
16
|
import { ProcedureServer, ProcedureRegistry, type AnyProcedure, type ProcedurePath } from "@procedures/client";
|
|
17
|
+
import { type McpHost, type McpHostFaces } from "../../host.js";
|
|
14
18
|
/** The default bundle of the tool surface. */
|
|
15
19
|
export declare const DEFAULT_SERVE_BUNDLE = "@procedures/bundle-mcp";
|
|
16
20
|
/** The options of `prepareServe`: the tool surface and the rules of the server. */
|
|
@@ -21,11 +25,25 @@ export interface ServeOptions {
|
|
|
21
25
|
bundles?: readonly string[] | undefined;
|
|
22
26
|
strictCalls?: boolean | undefined;
|
|
23
27
|
toolTimeoutMs?: number | undefined;
|
|
28
|
+
/** True: the tools are only the procedures that change nothing. */
|
|
29
|
+
readOnly?: boolean | undefined;
|
|
30
|
+
/** The name of the server for the MCP client. */
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
/** The version of the server for the MCP client. */
|
|
33
|
+
version?: string | undefined;
|
|
34
|
+
/** The instructions of the server. */
|
|
35
|
+
instructions?: string | undefined;
|
|
36
|
+
/** True: debug lines go to stderr. */
|
|
37
|
+
debug?: boolean | undefined;
|
|
38
|
+
/** The faces of the host. The default is stdio. */
|
|
39
|
+
faces?: McpHostFaces | undefined;
|
|
24
40
|
}
|
|
25
41
|
/** The server of `mcp.serve`, before its transport starts. */
|
|
26
42
|
export interface ServeSetup {
|
|
27
43
|
server: ProcedureServer;
|
|
28
44
|
expose: (path: ProcedurePath) => boolean;
|
|
45
|
+
/** The MCP host of the server: `host.start()` starts its faces. */
|
|
46
|
+
host: McpHost;
|
|
29
47
|
/** Why the server has no tools, when it has none. */
|
|
30
48
|
warning?: string;
|
|
31
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAEL,eAAe,EAEf,iBAAiB,EACjB,KAAK,YAAY,EAEjB,KAAK,aAAa,EAEnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAG/E,8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"}
|
|
@@ -9,11 +9,14 @@
|
|
|
9
9
|
* (default: `@procedures/bundle-mcp`, resolved from the current folder). Without a list,
|
|
10
10
|
* nothing is exposed. The nested calls follow the call policy (`strictCalls`), and each tool call
|
|
11
11
|
* has a time limit.
|
|
12
|
+
*
|
|
13
|
+
* The server comes from `createMcpHost()` (CLI-10), so its options come from `hostPolicy()` of the
|
|
14
|
+
* core, as for the dev-tools server. Before, `mcp.serve` built them by hand.
|
|
12
15
|
*/
|
|
13
16
|
import { z } from "zod";
|
|
14
|
-
import { defineProcedure, ProcedureServer, PROCEDURE_REGISTRY, ProcedureRegistry,
|
|
15
|
-
import { McpServerTransport } from "../../transport/mcp-transport.js";
|
|
17
|
+
import { defineProcedure, ProcedureServer, PROCEDURE_REGISTRY, ProcedureRegistry, } from "@procedures/client";
|
|
16
18
|
import { exposeRule, importBundles, mergeSurfaces } from "../../surface.js";
|
|
19
|
+
import { createMcpHost } from "../../host.js";
|
|
17
20
|
import { ms } from "@procedures/client";
|
|
18
21
|
/** The default bundle of the tool surface. */
|
|
19
22
|
export const DEFAULT_SERVE_BUNDLE = "@procedures/bundle-mcp";
|
|
@@ -41,6 +44,10 @@ const McpServeInputSchema = z.object({
|
|
|
41
44
|
strictCalls: z.boolean().default(true).describe("True (the default): a procedure of code without metadata.calls can call only tools."),
|
|
42
45
|
/** The time limit of each tool call, in milliseconds (default: 600000). 0: no limit. */
|
|
43
46
|
toolTimeoutMs: z.number().int().min(0).default(600_000).describe("The time limit of each tool call, in milliseconds (default: 600000). 0: no limit."),
|
|
47
|
+
/** True: the tools are only the procedures that change nothing, and each call has that capability. */
|
|
48
|
+
readOnly: z.boolean().default(false).describe("True: the tools are only the procedures that change nothing, and each call has that capability."),
|
|
49
|
+
/** The instructions of the server: the MCP client gives them to the model. */
|
|
50
|
+
instructions: z.string().optional().describe("The instructions of the server: the MCP client gives them to the model."),
|
|
44
51
|
});
|
|
45
52
|
const McpServeOutputSchema = {
|
|
46
53
|
parse: (data) => data,
|
|
@@ -54,17 +61,18 @@ const McpServeOutputSchema = {
|
|
|
54
61
|
* and the host registers the modules (P9).
|
|
55
62
|
*/
|
|
56
63
|
export async function prepareServe(input, from = process.cwd(), registry = PROCEDURE_REGISTRY) {
|
|
57
|
-
|
|
64
|
+
// Without a surface, nothing is a tool
|
|
65
|
+
let surface = () => false;
|
|
58
66
|
let warning;
|
|
59
67
|
if (input.namespaces) {
|
|
60
|
-
|
|
68
|
+
surface = { namespaces: input.namespaces, exclude: input.exclude };
|
|
61
69
|
}
|
|
62
70
|
else {
|
|
63
71
|
const bundles = input.bundles ?? [DEFAULT_SERVE_BUNDLE];
|
|
64
72
|
try {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
|
|
73
|
+
const merged = mergeSurfaces(await importBundles(bundles, from));
|
|
74
|
+
if (merged) {
|
|
75
|
+
surface = { namespaces: merged.namespaces, exclude: [...(merged.exclude ?? []), ...(input.exclude ?? [])] };
|
|
68
76
|
}
|
|
69
77
|
else {
|
|
70
78
|
warning = `The bundles ${bundles.join(", ")} give no mcpNamespaces, so no procedure is a tool. Give namespaces.`;
|
|
@@ -76,14 +84,24 @@ export async function prepareServe(input, from = process.cwd(), registry = PROCE
|
|
|
76
84
|
`so no procedure is a tool. Give namespaces, or run in a project that has the bundles.`;
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
|
-
const
|
|
80
|
-
autoRegister: input.autoRegister ?? true,
|
|
87
|
+
const host = createMcpHost({
|
|
81
88
|
registry,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
surface,
|
|
90
|
+
readOnly: input.readOnly === true,
|
|
91
|
+
policy: { strictCalls: input.strictCalls ?? true, timeout: ms(input.toolTimeoutMs ?? 600_000) },
|
|
92
|
+
serverOptions: { autoRegister: input.autoRegister ?? true },
|
|
93
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
94
|
+
...(input.version !== undefined ? { version: input.version } : {}),
|
|
95
|
+
...(input.instructions !== undefined ? { instructions: input.instructions } : {}),
|
|
96
|
+
...(input.debug !== undefined ? { debug: input.debug } : {}),
|
|
97
|
+
faces: input.faces ?? { stdio: true },
|
|
85
98
|
});
|
|
86
|
-
|
|
99
|
+
// A surface always gives a rule, so the host has one
|
|
100
|
+
const expose = host.expose ?? (typeof surface === "function" ? surface : exposeRule(surface));
|
|
101
|
+
const setup = { server: host.server, expose, host };
|
|
102
|
+
if (warning !== undefined)
|
|
103
|
+
setup.warning = warning;
|
|
104
|
+
return setup;
|
|
87
105
|
}
|
|
88
106
|
export const mcpServeProcedure = defineProcedure({
|
|
89
107
|
path: ["mcp", "serve"],
|
|
@@ -100,29 +118,16 @@ export const mcpServeProcedure = defineProcedure({
|
|
|
100
118
|
const serverVersion = input.version ?? "1.0.0";
|
|
101
119
|
// The registry of the caller: a host with its own registry serves its own procedures
|
|
102
120
|
const registry = ctx?.registry instanceof ProcedureRegistry ? ctx.registry : PROCEDURE_REGISTRY;
|
|
103
|
-
const {
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
serverInfo: {
|
|
108
|
-
name: serverName,
|
|
109
|
-
version: serverVersion,
|
|
110
|
-
},
|
|
111
|
-
debug: input.debug,
|
|
112
|
-
toolFilter: { include: expose },
|
|
113
|
-
};
|
|
114
|
-
// Create MCP transport
|
|
115
|
-
const mcpTransport = new McpServerTransport(server, options);
|
|
116
|
-
// Add transport and start
|
|
117
|
-
server.addTransport(mcpTransport);
|
|
118
|
-
await server.start();
|
|
119
|
-
const state = mcpTransport.getState();
|
|
121
|
+
const { host, warning } = await prepareServe({ ...input, name: serverName, version: serverVersion, faces: { stdio: true } }, process.cwd(), registry);
|
|
122
|
+
// The face of stdio: it stops the host when the client closes the input
|
|
123
|
+
await host.start();
|
|
124
|
+
const toolCount = host.state().faces[0]?.toolCount ?? host.tools().length;
|
|
120
125
|
if (warning)
|
|
121
126
|
console.error(`[mcp.serve] ${warning}`);
|
|
122
127
|
return {
|
|
123
128
|
success: true,
|
|
124
129
|
transport: input.transport,
|
|
125
|
-
toolCount
|
|
130
|
+
toolCount,
|
|
126
131
|
serverName,
|
|
127
132
|
...(warning ? { warning } : {}),
|
|
128
133
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GAKlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAmC,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC;;;OAGG;IACH,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,yLAAyL,CAAC;IACjP,wDAAwD;IACxD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qDAAqD,CAAC;IAC3F,gDAAgD;IAChD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;IACtF,8DAA8D;IAC9D,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,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C,KAAK,EAAE,CAAC,MAAM,CAAC;QAC1E,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;QAErD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS;YACT,UAAU;YACV,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/dist/transport/http.d.ts
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* a local server apply: the server listens on loopback by default, it refuses a web page of
|
|
9
9
|
* another host or origin (DNS rebinding, cross-site requests), and with a token it refuses a
|
|
10
10
|
* request without the token.
|
|
11
|
+
*
|
|
12
|
+
* Each tool call carries the credentials of its HTTP request (CLI-10), so the request hook of the
|
|
13
|
+
* server (`principalOf`) and its token check apply. A server that reads cookies trusts a request
|
|
14
|
+
* with a cookie only from a named origin (CSRF).
|
|
11
15
|
*/
|
|
12
16
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
13
17
|
import type { HttpTransportOptions } from "../types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,mGAAmG;IACnG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,CAAC,SAAS,EAAE,6BAA6B,KAAK,OAAO,CAAC,IAAI,CAAC,GACnE,gBAAgB,CA8FlB"}
|