@procedures/mcp-server 0.14.0 → 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 +40 -0
- package/README.md +99 -2
- 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 +183 -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 +200 -81
- package/src/types.ts +44 -4
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
9
|
import {
|
|
10
10
|
CallToolRequestSchema,
|
|
11
|
+
ErrorCode,
|
|
11
12
|
ListToolsRequestSchema,
|
|
13
|
+
McpError,
|
|
14
|
+
type CallToolResult,
|
|
12
15
|
type ServerNotification,
|
|
16
|
+
type Task,
|
|
13
17
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
18
|
+
import type { RequestTaskStore } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
14
19
|
import type { Transport as SdkTransport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
15
20
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
16
21
|
import type {
|
|
@@ -37,6 +42,7 @@ import { createSseTransport } from "./sse.js";
|
|
|
37
42
|
import { createHttpTransport, type McpHttpTransport } from "./http.js";
|
|
38
43
|
import { optionalMs } from "@procedures/client";
|
|
39
44
|
import { createUntrustedEnvelopes } from "../untrusted.js";
|
|
45
|
+
import { taskStoreOf, type McpTaskStore } from "../tasks.js";
|
|
40
46
|
|
|
41
47
|
/**
|
|
42
48
|
* The tools with the names of a `toolName` function. Without the function, the tools keep the
|
|
@@ -77,6 +83,18 @@ interface CallExtra {
|
|
|
77
83
|
sendNotification: (notification: ServerNotification) => Promise<void>;
|
|
78
84
|
/** The HTTP request of the message: present only for a network transport (Streamable HTTP) */
|
|
79
85
|
requestInfo?: { headers: Record<string, string | string[] | undefined>; url?: URL | undefined } | undefined;
|
|
86
|
+
/** The task store of the request, when the server has tasks (CLI-35) */
|
|
87
|
+
taskStore?: RequestTaskStore | undefined;
|
|
88
|
+
/** The time to keep the task that the client asked for */
|
|
89
|
+
taskRequestedTtl?: number | null | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The capability of a server with tasks (MCP 2025-11-25): list, cancel, and tools/call as a task. */
|
|
93
|
+
const TASKS_CAPABILITY = { list: {}, cancel: {}, requests: { tools: { call: {} } } };
|
|
94
|
+
|
|
95
|
+
/** The status message of a task for a progress: only counts, so no text of the work leaves its envelopes. */
|
|
96
|
+
function progressMessage(progress: number, total: number | undefined): string {
|
|
97
|
+
return `${String(progress)}${total === undefined ? "" : ` of ${String(total)}`} done`;
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
/**
|
|
@@ -185,6 +203,9 @@ export class McpServerTransport implements ServerTransport {
|
|
|
185
203
|
private readonly streamLimits: { items: number; timeMs: number };
|
|
186
204
|
/** This function removes the listener of the end of the stdio input */
|
|
187
205
|
private stdinEnd: (() => void) | undefined;
|
|
206
|
+
/** The store of the tasks (CLI-35), and true when this transport made it (then its stop closes it) */
|
|
207
|
+
private readonly taskStore: McpTaskStore | undefined;
|
|
208
|
+
private readonly ownsTaskStore: boolean;
|
|
188
209
|
|
|
189
210
|
constructor(server: RequestHandler, options: McpServerTransportOptions = {}) {
|
|
190
211
|
this.server = server;
|
|
@@ -200,6 +221,9 @@ export class McpServerTransport implements ServerTransport {
|
|
|
200
221
|
items: Math.max(1, options.streamLimits?.items ?? 100),
|
|
201
222
|
timeMs: optionalMs(options.streamLimits?.time, "streamLimits.time") ?? 30_000,
|
|
202
223
|
};
|
|
224
|
+
const tasks = taskStoreOf(options.tasks);
|
|
225
|
+
this.taskStore = tasks?.store;
|
|
226
|
+
this.ownsTaskStore = tasks?.owned ?? false;
|
|
203
227
|
// The registry of the server, when it has one (a ProcedureServer with an explicit registry):
|
|
204
228
|
// before, the tools came from the global registry, also when the server served another one
|
|
205
229
|
this.registry =
|
|
@@ -223,9 +247,13 @@ export class McpServerTransport implements ServerTransport {
|
|
|
223
247
|
const server = new McpServer(this.options.serverInfo, {
|
|
224
248
|
capabilities: {
|
|
225
249
|
tools: { listChanged: true },
|
|
250
|
+
// MCP tasks (CLI-35): a long tool call can run as a task
|
|
251
|
+
...(this.taskStore ? { tasks: TASKS_CAPABILITY } : {}),
|
|
226
252
|
},
|
|
227
253
|
// The instructions of the server: the client gives them to the model (CLI-10)
|
|
228
254
|
...(this.options.instructions !== undefined ? { instructions: this.options.instructions } : {}),
|
|
255
|
+
// The SDK answers tasks/get, tasks/result, tasks/list and tasks/cancel from the store
|
|
256
|
+
...(this.taskStore ? { taskStore: this.taskStore } : {}),
|
|
229
257
|
});
|
|
230
258
|
this.setupHandlers(server);
|
|
231
259
|
return server;
|
|
@@ -239,7 +267,12 @@ export class McpServerTransport implements ServerTransport {
|
|
|
239
267
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
240
268
|
this.log("ListToolsRequest received");
|
|
241
269
|
|
|
242
|
-
|
|
270
|
+
// Without a task store, no tool runs as a task: the list does not say that it can
|
|
271
|
+
const tools = Array.from(this.tools.values(), (tool) => {
|
|
272
|
+
const definition = toToolDefinition(tool);
|
|
273
|
+
if (!this.taskStore) delete definition.execution;
|
|
274
|
+
return definition;
|
|
275
|
+
});
|
|
243
276
|
|
|
244
277
|
this.log(`Returning ${tools.length} tools`);
|
|
245
278
|
|
|
@@ -248,7 +281,7 @@ export class McpServerTransport implements ServerTransport {
|
|
|
248
281
|
|
|
249
282
|
// CallToolRequestSchema -> Execute procedure
|
|
250
283
|
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
251
|
-
const { name, arguments: args } = request.params;
|
|
284
|
+
const { name, arguments: args, task } = request.params;
|
|
252
285
|
|
|
253
286
|
this.log(`CallToolRequest: ${name}`);
|
|
254
287
|
|
|
@@ -262,87 +295,155 @@ export class McpServerTransport implements ServerTransport {
|
|
|
262
295
|
};
|
|
263
296
|
}
|
|
264
297
|
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
...(narrowing !== undefined ? { [NARROWING_METADATA_KEY]: narrowing } : {}),
|
|
282
|
-
},
|
|
283
|
-
// A cancelled tool call (notifications/cancelled) aborts the procedure
|
|
284
|
-
signal: extra.signal,
|
|
285
|
-
// The credentials of a call over the network: the request hook (principalOf) and the
|
|
286
|
-
// token check of the server apply to it (CLI-10)
|
|
287
|
-
...(credentials ? { credentials } : {}),
|
|
288
|
-
};
|
|
289
|
-
// What this face offers the procedure (CLI-12): the questions to the person, and the
|
|
290
|
-
// progress for a caller that sent a progress token
|
|
291
|
-
const elicit = elicitWithPolicy(this.faceElicit(server, extra), this.options.elicitation);
|
|
292
|
-
const progress = this.callProgress(extra);
|
|
293
|
-
const callRequest = {
|
|
294
|
-
...serverRequest,
|
|
295
|
-
...(elicit ? { elicit } : {}),
|
|
296
|
-
...(progress ? { progress: progress.report } : {}),
|
|
297
|
-
};
|
|
298
|
+
// MCP tasks (CLI-35): a call as a task needs a tool that can run as one, and a call of a
|
|
299
|
+
// tool that runs only as a task needs a task. Without a task store each call is a request.
|
|
300
|
+
const support = this.taskStore ? tool.execution?.taskSupport : undefined;
|
|
301
|
+
const callExtra = extra as CallExtra;
|
|
302
|
+
if (task !== undefined) {
|
|
303
|
+
if (!this.taskStore || (support !== "optional" && support !== "required")) {
|
|
304
|
+
throw new McpError(ErrorCode.MethodNotFound, `The tool ${name} does not run as a task`);
|
|
305
|
+
}
|
|
306
|
+
return this.startTask(server, this.taskStore, tool, args, callExtra);
|
|
307
|
+
}
|
|
308
|
+
if (support === "required") {
|
|
309
|
+
throw new McpError(ErrorCode.MethodNotFound, `The tool ${name} runs only as a task: call it with a task`);
|
|
310
|
+
}
|
|
311
|
+
return this.callTool(server, tool, args, callExtra);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
298
314
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
315
|
+
/**
|
|
316
|
+
* This method starts a tool call as a task (CLI-35). The client gets the task at once, and the
|
|
317
|
+
* call goes on. A progress of the procedure becomes the status message of the task, and a
|
|
318
|
+
* progress notification when the client sent a progress token. A cancel of the task aborts the
|
|
319
|
+
* call. A task above the limit of the store fails at once with the reason. The call of a task
|
|
320
|
+
* cannot ask the person: its request already has its answer.
|
|
321
|
+
*/
|
|
322
|
+
private async startTask(server: McpServer, store: McpTaskStore, tool: McpTool, args: Record<string, unknown> | undefined, extra: CallExtra): Promise<{ task: Task }> {
|
|
323
|
+
const taskStore = extra.taskStore;
|
|
324
|
+
if (!taskStore) throw new McpError(ErrorCode.InternalError, "The server has no task store for this request");
|
|
325
|
+
const ttl = extra.taskRequestedTtl;
|
|
326
|
+
const task = await taskStore.createTask(typeof ttl === "number" ? { ttl } : {});
|
|
327
|
+
const id = task.taskId;
|
|
328
|
+
const finish = async (result: CallToolResult): Promise<void> => {
|
|
329
|
+
// A cancelled task keeps its status: the store refuses a result after a cancel
|
|
330
|
+
await taskStore.storeTaskResult(id, result.isError === true ? "failed" : "completed", result).catch(() => undefined);
|
|
331
|
+
};
|
|
332
|
+
const refused = store.refusal(id);
|
|
333
|
+
if (refused !== undefined) {
|
|
334
|
+
await finish({ content: [{ type: "text", text: refused }], isError: true });
|
|
335
|
+
return { task: await taskStore.getTask(id) };
|
|
336
|
+
}
|
|
337
|
+
const token = extra._meta?.progressToken;
|
|
338
|
+
const background: CallExtra = {
|
|
339
|
+
...extra,
|
|
340
|
+
// The procedure reports its progress to the status of the task, also without a token of the client
|
|
341
|
+
_meta: { ...extra._meta, progressToken: token ?? `task-${id}` },
|
|
342
|
+
signal: store.signal(id),
|
|
343
|
+
sendNotification: async (notification) => {
|
|
344
|
+
if (notification.method === "notifications/progress") {
|
|
345
|
+
const { progress, total } = notification.params;
|
|
346
|
+
await taskStore.updateTaskStatus(id, "working", progressMessage(progress, total)).catch(() => undefined);
|
|
347
|
+
if (token === undefined) return;
|
|
348
|
+
}
|
|
349
|
+
// The response of the request went: later messages go on the stream of the session
|
|
350
|
+
await server.notification(notification).catch(() => undefined);
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
// The slot of the task stays taken until the call settles, also after a cancel
|
|
354
|
+
void this.callTool(server, tool, args, background, false)
|
|
355
|
+
.then(finish)
|
|
356
|
+
.catch(() => undefined)
|
|
357
|
+
.finally(() => store.settle(id));
|
|
358
|
+
return { task };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* This method calls the procedure of a tool and gives the MCP result. `offerElicit` is false for
|
|
363
|
+
* the call of a task: then the procedure gets no function to ask the person.
|
|
364
|
+
*/
|
|
365
|
+
private async callTool(server: McpServer, tool: McpTool, args: Record<string, unknown> | undefined, extra: CallExtra, offerElicit = true): Promise<CallToolResult> {
|
|
366
|
+
const name = tool.name;
|
|
367
|
+
// The path of the procedure of the tool. The method is the core mapping of every host
|
|
368
|
+
// (deep dive architecture review 3.3). A tool name of the toolName option does not decode,
|
|
369
|
+
// and a sanitized segment does not decode to the segment of the procedure.
|
|
370
|
+
const path = tool.procedurePath;
|
|
371
|
+
|
|
372
|
+
// Build ServerRequest
|
|
373
|
+
const credentials = callCredentials(extra);
|
|
374
|
+
const narrowing = callNarrowing(extra);
|
|
375
|
+
const serverRequest = {
|
|
376
|
+
id: generateRequestId(),
|
|
377
|
+
method: pathToMethod(path),
|
|
378
|
+
payload: args ?? {},
|
|
379
|
+
metadata: {
|
|
380
|
+
transport: "mcp" as const,
|
|
381
|
+
mcpRequestId: generateRequestId(),
|
|
382
|
+
// The narrowing key of the call: the server applies it (CLI-30)
|
|
383
|
+
...(narrowing !== undefined ? { [NARROWING_METADATA_KEY]: narrowing } : {}),
|
|
384
|
+
},
|
|
385
|
+
// A cancelled tool call (notifications/cancelled) aborts the procedure
|
|
386
|
+
signal: extra.signal,
|
|
387
|
+
// The credentials of a call over the network: the request hook (principalOf) and the
|
|
388
|
+
// token check of the server apply to it (CLI-10)
|
|
389
|
+
...(credentials ? { credentials } : {}),
|
|
390
|
+
};
|
|
391
|
+
// What this face offers the procedure (CLI-12): the questions to the person, and the
|
|
392
|
+
// progress for a caller that sent a progress token
|
|
393
|
+
const elicit = offerElicit ? elicitWithPolicy(this.faceElicit(server, extra), this.options.elicitation) : undefined;
|
|
394
|
+
const progress = this.callProgress(extra);
|
|
395
|
+
const callRequest = {
|
|
396
|
+
...serverRequest,
|
|
397
|
+
...(elicit ? { elicit } : {}),
|
|
398
|
+
...(progress ? { progress: progress.report } : {}),
|
|
399
|
+
};
|
|
302
400
|
|
|
303
|
-
|
|
401
|
+
try {
|
|
402
|
+
// Process through universal server
|
|
403
|
+
const response = await this.server.handle(callRequest);
|
|
304
404
|
|
|
305
|
-
|
|
306
|
-
if (response.status.type === "success" && response.stream) {
|
|
307
|
-
const unbounded = response.metadata?.["stream"] === "unbounded";
|
|
308
|
-
// The items are the progress of a stream, unless the procedure reports its own
|
|
309
|
-
return await this.streamResult(response.stream, extra, unbounded, tool, () => progress?.used() === true);
|
|
310
|
-
}
|
|
311
|
-
if (response.status.type === "success") {
|
|
312
|
-
const rendered = this.render(response.payload, tool);
|
|
313
|
-
const hooked = this.options.content?.({ ...rendered, tool, value: response.payload });
|
|
314
|
-
const result = hooked ?? rendered;
|
|
315
|
-
return {
|
|
316
|
-
content: result.content,
|
|
317
|
-
// MCP structured output: the result as an object, for a tool with an output schema.
|
|
318
|
-
// The text block stays, for clients that do not read structured content.
|
|
319
|
-
...(result.structuredContent ? { structuredContent: result.structuredContent } : {}),
|
|
320
|
-
};
|
|
321
|
-
} else {
|
|
322
|
-
// The code, the retryable flag and the reason of the error travel on each face (roadmap
|
|
323
|
-
// R25, CLI-48)
|
|
324
|
-
const reason = typeof response.metadata?.["reason"] === "string" ? response.metadata["reason"] : undefined;
|
|
325
|
-
return {
|
|
326
|
-
content: [
|
|
327
|
-
{
|
|
328
|
-
type: "text" as const,
|
|
329
|
-
text: `${response.status.message ?? "Unknown error"}${reason ? ` (reason: ${reason})` : ""}`,
|
|
330
|
-
},
|
|
331
|
-
],
|
|
332
|
-
isError: true,
|
|
333
|
-
_meta: { code: response.status.code, retryable: response.status.retryable === true, ...(reason ? { reason } : {}) },
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
} catch (error) {
|
|
337
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
338
|
-
this.log(`Tool ${name} error: ${message}`);
|
|
405
|
+
this.log(`Tool ${name} completed: ${response.status.type}`);
|
|
339
406
|
|
|
407
|
+
// Convert to MCP result
|
|
408
|
+
if (response.status.type === "success" && response.stream) {
|
|
409
|
+
const unbounded = response.metadata?.["stream"] === "unbounded";
|
|
410
|
+
// The items are the progress of a stream, unless the procedure reports its own
|
|
411
|
+
return await this.streamResult(response.stream, extra, unbounded, tool, () => progress?.used() === true);
|
|
412
|
+
}
|
|
413
|
+
if (response.status.type === "success") {
|
|
414
|
+
const rendered = this.render(response.payload, tool);
|
|
415
|
+
const hooked = this.options.content?.({ ...rendered, tool, value: response.payload });
|
|
416
|
+
const result = hooked ?? rendered;
|
|
417
|
+
return {
|
|
418
|
+
content: result.content,
|
|
419
|
+
// MCP structured output: the result as an object, for a tool with an output schema.
|
|
420
|
+
// The text block stays, for clients that do not read structured content.
|
|
421
|
+
...(result.structuredContent ? { structuredContent: result.structuredContent } : {}),
|
|
422
|
+
};
|
|
423
|
+
} else {
|
|
424
|
+
// The code, the retryable flag and the reason of the error travel on each face (roadmap
|
|
425
|
+
// R25, CLI-48)
|
|
426
|
+
const reason = typeof response.metadata?.["reason"] === "string" ? response.metadata["reason"] : undefined;
|
|
340
427
|
return {
|
|
341
|
-
content: [
|
|
428
|
+
content: [
|
|
429
|
+
{
|
|
430
|
+
type: "text" as const,
|
|
431
|
+
text: `${response.status.message ?? "Unknown error"}${reason ? ` (reason: ${reason})` : ""}`,
|
|
432
|
+
},
|
|
433
|
+
],
|
|
342
434
|
isError: true,
|
|
435
|
+
_meta: { code: response.status.code, retryable: response.status.retryable === true, ...(reason ? { reason } : {}) },
|
|
343
436
|
};
|
|
344
437
|
}
|
|
345
|
-
})
|
|
438
|
+
} catch (error) {
|
|
439
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
440
|
+
this.log(`Tool ${name} error: ${message}`);
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
content: [{ type: "text" as const, text: message }],
|
|
444
|
+
isError: true,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
346
447
|
}
|
|
347
448
|
|
|
348
449
|
/**
|
|
@@ -624,12 +725,22 @@ export class McpServerTransport implements ServerTransport {
|
|
|
624
725
|
// The face trusts cookies only as the server reads them (CSRF)
|
|
625
726
|
const ambientCredentials = (this.server as Partial<RequestHandler>).ambientCredentials;
|
|
626
727
|
const httpOptions = { ...this.options.httpOptions, ...(ambientCredentials ? { ambientCredentials } : {}) };
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
728
|
+
const taskStore = this.taskStore;
|
|
729
|
+
this.http = createHttpTransport(
|
|
730
|
+
httpOptions,
|
|
731
|
+
async (sessionTransport) => {
|
|
732
|
+
const sessionServer = this.createSdkServer();
|
|
733
|
+
this.sessionServers.add(sessionServer);
|
|
734
|
+
sessionServer.onclose = () => {
|
|
735
|
+
this.sessionServers.delete(sessionServer);
|
|
736
|
+
// The close of a session cancels its tasks: their work stops (CLI-35)
|
|
737
|
+
if (taskStore && sessionTransport.sessionId) void taskStore.cancelSession(sessionTransport.sessionId);
|
|
738
|
+
};
|
|
739
|
+
await sessionServer.connect(sessionTransport as unknown as SdkTransport);
|
|
740
|
+
},
|
|
741
|
+
// The session limit keeps each session with a task in progress open
|
|
742
|
+
taskStore ? { busySessions: () => taskStore.busySessions() } : {},
|
|
743
|
+
);
|
|
633
744
|
transport = undefined;
|
|
634
745
|
} else if (this.options.transport === "sse") {
|
|
635
746
|
transport = createSseTransport(this.options.sseOptions);
|
|
@@ -678,6 +789,8 @@ export class McpServerTransport implements ServerTransport {
|
|
|
678
789
|
await this.http?.close();
|
|
679
790
|
for (const sessionServer of this.sessionServers) await sessionServer.close().catch(() => undefined);
|
|
680
791
|
this.sessionServers.clear();
|
|
792
|
+
// A store of this transport stops with it: its tasks are cancelled (CLI-35)
|
|
793
|
+
if (this.ownsTaskStore) await this.taskStore?.close();
|
|
681
794
|
this.http = undefined;
|
|
682
795
|
this.httpUrl = undefined;
|
|
683
796
|
this.running = false;
|
|
@@ -708,9 +821,15 @@ export class McpServerTransport implements ServerTransport {
|
|
|
708
821
|
toolCount: this.tools.size,
|
|
709
822
|
transport: this.options.transport,
|
|
710
823
|
...(this.httpUrl ? { url: this.httpUrl } : {}),
|
|
824
|
+
...(this.http ? { sessions: this.http.sessions } : {}),
|
|
711
825
|
};
|
|
712
826
|
}
|
|
713
827
|
|
|
828
|
+
/** The store of the tasks (CLI-35), or undefined when the transport has no tasks. */
|
|
829
|
+
getTaskStore(): McpTaskStore | undefined {
|
|
830
|
+
return this.taskStore;
|
|
831
|
+
}
|
|
832
|
+
|
|
714
833
|
/**
|
|
715
834
|
* Get the list of available tools.
|
|
716
835
|
*/
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { ElicitationPolicy, ProcedureRegistry } from "@procedures/client";
|
|
|
10
10
|
import type { McpServerInfo, McpTool, McpToolFilter } from "@procedures/mcp";
|
|
11
11
|
import type { Duration } from "@procedures/client";
|
|
12
12
|
import type { UntrustedContentOptions } from "./untrusted.js";
|
|
13
|
+
import type { McpTasksOptions } from "./tasks.js";
|
|
13
14
|
|
|
14
15
|
/** The streams of the stdio transport, and what happens when its input ends. */
|
|
15
16
|
export interface StdioTransportOptions {
|
|
@@ -51,11 +52,21 @@ export type McpToolContentHook = (result: McpToolContentInput) => McpToolContent
|
|
|
51
52
|
/**
|
|
52
53
|
* SSE transport configuration options.
|
|
53
54
|
*/
|
|
54
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* The options of the Streamable HTTP transport (roadmap R26). Give `mount: true` and mount the
|
|
57
|
+
* handler of the endpoint on a listener. An endpoint with a listener of its own (`port`, `host`,
|
|
58
|
+
* `server`) is deprecated (CLI-11).
|
|
59
|
+
*/
|
|
55
60
|
export interface HttpTransportOptions {
|
|
56
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Port to listen on (default: 3003)
|
|
63
|
+
* @deprecated The next MINOR removes the listener of the endpoint (CLI-11). Give `mount: true`, and mount `McpHost.handleHttp` on a listener of the service.
|
|
64
|
+
*/
|
|
57
65
|
port?: number | undefined;
|
|
58
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Host to bind to (default: "127.0.0.1": only this computer can reach the tools)
|
|
68
|
+
* @deprecated The next MINOR removes the listener of the endpoint (CLI-11). The listener of the service sets its address.
|
|
69
|
+
*/
|
|
59
70
|
host?: string | undefined;
|
|
60
71
|
/** The path of the MCP endpoint (default: "/mcp") */
|
|
61
72
|
path?: string | undefined;
|
|
@@ -63,7 +74,15 @@ export interface HttpTransportOptions {
|
|
|
63
74
|
token?: string | undefined;
|
|
64
75
|
/** Browser origins that can call the server, besides loopback origins */
|
|
65
76
|
allowedOrigins?: string[] | undefined;
|
|
66
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The host names that a request on a loopback address can name in its `Host` header, besides
|
|
79
|
+
* the loopback names (`browser.allowedHosts` of the host policy). `"*"` turns the check off.
|
|
80
|
+
*/
|
|
81
|
+
allowedHosts?: readonly string[] | "*" | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* An HTTP server to answer on, in place of a server of the transport (it does not listen then)
|
|
84
|
+
* @deprecated The next MINOR removes it (CLI-11). Give `mount: true`, and mount the handler on the server.
|
|
85
|
+
*/
|
|
67
86
|
server?: import("node:http").Server | undefined;
|
|
68
87
|
/**
|
|
69
88
|
* True: the endpoint has no server and attaches to none. The owner of a listener mounts its
|
|
@@ -75,6 +94,18 @@ export interface HttpTransportOptions {
|
|
|
75
94
|
* transport sets it from its server. With a value, a request with a cookie needs a named origin.
|
|
76
95
|
*/
|
|
77
96
|
ambientCredentials?: import("@procedures/client").AmbientCredentials | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The most sessions at one time (CLI-35). A new session above the limit closes the session that
|
|
99
|
+
* was idle longest: no task in progress and no open response. When each session is busy, the
|
|
100
|
+
* new session gets 503 with `Retry-After`.
|
|
101
|
+
* @default Infinity (no limit)
|
|
102
|
+
*/
|
|
103
|
+
maxSessions?: number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The largest body of a request, in bytes (CLI-35).
|
|
106
|
+
* @default 4194304 (4 MiB, the limit of the SDK)
|
|
107
|
+
*/
|
|
108
|
+
maxBodyBytes?: number | undefined;
|
|
78
109
|
}
|
|
79
110
|
|
|
80
111
|
export interface SseTransportOptions {
|
|
@@ -164,6 +195,13 @@ export interface McpServerTransportOptions {
|
|
|
164
195
|
* @default { items: 100, time: seconds(30) }
|
|
165
196
|
*/
|
|
166
197
|
streamLimits?: { items?: number; time?: Duration } | undefined;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* MCP tasks (CLI-35): a store, or the options of a new store (`maxRunning`, `ttl`). With it, a
|
|
201
|
+
* tool whose procedure has `metadata.taskSupport` can run as a task. Without it, each tool call
|
|
202
|
+
* is a normal request. The stop of the transport closes a store that it made.
|
|
203
|
+
*/
|
|
204
|
+
tasks?: McpTasksOptions | undefined;
|
|
167
205
|
}
|
|
168
206
|
|
|
169
207
|
/**
|
|
@@ -178,4 +216,6 @@ export interface McpServerTransportState {
|
|
|
178
216
|
transport: "stdio" | "sse" | "http";
|
|
179
217
|
/** The URL of the Streamable HTTP endpoint, when the transport is "http" */
|
|
180
218
|
url?: string;
|
|
219
|
+
/** The open sessions of the Streamable HTTP endpoint, when the transport is "http" (CLI-35) */
|
|
220
|
+
sessions?: number;
|
|
181
221
|
}
|