@orkestrel/mcp 0.0.28 → 0.0.29
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/README.md +11 -14
- package/dist/src/browser/index.d.ts +63 -65
- package/dist/src/browser/index.js +44 -44
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +233 -176
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +442 -366
- package/dist/src/core/index.d.ts +442 -366
- package/dist/src/core/index.js +233 -176
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +109 -109
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +209 -203
- package/dist/src/server/index.d.ts +209 -203
- package/dist/src/server/index.js +109 -109
- package/dist/src/server/index.js.map +1 -1
- package/package.json +24 -25
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
-
import { JSONValue } from '@orkestrel/contract';
|
|
5
|
-
import { ToolCall } from '@orkestrel/tool';
|
|
6
|
-
import { ToolInterface } from '@orkestrel/tool';
|
|
7
|
-
import { ToolManagerInterface } from '@orkestrel/tool';
|
|
8
|
-
import { ToolResult } from '@orkestrel/tool';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
+
import type { JSONValue } from '@orkestrel/contract';
|
|
5
|
+
import type { ToolCall } from '@orkestrel/tool';
|
|
6
|
+
import type { ToolInterface } from '@orkestrel/tool';
|
|
7
|
+
import type { ToolManagerInterface } from '@orkestrel/tool';
|
|
8
|
+
import type { ToolResult } from '@orkestrel/tool';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Pipes an {@link MCPTransportInterface} into an {@link MCPClientInterface} — every
|
|
12
|
-
* inbound message is decoded and delivered onto the client's
|
|
12
|
+
* inbound message is decoded and delivered onto the client's own transport
|
|
13
13
|
* (`client.transport.emitter`'s `message` / `close` events), resolving/rejecting the
|
|
14
14
|
* client's correlated pending requests exactly as a direct reply would.
|
|
15
15
|
*
|
|
@@ -17,30 +17,30 @@ import { ToolResult } from '@orkestrel/tool';
|
|
|
17
17
|
* The client's outbound writes flow through `client.transport.send` — its existing,
|
|
18
18
|
* unmodified request/response correlation — so `client` must have been constructed
|
|
19
19
|
* with a {@link import('./types.js').MCPMessageTransportInterface} that itself carries
|
|
20
|
-
* the
|
|
20
|
+
* the same `transport` (see {@link import('./factories.js').createDuplexClientTransport},
|
|
21
21
|
* the additive factory that adapts an {@link MCPTransportInterface} into that shape);
|
|
22
22
|
* this binder then completes the inbound half by decoding each message and pushing it
|
|
23
23
|
* onto `client.transport.emitter` (an {@link import('@orkestrel/emitter').EmitterInterface}
|
|
24
24
|
* exposes `emit`, so no client modification is needed). A malformed / non-JSON-RPC
|
|
25
|
-
* inbound message is
|
|
25
|
+
* inbound message is dropped (total — never throws); a delivery fault is routed to
|
|
26
26
|
* `client.transport.emitter`'s `error` event (never rethrown). The returned unbind
|
|
27
|
-
*
|
|
28
|
-
* ignored)
|
|
27
|
+
* detaches this binder (further inbound messages and the transport's `closed` signal are
|
|
28
|
+
* ignored) without closing the transport.
|
|
29
29
|
*
|
|
30
|
-
* `listen`/`closed` are
|
|
31
|
-
*
|
|
32
|
-
* `bindClient` call on the
|
|
30
|
+
* `listen`/`closed` are replace semantics (§ port contract): the returned unbind
|
|
31
|
+
* detaches by replacing this binder's own handlers with no-ops, so a subsequent
|
|
32
|
+
* `bindClient` call on the same transport is never double-dispatched by a stale
|
|
33
33
|
* subscription left behind — an unbind→rebind cycle delivers exactly one `message`
|
|
34
34
|
* emit per inbound reply.
|
|
35
35
|
*
|
|
36
36
|
* **This binder needs no live-request registry, and the asymmetry with {@link bindServer} is
|
|
37
|
-
* real rather than an omission.** A server binder holds the lifetime of work it
|
|
37
|
+
* real rather than an omission.** A server binder holds the lifetime of work it started, so an
|
|
38
38
|
* inbound `notifications/cancelled` has something to reach; a client binder starts no work —
|
|
39
39
|
* `MCPClient` already owns its pending entries and already writes the cancellation frame
|
|
40
40
|
* itself when a caller's `signal` aborts, on a carrier declaring `duplex`. Adding a registry
|
|
41
|
-
* here would be a second correlation table for ids the client is already correlating, and
|
|
42
|
-
* tables for one fact drift. The one obligation this binder does carry is delivery: a
|
|
43
|
-
* malformed / non-JSON-RPC inbound message is
|
|
41
|
+
* here would be a second correlation table for ids the client is already correlating, and a
|
|
42
|
+
* pair of tables for one fact drift. The one obligation this binder does carry is delivery: a
|
|
43
|
+
* malformed / non-JSON-RPC inbound message is dropped (total — never throws).
|
|
44
44
|
*
|
|
45
45
|
* @param client - The transport-agnostic client whose transport to deliver messages onto
|
|
46
46
|
* @param transport - The duplex channel to pipe the client over
|
|
@@ -66,36 +66,36 @@ export declare function bindClient(client: MCPClientInterface, transport: MCPTra
|
|
|
66
66
|
* `server.handle` already turns a malformed message into a serialized `-32700` /
|
|
67
67
|
* `-32600` reply and a notification into `undefined` (no reply), so this binder parses
|
|
68
68
|
* nothing the server would parse differently: it decodes each inbound message through
|
|
69
|
-
* {@link decodeBoundedMessage} under `server.limit`, the
|
|
69
|
+
* {@link decodeBoundedMessage} under `server.limit`, the server's own bound, so a message
|
|
70
70
|
* the server would refuse is never parsed here either and still receives its `-32700` from
|
|
71
|
-
* the one place that words it. A
|
|
71
|
+
* the one place that words it. A held-open reply arrives as an
|
|
72
72
|
* {@link import('./types.js').MCPTextStreamControllerInterface} instead of a string: this is
|
|
73
73
|
* the one place that pumps it, writing each notification in order and then the generator's
|
|
74
74
|
* returned terminating response ({@link sendStream}). A `transport.send` throw or rejection —
|
|
75
75
|
* mid-stream included — is caught and routed
|
|
76
76
|
* to `server.emitter`'s `error` event (never rethrown, never an unhandled rejection);
|
|
77
77
|
* a listener on that event that itself throws is swallowed (the end of the line —
|
|
78
|
-
* the caller's own bug, never this binder's). A fault raised
|
|
78
|
+
* the caller's own bug, never this binder's). A fault raised after its own request was
|
|
79
79
|
* cancelled reports nothing, because a cancellation is not a fault.
|
|
80
80
|
*
|
|
81
|
-
* **This binder
|
|
81
|
+
* **This binder owns every exchange it starts, and ends each one on every exit.** It holds one
|
|
82
82
|
* `AbortController` per live request, keyed by the request's id and deleted whenever that
|
|
83
83
|
* request leaves — normally, by a throw, or by cancellation — and it supplies that signal to
|
|
84
84
|
* `handle` as {@link import('./types.js').MCPDispatchOptions}. These consequences follow.
|
|
85
|
-
* An inbound `notifications/cancelled`
|
|
85
|
+
* An inbound `notifications/cancelled` aborts the request it names, which is how the message-
|
|
86
86
|
* based cancellation path reaches a tool on the carriers that have one (stdio, WebSocket,
|
|
87
|
-
* `MessagePort`); a cancelled request writes
|
|
87
|
+
* `MessagePort`); a cancelled request writes no response, because a peer that asked for a call
|
|
88
88
|
* to stop is not answered by it; and the transport's `closed` signal aborts every request
|
|
89
89
|
* still in flight, so an exchange being pumped when the carrier dies ends with it instead of
|
|
90
90
|
* writing into a socket nobody is holding.
|
|
91
91
|
*
|
|
92
|
-
* `listen`/`closed` are
|
|
93
|
-
*
|
|
94
|
-
* `bindServer` call on the
|
|
92
|
+
* `listen`/`closed` are replace semantics (§ port contract): the returned unbind
|
|
93
|
+
* detaches by replacing this binder's own handlers with no-ops, so a subsequent
|
|
94
|
+
* `bindServer` call on the same transport is never double-dispatched by a stale
|
|
95
95
|
* subscription left behind — an unbind→rebind cycle yields exactly one reply per
|
|
96
96
|
* request. Unbinding is itself an owner exit: it aborts and retires every request still in
|
|
97
97
|
* flight before detaching, so `unbind()` then `close()` and `close()` then `unbind()` end the
|
|
98
|
-
* same exchanges. It does
|
|
98
|
+
* same exchanges. It does not close the transport; that remains the caller's decision.
|
|
99
99
|
*
|
|
100
100
|
* @param server - The transport-agnostic server to dispatch inbound messages over
|
|
101
101
|
* @param transport - The duplex channel to pipe the server over
|
|
@@ -119,12 +119,12 @@ export declare function bindServer(server: MCPDispatcherInterface, transport: MC
|
|
|
119
119
|
* the arms the protocol gives a shape to, and deriving the tool's value from the one it
|
|
120
120
|
* does not:
|
|
121
121
|
*
|
|
122
|
-
* - A peer's `structuredContent` is
|
|
122
|
+
* - A peer's `structuredContent` is preferred over the content blocks, because it is the
|
|
123
123
|
* tool's value in its original structure while the blocks are a rendering beside it. Its
|
|
124
124
|
* mere presence decides — an explicit `null` is a value the tool returned, not an absence.
|
|
125
125
|
* - With no structured value the legacy shape applies: the value was JSON-serialized into
|
|
126
126
|
* the text block(s), so parse them and fall back to the raw string when they are not JSON.
|
|
127
|
-
* - A remote tool
|
|
127
|
+
* - A remote tool failure (`isError: true`) throws the error text, so an agent's tool
|
|
128
128
|
* registry isolates it into a failure result exactly as it would a local throw.
|
|
129
129
|
*
|
|
130
130
|
* @param name - The tool's name, used only to describe a failure that carried no text
|
|
@@ -145,7 +145,7 @@ export declare function buildCallOutcome(name: string, result: unknown): MCPCall
|
|
|
145
145
|
* Builds one official cancellation notification for a request already sent.
|
|
146
146
|
*
|
|
147
147
|
* @remarks
|
|
148
|
-
* `requestId` and `reason` are
|
|
148
|
+
* `requestId` and `reason` are wire spellings carried verbatim from the dated schema's
|
|
149
149
|
* `CancelledNotificationParams`, and so is the `cancelled` in the method name — this
|
|
150
150
|
* package's own vocabulary says `abort`, but the method is the protocol's and does not
|
|
151
151
|
* change. The notification is FIRE-AND-FORGET in the strongest sense: it carries no id,
|
|
@@ -178,7 +178,7 @@ export declare function buildCancelledNotification(id: JSONRPCId, reason?: strin
|
|
|
178
178
|
* `capabilities.resources` and `capabilities.prompts` appear only for servers with their
|
|
179
179
|
* respective managers and derive notification flags from the configured subscription filter.
|
|
180
180
|
* `capabilities.completions` is independent and appears only with a completion provider.
|
|
181
|
-
* `capabilities.extensions` appears only for a server that
|
|
181
|
+
* `capabilities.extensions` appears only for a server that configured the extension it
|
|
182
182
|
* would name. An advertisement is a promise a client is entitled to act on, so a server
|
|
183
183
|
* with no `task` policy omits the member entirely rather than advertising an empty
|
|
184
184
|
* record — and its discovery answer stays byte-for-byte what it was before the extension
|
|
@@ -194,8 +194,8 @@ export declare function buildDiscoverResult(options: MCPServerOptions): MCPDisco
|
|
|
194
194
|
*
|
|
195
195
|
* @remarks
|
|
196
196
|
* The single decision both sides of the protocol make about an annotated tool: an HTTP
|
|
197
|
-
*
|
|
198
|
-
*
|
|
197
|
+
* client excludes a definition this refuses from the `tools/list` result it delivers, and a
|
|
198
|
+
* server recognizes exactly the `Mcp-Param-*` names this returns for its own definitions.
|
|
199
199
|
*
|
|
200
200
|
* `undefined` means the definition is invalid, and every rule the protocol states produces
|
|
201
201
|
* it: a value that is not an RFC 9110 token, a non-primitive or untyped annotated leaf, a
|
|
@@ -266,14 +266,14 @@ export declare function buildInitializeResult(name: string, version: string, req
|
|
|
266
266
|
* as an `error` object.
|
|
267
267
|
*
|
|
268
268
|
* @remarks
|
|
269
|
-
* An `undefined` `id` is
|
|
269
|
+
* An `undefined` `id` is omitted from the envelope rather than serialized as `null`:
|
|
270
270
|
* MCP overrides the base specification here, so a peer that could not have its id
|
|
271
271
|
* read receives a response with no `id` member at all.
|
|
272
272
|
*
|
|
273
273
|
* @param id - The failed request's id, or `undefined` when none could be read
|
|
274
274
|
* @param code - One of the reserved JSON-RPC codes (see `./constants.js`)
|
|
275
275
|
* @param message - A short human description of the failure
|
|
276
|
-
* @param data - An
|
|
276
|
+
* @param data - An optional machine-readable payload (omitted from the envelope when absent)
|
|
277
277
|
* @returns The error response envelope
|
|
278
278
|
*/
|
|
279
279
|
export declare function buildJSONRPCError(id: JSONRPCId | undefined, code: number, message: string, data?: unknown): JSONRPCErrorResponse;
|
|
@@ -297,11 +297,11 @@ export declare function buildJSONRPCResult(id: JSONRPCId, result: MCPResult | MC
|
|
|
297
297
|
* receives.
|
|
298
298
|
*
|
|
299
299
|
* @remarks
|
|
300
|
-
* The
|
|
300
|
+
* The one place a cancellation signal is resolved. A caller may have no signal to
|
|
301
301
|
* offer; a dispatched method always has one to observe, so a missing signal becomes
|
|
302
302
|
* a real signal rather than an absence every downstream handler would have to case on.
|
|
303
303
|
*
|
|
304
|
-
* The resolved signal is the request's
|
|
304
|
+
* The resolved signal is the request's lifetime, which is strictly wider than the
|
|
305
305
|
* caller's: it composes the caller's signal, when there is one, with the `lifetime`
|
|
306
306
|
* dispatch owns and aborts once the answer this request produced is finished. That is
|
|
307
307
|
* what wakes a stream producer parked on an event that will never arrive after its
|
|
@@ -430,7 +430,7 @@ export declare function buildToolDescriptors(manager: ToolManagerInterface): rea
|
|
|
430
430
|
* Computes the capabilities one round of input requests needs and the client did not declare.
|
|
431
431
|
*
|
|
432
432
|
* @remarks
|
|
433
|
-
* The protocol's rule is about
|
|
433
|
+
* The protocol's rule is about sending: a server never issues a request kind the client's
|
|
434
434
|
* declared capabilities exclude. So this reads the round rather than the method, and it
|
|
435
435
|
* answers with the refusal's own payload — the `requiredCapabilities` record a
|
|
436
436
|
* `MissingRequiredClientCapability` error carries, keyed by each missing capability, in the
|
|
@@ -442,7 +442,7 @@ export declare function buildToolDescriptors(manager: ToolManagerInterface): rea
|
|
|
442
442
|
* recognize needs nothing, because {@link import('./validators.js').isMCPInputRequestMap}
|
|
443
443
|
* has already refused the round it would have travelled in. Total over hostile input.
|
|
444
444
|
*
|
|
445
|
-
* The `elicitation` value names the
|
|
445
|
+
* The `elicitation` value names the arm the round needs, so a client can act on the refusal
|
|
446
446
|
* by declaring exactly what the payload asks for. A missing URL arm answers `{ url: {} }`, a
|
|
447
447
|
* missing form arm answers the empty record this package reads as form-only, and a round
|
|
448
448
|
* needing both answers `{ form: {}, url: {} }`. An empty record for a URL round would name
|
|
@@ -465,7 +465,7 @@ export declare function computeMissingCapabilities(requests: MCPInputRequestMap,
|
|
|
465
465
|
*
|
|
466
466
|
* @remarks
|
|
467
467
|
* The companion of {@link extractHeaderAnnotations}, which reads only the annotations a
|
|
468
|
-
* `properties` chain reaches. Comparing the
|
|
468
|
+
* `properties` chain reaches. Comparing the answers is how
|
|
469
469
|
* {@link buildHeaderParameters} decides reachability without a second walk that would have
|
|
470
470
|
* to re-state which JSON Schema keywords are traversable: an annotation the reachable walk
|
|
471
471
|
* did not read is one sitting under `items`, a composition or conditional keyword, a `$ref`
|
|
@@ -492,7 +492,7 @@ export declare function countHeaderAnnotations(value: unknown): number;
|
|
|
492
492
|
* existing shape.
|
|
493
493
|
*
|
|
494
494
|
* @remarks
|
|
495
|
-
* Hand the
|
|
495
|
+
* Hand the result to `createMCPClient({ transport })`, then pass the same
|
|
496
496
|
* `transport` to {@link import('./helpers.js').bindClient} to complete the inbound
|
|
497
497
|
* wiring: `send` serializes each outbound {@link JSONRPCMessage} and writes it through
|
|
498
498
|
* `transport.send`; `close` closes the underlying
|
|
@@ -500,10 +500,10 @@ export declare function countHeaderAnnotations(value: unknown): number;
|
|
|
500
500
|
* it is handed in — there is no separate connect step at this layer); `session` is
|
|
501
501
|
* always `undefined` (session correlation is a higher-level concern the duplex port
|
|
502
502
|
* does not carry); and `duplex` is always `true`, because carrying frames in both
|
|
503
|
-
* directions at any moment is exactly what the adapted port is — a claim
|
|
503
|
+
* directions at any moment is exactly what the adapted port is — a claim driven over a real
|
|
504
504
|
* `MessageChannel` and a real scope pair (a client-initiated `notifications/cancelled`
|
|
505
505
|
* observed arriving at the peer) rather than read back off this literal. The literal is
|
|
506
|
-
* true of the
|
|
506
|
+
* true of the port, and stays true only while the port has a peer: close the far half and
|
|
507
507
|
* this transport still declares `true` while carrying nothing, which is the one thing a
|
|
508
508
|
* per-carrier declaration cannot express. Inbound delivery (`emitter`'s `message` / `close` events) is
|
|
509
509
|
* `bindClient`'s job, not this factory's — the returned object exposes a `message`-
|
|
@@ -522,14 +522,14 @@ export declare function countHeaderAnnotations(value: unknown): number;
|
|
|
522
522
|
export declare function createDuplexClientTransport(transport: MCPTransportInterface): MCPMessageTransportInterface;
|
|
523
523
|
|
|
524
524
|
/**
|
|
525
|
-
* Creates a transport-agnostic Model Context Protocol
|
|
525
|
+
* Creates a transport-agnostic Model Context Protocol client — connects to a remote
|
|
526
526
|
* MCP server over an injected {@link import('./types.js').MCPMessageTransportInterface},
|
|
527
527
|
* negotiates the modern revision through `server/discover`, and exposes the server's tools as local
|
|
528
528
|
* {@link import('@orkestrel/tool').ToolInterface}s an agent can run.
|
|
529
529
|
*
|
|
530
530
|
* @remarks
|
|
531
531
|
* The egress mirror of {@link createMCPServer}: where the server exposes a local tool
|
|
532
|
-
* registry over MCP, the client
|
|
532
|
+
* registry over MCP, the client uses a remote server's tools. `connect()` discovers,
|
|
533
533
|
* validates, and exposes the negotiated modern protocol; a legacy peer requires
|
|
534
534
|
* {@link createMCPLegacyClientTransport}. `tools()` lists + wraps the remote
|
|
535
535
|
* tools (each `execute` calls back over the wire),
|
|
@@ -539,7 +539,7 @@ export declare function createDuplexClientTransport(transport: MCPTransportInter
|
|
|
539
539
|
* `fetch`) lives in the published server environment; the client itself is provider-agnostic. Subscribe
|
|
540
540
|
* to `connect` / `disconnect` / `notification` through `client.emitter.on(...)`.
|
|
541
541
|
*
|
|
542
|
-
* @param options - `transport` (the carrier;
|
|
542
|
+
* @param options - `transport` (the carrier; required), an optional `identity`
|
|
543
543
|
* (the client identity), `timeout` (the per-request deadline), and the reserved `on`
|
|
544
544
|
* {@link import('@orkestrel/emitter').EmitterHooks} (see {@link MCPClientOptions})
|
|
545
545
|
* @returns A working {@link MCPClientInterface}
|
|
@@ -562,6 +562,10 @@ export declare function createMCPClient(options: MCPClientOptions): MCPClientInt
|
|
|
562
562
|
/**
|
|
563
563
|
* Decorates one MCP server with the fixed legacy method translation.
|
|
564
564
|
*
|
|
565
|
+
* @remarks
|
|
566
|
+
* Adds support for the `2025-11-25` and `2025-06-18` legacy revisions. Removing this one
|
|
567
|
+
* decorator removes that legacy surface while leaving the modern dispatcher unchanged.
|
|
568
|
+
*
|
|
565
569
|
* @param server - The sole modern dispatcher and handshake identity source
|
|
566
570
|
* @returns A dispatcher accepting both modern and legacy invocations
|
|
567
571
|
*/
|
|
@@ -608,20 +612,35 @@ export declare function createMCPLegacyClientTransport(transport: MCPMessageTran
|
|
|
608
612
|
* {@link import('@orkestrel/emitter').EmitterHooks} (see {@link MCPServerOptions})
|
|
609
613
|
* @returns A working {@link MCPServerInterface}
|
|
610
614
|
*
|
|
611
|
-
* @example
|
|
615
|
+
* @example Expose a tool registry over MCP
|
|
612
616
|
* ```ts
|
|
613
617
|
* import { createMCPServer } from '@orkestrel/mcp'
|
|
614
618
|
* import { createTool, createToolManager } from '@orkestrel/tool'
|
|
615
619
|
*
|
|
616
620
|
* const tools = createToolManager()
|
|
621
|
+
* tools.add(
|
|
622
|
+
* createTool({
|
|
623
|
+
* name: 'search',
|
|
624
|
+
* description: 'Search the docs',
|
|
625
|
+
* execute: (a) => find(String(a.query)),
|
|
626
|
+
* }),
|
|
627
|
+
* )
|
|
617
628
|
* tools.add(createTool({ name: 'add', execute: (a) => Number(a.x) + Number(a.y) }))
|
|
618
629
|
*
|
|
619
|
-
* const server = createMCPServer({ identity: { name: '
|
|
630
|
+
* const server = createMCPServer({ identity: { name: 'docs', version: '1.0.0' }, tools })
|
|
620
631
|
* server.emitter.on('request', (method, id) => log(method, id))
|
|
621
632
|
*
|
|
622
|
-
* // A transport
|
|
623
|
-
* const
|
|
624
|
-
*
|
|
633
|
+
* // A transport reads a framed message string and writes the reply:
|
|
634
|
+
* for await (const message of transport) {
|
|
635
|
+
* const reply = await server.handle(message)
|
|
636
|
+
* if (reply !== undefined) await transport.send(reply) // a notification has no reply
|
|
637
|
+
* }
|
|
638
|
+
*
|
|
639
|
+
* // `handle` also answers one message string on its own:
|
|
640
|
+
* const listed = await server.handle(
|
|
641
|
+
* '{"jsonrpc":"2.0","method":"tools/list","id":1,"params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}',
|
|
642
|
+
* )
|
|
643
|
+
* // listed → '{"jsonrpc":"2.0","id":1,"result":{"tools":[{"name":"search","inputSchema":{"type":"object"},"description":"Search the docs"},{"name":"add","inputSchema":{"type":"object"}}],"resultType":"complete","ttlMs":60000,"cacheScope":"private","_meta":{"io.modelcontextprotocol/serverInfo":{"name":"docs","version":"1.0.0"}}}}'
|
|
625
644
|
* ```
|
|
626
645
|
*/
|
|
627
646
|
export declare function createMCPServer(options: MCPServerOptions): MCPServerInterface;
|
|
@@ -631,7 +650,7 @@ export declare function createMCPServer(options: MCPServerOptions): MCPServerInt
|
|
|
631
650
|
* before it hands the string on.
|
|
632
651
|
*
|
|
633
652
|
* @remarks
|
|
634
|
-
* The bound is checked
|
|
653
|
+
* The bound is checked first, against the raw string, so an oversized message is never
|
|
635
654
|
* parsed at all: a decoder that parses before it measures has already spent the work
|
|
636
655
|
* the bound exists to refuse. A message over the bound, malformed JSON, and a well-formed
|
|
637
656
|
* value that is not a JSON-RPC message are one answer — `undefined` — because a binder does
|
|
@@ -686,7 +705,7 @@ export declare function decodeEvent(data: string): JSONRPCMessage | undefined;
|
|
|
686
705
|
* second spelling of a byte, so it is refused: `=?base64?QR==?=` reaches for the byte
|
|
687
706
|
* `=?base64?QQ==?=` spells canonically, and only the canonical spelling decodes. A malformed
|
|
688
707
|
* payload answers `undefined` rather than falling back to the literal, because the protocol
|
|
689
|
-
* requires a server to
|
|
708
|
+
* requires a server to reject invalid characters, and a fallback would admit the very value
|
|
690
709
|
* the rule exists to refuse. A value missing either marker is a literal and comes back
|
|
691
710
|
* unchanged.
|
|
692
711
|
*
|
|
@@ -779,12 +798,12 @@ export declare const DEFAULT_MCP_SUBSCRIPTION_CAPACITY = 64;
|
|
|
779
798
|
* Decodes one inbound frame and delivers it onto a transport emitter as `message` or `error`.
|
|
780
799
|
*
|
|
781
800
|
* @remarks
|
|
782
|
-
* The
|
|
801
|
+
* The one inbound fold every message-carrying transport in this package runs: parse the frame,
|
|
783
802
|
* narrow it with `parseJSONRPCMessage`, emit `message` for a well-formed
|
|
784
803
|
* {@link JSONRPCMessage}, and emit `error` for anything else. Total — an adversarial frame
|
|
785
804
|
* produces an `error` emission and never a throw.
|
|
786
805
|
*
|
|
787
|
-
* The
|
|
806
|
+
* The failures report differently on purpose. Unparsable text emits the caught parse
|
|
788
807
|
* error, which names the offending position; well-formed JSON that is not a JSON-RPC message
|
|
789
808
|
* has no caught value to report, so it emits `fault` — the carrier's own wording, passed in
|
|
790
809
|
* rather than forked into a second copy of this body.
|
|
@@ -813,7 +832,7 @@ export declare function digestJSON(value: unknown, limits: MCPJSONLimitOptions):
|
|
|
813
832
|
* Holds the one empty argument record every argument-less modern `tools/call` runs with.
|
|
814
833
|
*
|
|
815
834
|
* @remarks
|
|
816
|
-
* Frozen and null-prototype, and
|
|
835
|
+
* Frozen and null-prototype, and shared: two calls that name no `arguments` receive the same
|
|
817
836
|
* reference, so nothing a tool writes into its own `arguments` can survive into the next
|
|
818
837
|
* call — the write fails instead. That failure is a tool-domain failure like any other: the
|
|
819
838
|
* registry isolates it into a `success: false` result, which reaches the peer as an
|
|
@@ -830,7 +849,7 @@ export declare const EMPTY_MCP_ARGUMENTS: Readonly<Record<string, unknown>>;
|
|
|
830
849
|
*
|
|
831
850
|
* @remarks
|
|
832
851
|
* The exact inverse of {@link decodeSentinel}, and its membership rule is stated as that
|
|
833
|
-
* inverse rather than as a second list that could drift: a value travels
|
|
852
|
+
* inverse rather than as a second list that could drift: a value travels literally when it is
|
|
834
853
|
* plain printable ASCII — every code point in `U+0020`–`U+007E`, the RFC 9110 field-value
|
|
835
854
|
* range this package admits — and {@link decodeSentinel} gives it back unchanged. Every other
|
|
836
855
|
* value travels wrapped in {@link MCP_SENTINEL_PREFIX} and {@link MCP_SENTINEL_SUFFIX}, the
|
|
@@ -867,9 +886,9 @@ export declare function encodeSentinel(value: string): string;
|
|
|
867
886
|
* Concatenates an MCP tool-call result's text content blocks into one string.
|
|
868
887
|
*
|
|
869
888
|
* @remarks
|
|
870
|
-
* The inverse of a server splitting a value into text block(s), and
|
|
889
|
+
* The inverse of a server splitting a value into text block(s), and total: a non-record
|
|
871
890
|
* result, a non-array `content`, or a non-string `text` contributes nothing rather than
|
|
872
|
-
* throwing. What it returns is a
|
|
891
|
+
* throwing. What it returns is a rendering — the prose a model reads — and not the tool's
|
|
873
892
|
* value, which travels as `structuredContent` whenever the peer sent one.
|
|
874
893
|
*
|
|
875
894
|
* @param result - The unknown result payload to read content blocks from
|
|
@@ -890,12 +909,12 @@ export declare function extractContentText(result: unknown): string;
|
|
|
890
909
|
* Reachability is the protocol's own rule: an annotation counts only where a chain of
|
|
891
910
|
* `properties` keys leads to it from the `inputSchema` root, so `path` is both the schema
|
|
892
911
|
* position and the position the call's `arguments` carry the value at. A property named
|
|
893
|
-
* `items` is reachable like any other, because the chain is read by key
|
|
912
|
+
* `items` is reachable like any other, because the chain is read by key position rather than
|
|
894
913
|
* by key name.
|
|
895
914
|
*
|
|
896
915
|
* `undefined` means the definition is invalid rather than empty: a reachable annotation whose
|
|
897
916
|
* value is not an {@link import('./validators.js').isFieldToken} token, one sitting on the
|
|
898
|
-
* schema
|
|
917
|
+
* schema root (which is no property), one on a leaf whose declared type is not an
|
|
899
918
|
* {@link import('./validators.js').isMCPHeaderPrimitive} primitive, or a chain deeper than
|
|
900
919
|
* `DEFAULT_MCP_LIMITS.depth` — which is also what makes a self-referential schema terminate.
|
|
901
920
|
* A node that is not a record carries nothing and answers an empty list, because a leaf the
|
|
@@ -934,7 +953,7 @@ export declare function extractHeaderAnnotations(schema: unknown, path: readonly
|
|
|
934
953
|
export declare function extractToolSchema(response: unknown, name: string): Readonly<Record<string, unknown>> | undefined;
|
|
935
954
|
|
|
936
955
|
/**
|
|
937
|
-
* Drives a
|
|
956
|
+
* Drives a remote Streamable-HTTP MCP server over `fetch` — a client
|
|
938
957
|
* {@link MCPMessageTransportInterface} for the Model Context Protocol, the egress mirror of
|
|
939
958
|
* the server's `createMCPRoutes`.
|
|
940
959
|
*
|
|
@@ -946,7 +965,7 @@ export declare function extractToolSchema(response: unknown, name: string): Read
|
|
|
946
965
|
* class, so a reply reaches a page and a Node process through the same decode.
|
|
947
966
|
* - **Request/response over `fetch`.** `send(message)` POSTs the JSON-serialized
|
|
948
967
|
* message to `options.url` with `content-type: application/json` and an
|
|
949
|
-
* `Accept` of
|
|
968
|
+
* `Accept` of both `application/json` and `text/event-stream` (so the server may
|
|
950
969
|
* answer with either framing) — plus any `options.headers` (for example, an `Authorization`
|
|
951
970
|
* bearer). It then decodes the reply and emits each decoded {@link JSONRPCMessage} on
|
|
952
971
|
* the `message` event the {@link import('@orkestrel/mcp').MCPClientInterface} subscribes
|
|
@@ -959,12 +978,12 @@ export declare function extractToolSchema(response: unknown, name: string): Read
|
|
|
959
978
|
* Accepted (a notification) carries no body and emits nothing.
|
|
960
979
|
* - **Session and protocol headers.** `start()` is a no-op (a
|
|
961
980
|
* request/response transport opens no long-lived connection). The
|
|
962
|
-
* `mcp-session-id` response header, when a
|
|
963
|
-
* `initialize`), is captured into `session` and then
|
|
964
|
-
* `mcp-session-id` request header on every
|
|
981
|
+
* `mcp-session-id` response header, when a stateful server sends one (on
|
|
982
|
+
* `initialize`), is captured into `session` and then echoed as the
|
|
983
|
+
* `mcp-session-id` request header on every subsequent request — so an
|
|
965
984
|
* `MCPClient` passes a stateful server's session validation. The
|
|
966
985
|
* initialize result's `protocolVersion` is likewise captured, but only
|
|
967
|
-
* when it is a
|
|
986
|
+
* when it is a supported value, and echoed as `mcp-protocol-version` alone on
|
|
968
987
|
* subsequent legacy requests. Modern requests instead derive protocol and method
|
|
969
988
|
* headers from the message, plus the name header only for `tools/call` — carried in the
|
|
970
989
|
* protocol's Base64 sentinel form whenever the tool name cannot ride as plain ASCII.
|
|
@@ -972,11 +991,11 @@ export declare function extractToolSchema(response: unknown, name: string): Read
|
|
|
972
991
|
* `close()` clears the captured protocol so a reconnect's `initialize`
|
|
973
992
|
* POST is headerless; the captured `session` persists across `close()`.
|
|
974
993
|
* - **`close()` releases what is in flight.** Every `fetch` this transport still has open is
|
|
975
|
-
*
|
|
994
|
+
* aborted, which cancels the response body a `send` is reading — an SSE reply the server
|
|
976
995
|
* never ends would otherwise outlive the transport, with nothing left able to reach it. The
|
|
977
996
|
* aborted read surfaces on `error` and the `send` reporting it resolves. `close()` is
|
|
978
997
|
* idempotent (one `close` event per connected lifetime), and `start()` opens the next one.
|
|
979
|
-
* - **Total at the boundary, and a non-success reply
|
|
998
|
+
* - **Total at the boundary, and a non-success reply rejects.** Every reply is narrowed
|
|
980
999
|
* (`parseJSONRPCMessage`, the SSE decoder). A non-message success reply is dropped, never
|
|
981
1000
|
* asserted. A non-success reply that carries no valid JSON-RPC message rejects `send` with
|
|
982
1001
|
* an error naming its HTTP status and body shape — the peer answered, and answering the
|
|
@@ -1012,7 +1031,7 @@ export declare class HTTPClientTransport implements MCPMessageTransportInterface
|
|
|
1012
1031
|
* @remarks
|
|
1013
1032
|
* - `url` — the absolute URL of the remote server's Streamable-HTTP endpoint (the
|
|
1014
1033
|
* `POST` target every JSON-RPC message is written to, for example,
|
|
1015
|
-
* `http://localhost:3000/mcp`).
|
|
1034
|
+
* `http://localhost:3000/mcp`). Required.
|
|
1016
1035
|
* - `headers` — extra request headers merged onto every `POST` (for example, an
|
|
1017
1036
|
* `Authorization` bearer for a guarded server). The transport always sets
|
|
1018
1037
|
* `content-type: application/json` and an `Accept` of both `application/json` and
|
|
@@ -1038,9 +1057,9 @@ export declare interface HTTPClientTransportOptions {
|
|
|
1038
1057
|
* Infers the wire era for an MCP protocol revision.
|
|
1039
1058
|
*
|
|
1040
1059
|
* @remarks
|
|
1041
|
-
* The era is
|
|
1060
|
+
* The era is read from the era guards rather than restated here, so a revision added
|
|
1042
1061
|
* to {@link SUPPORTED_MODERN_PROTOCOL_VERSIONS} or {@link SUPPORTED_LEGACY_PROTOCOL_VERSIONS}
|
|
1043
|
-
* carries its era with it and no
|
|
1062
|
+
* carries its era with it and no further list can disagree with them.
|
|
1044
1063
|
*
|
|
1045
1064
|
* @param version - The protocol revision to classify
|
|
1046
1065
|
* @returns `'modern'` for a revision a bare server accepts, `'legacy'` for a revision the
|
|
@@ -1052,10 +1071,10 @@ export declare function inferEra(version: string): MCPEra | undefined;
|
|
|
1052
1071
|
* Infers the wire era one invocation's own structure selects.
|
|
1053
1072
|
*
|
|
1054
1073
|
* @remarks
|
|
1055
|
-
* The
|
|
1074
|
+
* The structural read, distinct from {@link inferEra}'s read of a revision string: era is fixed
|
|
1056
1075
|
* by the reserved modern metadata a request carries, so this answers for a message whose
|
|
1057
1076
|
* revision has not been read and cannot answer `undefined` — every invocation took one of the
|
|
1058
|
-
*
|
|
1077
|
+
* published wire shapes. It is what an observation surface reports and what an ingress
|
|
1059
1078
|
* routes on, so both derive it here rather than each spelling the ternary out.
|
|
1060
1079
|
*
|
|
1061
1080
|
* @param invocation - The invocation whose structure selects the era
|
|
@@ -1069,15 +1088,15 @@ export declare function inferEra(version: string): MCPEra | undefined;
|
|
|
1069
1088
|
export declare function inferRequestEra(invocation: JSONRPCInvocation): MCPEra;
|
|
1070
1089
|
|
|
1071
1090
|
/**
|
|
1072
|
-
* Infers the protocol version an outbound message announces itself with — the
|
|
1091
|
+
* Infers the protocol version an outbound message announces itself with — the one
|
|
1073
1092
|
* projection every HTTP client transport stamps `mcp-protocol-version` from.
|
|
1074
1093
|
*
|
|
1075
1094
|
* @remarks
|
|
1076
|
-
* This is deliberately the
|
|
1095
|
+
* This is deliberately the same read the server's own expectation performs
|
|
1077
1096
|
* ({@link import('@orkestrel/mcp/server').inferHeaderIssue}): a modern request's reserved
|
|
1078
|
-
* `_meta` version, accepted whenever it is a string. It is
|
|
1097
|
+
* `_meta` version, accepted whenever it is a string. It is not
|
|
1079
1098
|
* {@link import('./parsers.js').parseRequestContext}, and the difference is the whole
|
|
1080
|
-
* point. That parser answers a different question — is the modern metadata
|
|
1099
|
+
* point. That parser answers a different question — is the modern metadata well formed —
|
|
1081
1100
|
* and refuses a request whose capability declaration or logging level is malformed. Such a
|
|
1082
1101
|
* request is still modern (era is fixed by key presence) and the server still demands the
|
|
1083
1102
|
* header for it, so projecting through the parser withholds a header the peer requires and
|
|
@@ -1086,7 +1105,7 @@ export declare function inferRequestEra(invocation: JSONRPCInvocation): MCPEra;
|
|
|
1086
1105
|
* A non-modern message projects nothing: a legacy request's version comes from the
|
|
1087
1106
|
* `initialize` handshake the transport captured, not from the message.
|
|
1088
1107
|
*
|
|
1089
|
-
* Header
|
|
1108
|
+
* Header names stay with the transports that own the wire (see `constants.ts`); core owns
|
|
1090
1109
|
* the value this projection derives, which is the part the browser and Node faces disagreed about.
|
|
1091
1110
|
*
|
|
1092
1111
|
* @param message - The outbound message about to be written
|
|
@@ -1157,13 +1176,13 @@ export declare function isBoundedString(value: unknown, bytes: number): value is
|
|
|
1157
1176
|
* Determines whether accepted elicitation content satisfies the exact schema that was issued.
|
|
1158
1177
|
*
|
|
1159
1178
|
* @remarks
|
|
1160
|
-
* {@link isMCPElicitResult} says a response has the
|
|
1161
|
-
* response answers the
|
|
1179
|
+
* {@link isMCPElicitResult} says a response has the shape of a response; this says the
|
|
1180
|
+
* response answers the question that was asked. A server that protects the schema it issued
|
|
1162
1181
|
* and then never enforces it has bought nothing, so this guard closes that gap: it is what
|
|
1163
1182
|
* turns a bound schema into a checked one.
|
|
1164
1183
|
*
|
|
1165
1184
|
* Every own value must be one {@link MCPElicitValue} — a string, a finite number, a boolean,
|
|
1166
|
-
* or an array of strings. A value whose name is
|
|
1185
|
+
* or an array of strings. A value whose name is declared in `schema.properties` must in
|
|
1167
1186
|
* addition satisfy that field's schema: `integer` rejects a fraction, `minimum` / `maximum`
|
|
1168
1187
|
* bound a number, `minLength` / `maxLength` bound a string by code points, `enum` and `oneOf`
|
|
1169
1188
|
* bound it to a declared member, `format` is enforced (`uri` by {@link isAbsoluteURI}, `email`
|
|
@@ -1172,9 +1191,9 @@ export declare function isBoundedString(value: unknown, bytes: number): value is
|
|
|
1172
1191
|
* `maxItems` with every entry drawn from its `items.enum` or `items.anyOf`. Every name listed
|
|
1173
1192
|
* in `schema.required` must be present.
|
|
1174
1193
|
*
|
|
1175
|
-
* An
|
|
1194
|
+
* An undeclared property remains valid: the restricted schema is open by default, so a client
|
|
1176
1195
|
* that answers more than it was asked is not refused for it. A `schema` that is not itself a
|
|
1177
|
-
* valid {@link MCPElicitSchema} admits
|
|
1196
|
+
* valid {@link MCPElicitSchema} admits nothing — an unenforceable schema is never a permissive
|
|
1178
1197
|
* one — which is why `schema` is accepted as `unknown` and checked rather than trusted. Total
|
|
1179
1198
|
* over hostile content and hostile schemas alike.
|
|
1180
1199
|
*
|
|
@@ -1238,17 +1257,17 @@ export declare function isJSONObject(value: unknown): value is Readonly<Record<s
|
|
|
1238
1257
|
* Determines whether a value is one JSON-RPC `error` member.
|
|
1239
1258
|
*
|
|
1240
1259
|
* @remarks
|
|
1241
|
-
* The failure
|
|
1260
|
+
* The failure object, not the envelope carrying it — the shape a failed response owns
|
|
1242
1261
|
* under `error`, and the shape a `failed` {@link MCPTaskDetail} owns under the same name,
|
|
1243
1262
|
* which is why it is one guard rather than the same checks written twice.
|
|
1244
1263
|
*
|
|
1245
|
-
* It is deliberately
|
|
1264
|
+
* It is deliberately structural rather than exact-JSON: `data` is declared `unknown`, so
|
|
1246
1265
|
* requiring the whole object to survive a JSON clone would refuse a legal error that
|
|
1247
1266
|
* carried a non-JSON payload. Both callers here hand it an already-owned value.
|
|
1248
1267
|
*
|
|
1249
1268
|
* That choice is why the key reads are guarded. Every sibling guard clones first, and a
|
|
1250
1269
|
* clone reads each key once behind a boundary that already owns totality; this one is the
|
|
1251
|
-
* family's only
|
|
1270
|
+
* family's only direct reader, so it meets `code` and `message` exactly as the value defines
|
|
1252
1271
|
* them — including as accessors that throw. Reading a named key off an unowned value is
|
|
1253
1272
|
* itself the hostile step, and it is bounded here rather than allowed to escape. Total.
|
|
1254
1273
|
*
|
|
@@ -1268,9 +1287,9 @@ export declare function isJSONRPCError(value: unknown): value is JSONRPCError;
|
|
|
1268
1287
|
* arm of a response.
|
|
1269
1288
|
*
|
|
1270
1289
|
* @remarks
|
|
1271
|
-
* `id` is
|
|
1272
|
-
* request's id
|
|
1273
|
-
* valid and a `null` one is not. The envelope must own an `error` and must
|
|
1290
|
+
* `id` is optional here and only here: a peer that could not read the failed
|
|
1291
|
+
* request's id omits the member rather than sending `null`, so an absent `id` is
|
|
1292
|
+
* valid and a `null` one is not. The envelope must own an `error` and must not own a
|
|
1274
1293
|
* `result`. `error` carries an integer `code` and a string `message`. Total.
|
|
1275
1294
|
*
|
|
1276
1295
|
* @param value - The already-parsed value to test
|
|
@@ -1338,7 +1357,7 @@ export declare function isJSONRPCMessage(value: unknown): value is JSONRPCMessag
|
|
|
1338
1357
|
* Determines whether a parsed value is a {@link JSONRPCNotification}.
|
|
1339
1358
|
*
|
|
1340
1359
|
* @remarks
|
|
1341
|
-
* A notification is a request-shaped call carrying
|
|
1360
|
+
* A notification is a request-shaped call carrying no `id` member — the protocol
|
|
1342
1361
|
* forbids one, because nothing answers a notification. `params`, when present, must
|
|
1343
1362
|
* be a record. Total: any other input returns `false`.
|
|
1344
1363
|
*
|
|
@@ -1358,7 +1377,7 @@ export declare function isJSONRPCNotification(value: unknown): value is JSONRPCN
|
|
|
1358
1377
|
*
|
|
1359
1378
|
* @remarks
|
|
1360
1379
|
* A request is a record with `jsonrpc === '2.0'`, a string `method`, and an `id`
|
|
1361
|
-
* that {@link isJSONRPCId} accepts. An id-less call is
|
|
1380
|
+
* that {@link isJSONRPCId} accepts. An id-less call is not a request — it is a
|
|
1362
1381
|
* {@link JSONRPCNotification}, which {@link isJSONRPCNotification} answers for. The
|
|
1363
1382
|
* guards are mutually exclusive on every input: this one requires a valid `id`
|
|
1364
1383
|
* value, that one requires no own `id` member at all. `params`, when present, must
|
|
@@ -1392,8 +1411,8 @@ export declare function isJSONRPCResponse(value: unknown): value is JSONRPCRespo
|
|
|
1392
1411
|
* arm of a response.
|
|
1393
1412
|
*
|
|
1394
1413
|
* @remarks
|
|
1395
|
-
* A result answers a request, so `id` is
|
|
1396
|
-
* {@link isJSONRPCId}. The envelope must own a `result` and must
|
|
1414
|
+
* A result answers a request, so `id` is required and must be a valid
|
|
1415
|
+
* {@link isJSONRPCId}. The envelope must own a `result` and must not own an `error`,
|
|
1397
1416
|
* which is what makes this guard and {@link isJSONRPCErrorResponse} mutually
|
|
1398
1417
|
* exclusive on every input. `result` itself must be an object: either a modern
|
|
1399
1418
|
* {@link isMCPResult} or a legacy {@link isMCPLegacyResult}, never a bare primitive.
|
|
@@ -1644,12 +1663,12 @@ export declare function isMCPInputRequestMap(value: unknown): value is MCPInputR
|
|
|
1644
1663
|
* Determines whether a response answers the exact embedded request that was issued.
|
|
1645
1664
|
*
|
|
1646
1665
|
* @remarks
|
|
1647
|
-
* A response carries no `method` of its own, so the
|
|
1666
|
+
* A response carries no `method` of its own, so the issued request selects which arm applies
|
|
1648
1667
|
* — the same way {@link isElicitContent} takes the issued schema rather than trusting the
|
|
1649
1668
|
* content to describe itself. A form elicitation is checked twice: once for the response
|
|
1650
1669
|
* shape and once, on `accept`, for the content against the schema that round issued. A
|
|
1651
1670
|
* URL-mode elicitation issues no schema, so only the shape is checked. A request this
|
|
1652
|
-
* package cannot recognize admits
|
|
1671
|
+
* package cannot recognize admits nothing, because an unrecognized question has no correct
|
|
1653
1672
|
* answer. Total over hostile responses and hostile requests alike.
|
|
1654
1673
|
*
|
|
1655
1674
|
* @param value - The client's answer to check
|
|
@@ -1731,8 +1750,8 @@ export declare function isMCPModernVersion(value: unknown): value is MCPModernVe
|
|
|
1731
1750
|
* subscription id.
|
|
1732
1751
|
*
|
|
1733
1752
|
* @remarks
|
|
1734
|
-
* The reserved key is
|
|
1735
|
-
* stream passes with no stamp at all. When the key
|
|
1753
|
+
* The reserved key is optional, so a frame delivered outside a `subscriptions/listen`
|
|
1754
|
+
* stream passes with no stamp at all. When the key is present its value must be a valid
|
|
1736
1755
|
* {@link JSONRPCId}, because a stamp naming nothing addressable is worse than no stamp.
|
|
1737
1756
|
*
|
|
1738
1757
|
* @param value - The unknown value to inspect
|
|
@@ -1852,7 +1871,7 @@ export declare function isMCPResourceTemplatePage(value: unknown): value is MCPR
|
|
|
1852
1871
|
*
|
|
1853
1872
|
* @remarks
|
|
1854
1873
|
* The open contract's guard: a record carrying a string `resultType` and, when
|
|
1855
|
-
* present, exact result metadata. It deliberately does
|
|
1874
|
+
* present, exact result metadata. It deliberately does not narrow `resultType` to a
|
|
1856
1875
|
* known value, because the dated schema keeps adding them — a caller that needs a
|
|
1857
1876
|
* specific result uses that result's own guard, which narrows to its literal.
|
|
1858
1877
|
* Mutually exclusive with {@link isMCPLegacyResult} on every input: this one needs
|
|
@@ -1939,10 +1958,11 @@ export declare function isMCPSampleContent(value: unknown): value is MCPSampleCo
|
|
|
1939
1958
|
*
|
|
1940
1959
|
* @remarks
|
|
1941
1960
|
* The schema's `CreateMessageResult` types `content` as an `anyOf` over one
|
|
1942
|
-
* {@link isMCPSampleContent} block or an
|
|
1961
|
+
* {@link isMCPSampleContent} block or an array of them, so both are admitted here: a
|
|
1943
1962
|
* tool-using model answers with `tool_use` and `tool_result` blocks, and a model answering in
|
|
1944
1963
|
* several parts answers with the array. `stopReason` stays an open string because the schema
|
|
1945
|
-
* names
|
|
1964
|
+
* names `endTurn`, `stopSequence`, `maxTokens`, and `toolUse` and permits any other a provider
|
|
1965
|
+
* reports. Total over hostile input.
|
|
1946
1966
|
*
|
|
1947
1967
|
* @param value - The unknown value to inspect
|
|
1948
1968
|
* @returns True if `value` has the sampling-completion shape; false otherwise
|
|
@@ -2010,7 +2030,7 @@ export declare function isMCPSubscriptionResult(value: unknown): value is MCPSub
|
|
|
2010
2030
|
* the requests to answer, `completed` owns the deferred call's result, `failed` owns the
|
|
2011
2031
|
* JSON-RPC error that ended it, and `working` / `cancelled` own nothing further.
|
|
2012
2032
|
*
|
|
2013
|
-
* A `completed` task's `result` is checked as an
|
|
2033
|
+
* A `completed` task's `result` is checked as an object and no further. The schema declares
|
|
2014
2034
|
* it an open record, so its contents belong to whichever method was deferred; a guard that
|
|
2015
2035
|
* demanded a protocol result here would refuse payloads the extension permits.
|
|
2016
2036
|
* `ttlMs` and `pollIntervalMs` are integer milliseconds, per the schema's `int` formats.
|
|
@@ -2036,11 +2056,11 @@ export declare function isMCPTaskDetail(value: unknown): value is MCPTaskDetail;
|
|
|
2036
2056
|
* Determines whether a value is the wire answer to `tasks/get`.
|
|
2037
2057
|
*
|
|
2038
2058
|
* @remarks
|
|
2039
|
-
* {@link isMCPTaskDetail} plus the stamp the
|
|
2059
|
+
* {@link isMCPTaskDetail} plus the stamp the method owes. The schema types a `tasks/get`
|
|
2040
2060
|
* reply as the detail intersected with the standard result, so `resultType: 'complete'` is
|
|
2041
2061
|
* part of the answer rather than decoration on it — and an unstamped payload, or one
|
|
2042
2062
|
* carrying the creation answer's `resultType: 'task'`, is a peer answering some other
|
|
2043
|
-
* shape. Use this guard wherever a `tasks/get`
|
|
2063
|
+
* shape. Use this guard wherever a `tasks/get` reply is read; use
|
|
2044
2064
|
* {@link isMCPTaskDetail} wherever a consumer's manager answers directly.
|
|
2045
2065
|
*
|
|
2046
2066
|
* `_meta` is checked only when present, and only as result metadata: the server identity a
|
|
@@ -2063,14 +2083,14 @@ export declare function isMCPTaskDetailResult(value: unknown): value is MCPTaskD
|
|
|
2063
2083
|
* Determines whether a value is a `notifications/tasks` frame carrying a task snapshot.
|
|
2064
2084
|
*
|
|
2065
2085
|
* @remarks
|
|
2066
|
-
* The
|
|
2086
|
+
* The admission guard for a task transition: a subscription producer is consumer-written,
|
|
2067
2087
|
* so the frame it hands over is foreign input, and this is what stands between a mutated
|
|
2068
2088
|
* or half-built snapshot and a subscribed client. Both halves are checked — the method
|
|
2069
2089
|
* literal the extension fixes, and params that hold together as an
|
|
2070
2090
|
* {@link MCPTaskDetail} — because either alone admits a frame the other rejects.
|
|
2071
2091
|
*
|
|
2072
|
-
* `_meta` is checked for
|
|
2073
|
-
* stamp is the
|
|
2092
|
+
* `_meta` is checked for shape when present and nothing more. The reserved subscription
|
|
2093
|
+
* stamp is the server's to write, after this guard admits the frame and the matcher agrees
|
|
2074
2094
|
* to it, so a guard that demanded the stamp would refuse every frame a producer emits.
|
|
2075
2095
|
*
|
|
2076
2096
|
* @param value - The unknown value to inspect
|
|
@@ -2096,7 +2116,7 @@ export declare function isMCPTaskNotification(value: unknown): value is MCPTaskN
|
|
|
2096
2116
|
* proof: this is what stands between a manager that answers a numeric `taskId` and a
|
|
2097
2117
|
* client that would receive one. `ttlMs` accepts `null` because the schema uses it to
|
|
2098
2118
|
* mean "no expiry", which is distinct from an absent field, and both durations must be
|
|
2099
|
-
*
|
|
2119
|
+
* integer milliseconds because the schema formats them `int`.
|
|
2100
2120
|
*
|
|
2101
2121
|
* @param value - The unknown value to inspect
|
|
2102
2122
|
* @returns True if the value is a well-formed `resultType: 'task'` result; false otherwise
|
|
@@ -2158,7 +2178,7 @@ export declare function isModernRequest(value: unknown): value is JSONRPCInvocat
|
|
|
2158
2178
|
* Determines whether a value is one RFC 3339 `full-date` naming a real calendar day.
|
|
2159
2179
|
*
|
|
2160
2180
|
* @remarks
|
|
2161
|
-
* RFC 3339 §5.6 defines `date-mday` as `01-28`, `29`, `30`, or `31`
|
|
2181
|
+
* RFC 3339 §5.6 defines `date-mday` as `01-28`, `29`, `30`, or `31` based on the month and
|
|
2162
2182
|
* year, so the grammar is not satisfied by shape alone: `2026-02-30` and `2025-02-29` are
|
|
2163
2183
|
* well-formed triples that name no day, and a downstream `new Date` rolls each of them
|
|
2164
2184
|
* silently onto a different date rather than refusing it. February's length follows the
|
|
@@ -2166,7 +2186,7 @@ export declare function isModernRequest(value: unknown): value is JSONRPCInvocat
|
|
|
2166
2186
|
*
|
|
2167
2187
|
* The check is pure integer arithmetic on the matched fields and never constructs a `Date`,
|
|
2168
2188
|
* because `Date` is exactly the component that performs the rollover this guard exists to
|
|
2169
|
-
* refuse. It is a
|
|
2189
|
+
* refuse. It is a syntax guard: no time zone, locale, calendar era, or leap second applies.
|
|
2170
2190
|
*
|
|
2171
2191
|
* @param value - The unknown value to inspect
|
|
2172
2192
|
* @returns True if the value is an RFC 3339 `full-date` for a day that exists; false otherwise
|
|
@@ -2217,7 +2237,7 @@ export declare function isStandardBase64(value: unknown): value is string;
|
|
|
2217
2237
|
* valid request.
|
|
2218
2238
|
*
|
|
2219
2239
|
* @remarks
|
|
2220
|
-
* The code every
|
|
2240
|
+
* The code every modern internal fault answers with — a provider, handler, continuation,
|
|
2221
2241
|
* capacity, stream-source, normalization, or serialization failure the server contained.
|
|
2222
2242
|
* It is detail-free on the wire: the caught value reaches the application through the
|
|
2223
2243
|
* server's `error` event and never through the response.
|
|
@@ -2240,7 +2260,7 @@ export declare const JSONRPC_PARSE_ERROR = -32700;
|
|
|
2240
2260
|
* Names the JSON-RPC 2.0 implementation-defined server error (the `-32000` to `-32099` range).
|
|
2241
2261
|
*
|
|
2242
2262
|
* @remarks
|
|
2243
|
-
* Retained for the
|
|
2263
|
+
* Retained for the legacy branch alone. A modern fault answers
|
|
2244
2264
|
* {@link JSONRPC_INTERNAL_ERROR}; this code survives only where an old-wire peer was
|
|
2245
2265
|
* already characterized against it.
|
|
2246
2266
|
*/
|
|
@@ -2252,7 +2272,7 @@ export declare const JSONRPC_SERVER_ERROR = -32000;
|
|
|
2252
2272
|
*
|
|
2253
2273
|
* @remarks
|
|
2254
2274
|
* `code` is one of the reserved JSON-RPC codes (see `./constants.js`); `message`
|
|
2255
|
-
* is a short human description; `data` is an
|
|
2275
|
+
* is a short human description; `data` is an optional machine-readable payload
|
|
2256
2276
|
* carrying extra detail.
|
|
2257
2277
|
*/
|
|
2258
2278
|
export declare interface JSONRPCError {
|
|
@@ -2266,20 +2286,26 @@ export declare interface JSONRPCError {
|
|
|
2266
2286
|
* the {@link JSONRPCError} that ended it.
|
|
2267
2287
|
*
|
|
2268
2288
|
* @remarks
|
|
2269
|
-
* `id` is
|
|
2289
|
+
* `id` is omitted, never `null`, when the request could not be parsed or its id
|
|
2270
2290
|
* read: MCP overrides the base specification here, so a modern peer receives an
|
|
2271
2291
|
* envelope with no `id` member at all. `result` is forbidden.
|
|
2272
2292
|
*/
|
|
2273
2293
|
export declare interface JSONRPCErrorResponse {
|
|
2274
2294
|
readonly jsonrpc: '2.0';
|
|
2275
|
-
/** Holds the failed request's id;
|
|
2295
|
+
/** Holds the failed request's id; absent when no id could be read. */
|
|
2276
2296
|
readonly id?: JSONRPCId;
|
|
2277
2297
|
readonly error: JSONRPCError;
|
|
2278
2298
|
/** Forbids this member; an answer carries a result or an error, never both. */
|
|
2279
2299
|
readonly result?: never;
|
|
2280
2300
|
}
|
|
2281
2301
|
|
|
2282
|
-
/**
|
|
2302
|
+
/**
|
|
2303
|
+
* Represents a JSON-RPC 2.0 correlation id — the value a request and its response share.
|
|
2304
|
+
*
|
|
2305
|
+
* @remarks
|
|
2306
|
+
* `null` is not an id. A response that could not read one omits the member entirely, which is
|
|
2307
|
+
* what {@link JSONRPCErrorResponse} declares.
|
|
2308
|
+
*/
|
|
2283
2309
|
export declare type JSONRPCId = string | number;
|
|
2284
2310
|
|
|
2285
2311
|
/**
|
|
@@ -2321,7 +2347,7 @@ export declare interface JSONRPCNotification {
|
|
|
2321
2347
|
|
|
2322
2348
|
/**
|
|
2323
2349
|
* Represents a JSON-RPC 2.0 request — a `method` call with optional `params`, correlated to
|
|
2324
|
-
* its response by the `id` it
|
|
2350
|
+
* its response by the `id` it requires.
|
|
2325
2351
|
*
|
|
2326
2352
|
* @remarks
|
|
2327
2353
|
* `jsonrpc` is the literal `'2.0'`. A call with no `id` is not a request at all: it
|
|
@@ -2352,7 +2378,7 @@ export declare type JSONRPCResponse = JSONRPCResultResponse | JSONRPCErrorRespon
|
|
|
2352
2378
|
*
|
|
2353
2379
|
* @remarks
|
|
2354
2380
|
* A result answers a request, and a request always has a readable `id`, so `id` is
|
|
2355
|
-
*
|
|
2381
|
+
* required here. `result` is an {@link MCPResult} on the modern wire and an
|
|
2356
2382
|
* {@link MCPLegacyResult} on the legacy one; `error` is forbidden.
|
|
2357
2383
|
*/
|
|
2358
2384
|
export declare interface JSONRPCResultResponse {
|
|
@@ -2389,7 +2415,7 @@ export declare function legacyResultToModern(result: MCPLegacyResult, method: st
|
|
|
2389
2415
|
* Determines whether one method may answer with a given modern `resultType`.
|
|
2390
2416
|
*
|
|
2391
2417
|
* @remarks
|
|
2392
|
-
* The dated protocol lets a `tools/call` answer in more than one way — it
|
|
2418
|
+
* The dated protocol lets a `tools/call` answer in more than one way — it completed, it became a
|
|
2393
2419
|
* durable task, or it needs another round trip — while every other method this client
|
|
2394
2420
|
* issues has exactly one legal answer. So the arm a peer chose is only meaningful beside
|
|
2395
2421
|
* the method it answers, and this is the one place that pairing is decided.
|
|
@@ -2424,19 +2450,23 @@ export declare function matchesSubscriptionNotification(notification: JSONRPCNot
|
|
|
2424
2450
|
* Names the reserved extension key identifying the stable Tasks extension.
|
|
2425
2451
|
*
|
|
2426
2452
|
* @remarks
|
|
2427
|
-
* The
|
|
2428
|
-
* 2026-07-28 this package implements. A client declares it per
|
|
2453
|
+
* The one spelling of it in this package, and the identity of the immutable snapshot dated
|
|
2454
|
+
* 2026-07-28 this package implements. A client declares it per request, under
|
|
2429
2455
|
* `_meta['io.modelcontextprotocol/clientCapabilities'].extensions`; a server advertises it
|
|
2430
2456
|
* under `server/discover`'s `capabilities.extensions`. Both sides carry an empty object —
|
|
2431
2457
|
* the extension defines no options, so presence is the entire declaration.
|
|
2432
2458
|
*/
|
|
2433
2459
|
export declare const MCP_EXTENSION_TASKS = "io.modelcontextprotocol/tasks";
|
|
2434
2460
|
|
|
2435
|
-
/**
|
|
2461
|
+
/**
|
|
2462
|
+
* Names the older legacy revision the optional legacy decorator accepts and an adapter can pin,
|
|
2463
|
+
* `'2025-06-18'`.
|
|
2464
|
+
*/
|
|
2436
2465
|
export declare const MCP_FALLBACK_VERSION: MCPLegacyVersion;
|
|
2437
2466
|
|
|
2438
2467
|
/**
|
|
2439
|
-
* Names the revision offered and defaulted to in the legacy `initialize` handshake
|
|
2468
|
+
* Names the revision offered and defaulted to in the legacy `initialize` handshake,
|
|
2469
|
+
* `'2025-11-25'`.
|
|
2440
2470
|
*
|
|
2441
2471
|
* @remarks
|
|
2442
2472
|
* This is deliberately a legacy revision, and the newest one supported. 2026-07-28 is stateless
|
|
@@ -2449,7 +2479,7 @@ export declare const MCP_HANDSHAKE_VERSION: MCPLegacyVersion;
|
|
|
2449
2479
|
* Identifies the tool-schema annotation key naming the header one parameter projects into.
|
|
2450
2480
|
*
|
|
2451
2481
|
* @remarks
|
|
2452
|
-
* It is valid
|
|
2482
|
+
* It is valid only on a primitive property schema statically reachable from the `inputSchema`
|
|
2453
2483
|
* root through `properties` keys alone. An occurrence anywhere else — under `items`, a
|
|
2454
2484
|
* composition or conditional keyword, or a `$ref` target — makes the whole tool definition
|
|
2455
2485
|
* invalid, which is what {@link import('@orkestrel/mcp').buildHeaderParameters} decides.
|
|
@@ -2503,7 +2533,7 @@ export declare const MCP_METHOD_HEADER = "mcp-method";
|
|
|
2503
2533
|
* declared.
|
|
2504
2534
|
*
|
|
2505
2535
|
* @remarks
|
|
2506
|
-
* The
|
|
2536
|
+
* The generic code for the whole condition, not one capability's code. This server answers
|
|
2507
2537
|
* it in more than one place — a `tools/call` that needs `elicitation`, and a `tasks/*` request
|
|
2508
2538
|
* whose client never declared `io.modelcontextprotocol/tasks` — and they are told apart by
|
|
2509
2539
|
* `error.data.requiredCapabilities` alone (`{ elicitation: {} }` against
|
|
@@ -2514,7 +2544,7 @@ export declare const MCP_METHOD_HEADER = "mcp-method";
|
|
|
2514
2544
|
*/
|
|
2515
2545
|
export declare const MCP_MISSING_CAPABILITY = -32021;
|
|
2516
2546
|
|
|
2517
|
-
/** Names the modern revision offered by an unpinned client during discovery
|
|
2547
|
+
/** Names the modern revision offered by an unpinned client during discovery, `'2026-07-28'`. */
|
|
2518
2548
|
export declare const MCP_MODERN_VERSION: MCPModernVersion;
|
|
2519
2549
|
|
|
2520
2550
|
/**
|
|
@@ -2550,10 +2580,10 @@ export declare const MCP_PROTOCOL_VERSION_HEADER = "mcp-protocol-version";
|
|
|
2550
2580
|
* Names the opening marker of the Base64 sentinel a standard MCP header value travels in.
|
|
2551
2581
|
*
|
|
2552
2582
|
* @remarks
|
|
2553
|
-
* The markers are
|
|
2554
|
-
* their
|
|
2583
|
+
* The markers are lowercase and exact, and this constant with {@link MCP_SENTINEL_SUFFIX} is
|
|
2584
|
+
* their one spelling in this package: {@link import('@orkestrel/mcp').encodeSentinel} builds a
|
|
2555
2585
|
* sentinel from them and {@link import('@orkestrel/mcp').decodeSentinel} recognizes one by
|
|
2556
|
-
* them, so the
|
|
2586
|
+
* them, so the directions cannot drift apart.
|
|
2557
2587
|
*/
|
|
2558
2588
|
export declare const MCP_SENTINEL_PREFIX = "=?base64?";
|
|
2559
2589
|
|
|
@@ -2564,7 +2594,7 @@ export declare const MCP_SENTINEL_SUFFIX = "?=";
|
|
|
2564
2594
|
* Names the Streamable-HTTP transport header that carries the MCP session id.
|
|
2565
2595
|
*
|
|
2566
2596
|
* @remarks
|
|
2567
|
-
* A
|
|
2597
|
+
* A stateful server sends it on the `initialize` reply, and
|
|
2568
2598
|
* {@link import('./transports/HTTPClientTransport.js').HTTPClientTransport} echoes it as a
|
|
2569
2599
|
* request header on every subsequent request, so a client passes that server's session
|
|
2570
2600
|
* validation unchanged.
|
|
@@ -2621,10 +2651,10 @@ export declare interface MCPBlobResource {
|
|
|
2621
2651
|
* @remarks
|
|
2622
2652
|
* Each option lives for exactly one request:
|
|
2623
2653
|
*
|
|
2624
|
-
* - `signal` cancels
|
|
2654
|
+
* - `signal` cancels that request and nothing else. It never closes the connection, never
|
|
2625
2655
|
* reaches a durable task the call may have become, and never asks the peer to undo work
|
|
2626
2656
|
* already done — cancellation is advisory in MCP, so the peer may finish anyway and the
|
|
2627
|
-
* caller
|
|
2657
|
+
* caller stops waiting. A signal that is already aborted refuses the call before
|
|
2628
2658
|
* anything is written, so no request the peer would have to be told about is ever issued.
|
|
2629
2659
|
* - `progress` receives each `notifications/progress` frame the peer publishes for this
|
|
2630
2660
|
* request. Supplying it is what stamps the request's progress token, so a peer only
|
|
@@ -2660,9 +2690,9 @@ export declare interface MCPCallOptions {
|
|
|
2660
2690
|
* - `'complete'` — the call finished. `value` is the tool's own value: the peer's
|
|
2661
2691
|
* `structuredContent` when it sent one (the tool's value in its original structure),
|
|
2662
2692
|
* and otherwise the concatenated `text` blocks parsed as JSON, falling back to the raw
|
|
2663
|
-
* text. A tool
|
|
2693
|
+
* text. A tool failure never reaches this arm — `isError: true` throws, so an agent's
|
|
2664
2694
|
* {@link ToolManagerInterface} isolates a remote failure exactly as it does a local one.
|
|
2665
|
-
* - {@link MCPTaskResult} — the server
|
|
2695
|
+
* - {@link MCPTaskResult} — the server deferred the call into a durable task. The request
|
|
2666
2696
|
* is over and the work is not; the outcome arrives later through the task's own methods.
|
|
2667
2697
|
* - {@link MCPInputResult} — the call needs another round trip before it can finish.
|
|
2668
2698
|
*
|
|
@@ -2681,20 +2711,20 @@ export declare type MCPCallResult = MCPUnstampedCallResult & {
|
|
|
2681
2711
|
};
|
|
2682
2712
|
|
|
2683
2713
|
/**
|
|
2684
|
-
* Connects to a
|
|
2714
|
+
* Connects to a remote MCP server over any injected {@link MCPMessageTransportInterface},
|
|
2685
2715
|
* negotiates the modern revision, and exposes the server's tools as local
|
|
2686
2716
|
* {@link ToolInterface}s an agent can run.
|
|
2687
2717
|
*
|
|
2688
2718
|
* @remarks
|
|
2689
|
-
* - **The mirror of `MCPServer`.** The server
|
|
2690
|
-
* this client
|
|
2719
|
+
* - **The mirror of `MCPServer`.** The server dispatches requests over a tool registry;
|
|
2720
|
+
* this client issues them over a transport. `connect` probes `server/discover` and exposes
|
|
2691
2721
|
* the negotiated `version`; a legacy peer requires an explicit transport adapter.
|
|
2692
2722
|
* `tools()` lists the remote tools and wraps each as a
|
|
2693
2723
|
* local {@link ToolInterface} whose `execute` calls back through `call`; `call` runs a
|
|
2694
2724
|
* remote `tools/call` and reports the arm the peer answered with — a value, a durable
|
|
2695
2725
|
* task, or a request for more input (a remote `isError: true` throws locally, so an
|
|
2696
2726
|
* agent's {@link import('@orkestrel/tool').ToolManagerInterface} isolates it into a
|
|
2697
|
-
* `success: false` result
|
|
2727
|
+
* `success: false` result exactly like a local throw). A wrapped tool cannot hand an agent
|
|
2698
2728
|
* a deferred answer, so a non-`'complete'` arm throws there.
|
|
2699
2729
|
* - **Request↔response correlation.** Each request is tagged with a monotonic numeric
|
|
2700
2730
|
* `id` ({@link #nextId}); a single transport `message` subscription resolves / rejects
|
|
@@ -2702,9 +2732,9 @@ export declare type MCPCallResult = MCPUnstampedCallResult & {
|
|
|
2702
2732
|
* every pending request because the peer could not identify which request failed. A
|
|
2703
2733
|
* server-initiated message is re-surfaced on the `notification` event, except a progress
|
|
2704
2734
|
* frame claimed by the request that asked
|
|
2705
|
-
* for it; a
|
|
2735
|
+
* for it; a response correlating to nothing pending is discarded, because the request it
|
|
2706
2736
|
* answers has already settled.
|
|
2707
|
-
* - **Per-request cancellation.** `call`'s `options.signal` withdraws
|
|
2737
|
+
* - **Per-request cancellation.** `call`'s `options.signal` withdraws one caller from one
|
|
2708
2738
|
* request: the pending entry rejects on every carrier, and `notifications/cancelled` goes
|
|
2709
2739
|
* out only where the transport declares itself duplex — the dated revision defines no
|
|
2710
2740
|
* client-to-server notification over Streamable HTTP, where closing the response stream
|
|
@@ -2721,7 +2751,7 @@ export declare type MCPCallResult = MCPUnstampedCallResult & {
|
|
|
2721
2751
|
* discovery probe uses that same configured deadline, so a silent peer cannot hold
|
|
2722
2752
|
* negotiation indefinitely.
|
|
2723
2753
|
* `AbortSignal.timeout` (never a raw `setTimeout`) rejects only that pending request, and the
|
|
2724
|
-
* same deadline bounds the
|
|
2754
|
+
* same deadline bounds the wait on the transport's `close`, the one wait no drain and no signal
|
|
2725
2755
|
* can reach. It bounds the wait rather than the close, which keeps running, so a retry joins it
|
|
2726
2756
|
* instead of shutting one connection down twice.
|
|
2727
2757
|
* - **Transport-agnostic.** Imports only core siblings (JSON-RPC + the tool vocabulary);
|
|
@@ -2783,13 +2813,13 @@ export declare type MCPClientCapabilities = Readonly<Record<string, MCPMetaObjec
|
|
|
2783
2813
|
* - `disconnect` — the connection this client had announced ended (every pending request
|
|
2784
2814
|
* rejected, and the connection it owned on the transport closed — or that close faulted or
|
|
2785
2815
|
* timed out, which rejects the `disconnect` caller rather than withholding this event).
|
|
2786
|
-
* - `notification` — a server-initiated JSON-RPC
|
|
2816
|
+
* - `notification` — a server-initiated JSON-RPC notification arrived — forwarded for the
|
|
2787
2817
|
* consumer to react to (for example, a `notifications/tools/list_changed`). A
|
|
2788
2818
|
* `notifications/progress` frame claimed by an in-flight request's progress handler is
|
|
2789
|
-
* delivered there instead, and a
|
|
2819
|
+
* delivered there instead, and a response correlating to nothing pending is discarded
|
|
2790
2820
|
* rather than forwarded here, because it answers a request that has already settled.
|
|
2791
2821
|
* - `error` — a client-level fault surfaced for observation (typed `unknown`). This is
|
|
2792
|
-
* a
|
|
2822
|
+
* a domain event, distinct from the emitter's own listener-error channel: a listener throw
|
|
2793
2823
|
* is routed to the emitter's `error` handler (the `error` option), never onto this map.
|
|
2794
2824
|
* Declared as a `type` alias so the literal satisfies `EventMap`.
|
|
2795
2825
|
*/
|
|
@@ -2805,13 +2835,13 @@ export declare type MCPClientEventMap = {
|
|
|
2805
2835
|
};
|
|
2806
2836
|
|
|
2807
2837
|
/**
|
|
2808
|
-
* Connects to a
|
|
2838
|
+
* Connects to a remote MCP server over any injected {@link MCPMessageTransportInterface},
|
|
2809
2839
|
* negotiates the modern wire revision, and exposes the server's tools as local
|
|
2810
2840
|
* {@link ToolInterface}s an agent can run.
|
|
2811
2841
|
*
|
|
2812
2842
|
* @remarks
|
|
2813
|
-
* - **The mirror of {@link MCPServerInterface}.** Where the server
|
|
2814
|
-
* over a tool registry, the client
|
|
2843
|
+
* - **The mirror of {@link MCPServerInterface}.** Where the server dispatches requests
|
|
2844
|
+
* over a tool registry, the client issues them over a transport: `connect` negotiates through
|
|
2815
2845
|
* `server/discover`. A legacy peer requires an explicit
|
|
2816
2846
|
* {@link MCPLegacyClientTransportOptions legacy transport adapter}; the bare client refuses a
|
|
2817
2847
|
* peer that does not speak the modern era and names that adapter.
|
|
@@ -2819,11 +2849,11 @@ export declare type MCPClientEventMap = {
|
|
|
2819
2849
|
* the remote tools and wraps each as a local {@link ToolInterface} whose `execute`
|
|
2820
2850
|
* calls back through `call`; `call(name, args)` runs a remote `tools/call` and reports
|
|
2821
2851
|
* the arm the peer answered with — a value, a durable task, or a request for more input
|
|
2822
|
-
* (a remote tool
|
|
2823
|
-
* {@link ToolManagerInterface} isolates it into a `success: false` result
|
|
2852
|
+
* (a remote tool failure — `isError: true` — throws locally, so the agent's
|
|
2853
|
+
* {@link ToolManagerInterface} isolates it into a `success: false` result exactly like a
|
|
2824
2854
|
* local throw). A wrapped tool has no way to hand an agent a deferred answer, so a
|
|
2825
2855
|
* non-`'complete'` arm throws there instead.
|
|
2826
|
-
* - **Per-request cancellation.** `call`'s `options.signal` cancels
|
|
2856
|
+
* - **Per-request cancellation.** `call`'s `options.signal` cancels one in-flight request:
|
|
2827
2857
|
* it rejects locally on every carrier, and additionally writes `notifications/cancelled`
|
|
2828
2858
|
* where the transport declares itself {@link MCPMessageTransportInterface.duplex}. It
|
|
2829
2859
|
* never cancels the connection, and never a durable task — a call that already answered
|
|
@@ -2832,17 +2862,17 @@ export declare type MCPClientEventMap = {
|
|
|
2832
2862
|
* - **Durable tasks, no schedule.** `tasks` ({@link MCPTaskClientInterface}) reads, answers,
|
|
2833
2863
|
* and stops a task the peer deferred a call into. It carries the peer's `pollIntervalMs`
|
|
2834
2864
|
* datum and supplies the one-shot read; it starts no timer and keeps no cache, so a client
|
|
2835
|
-
* left alone after a `resultType: 'task'` answer writes
|
|
2865
|
+
* left alone after a `resultType: 'task'` answer writes nothing until its consumer asks.
|
|
2836
2866
|
* - **Request↔response correlation.** Every request is tagged with a monotonic numeric
|
|
2837
2867
|
* `id`; the client subscribes to the transport's `message` event and resolves /
|
|
2838
2868
|
* rejects the matching pending request by that `id`. A server-initiated message is
|
|
2839
2869
|
* surfaced on `notification` — except a `notifications/progress` frame naming a request
|
|
2840
2870
|
* whose caller supplied a progress handler, which goes to that handler instead. A
|
|
2841
|
-
*
|
|
2871
|
+
* response whose id matches nothing pending is discarded: the request it answers has
|
|
2842
2872
|
* already settled, by its deadline, by an abort, or by a disconnect, and the protocol
|
|
2843
2873
|
* says to ignore it rather than surface it as something a caller might act on.
|
|
2844
2874
|
* - **Per-request deadline.** A request carrying a deadline races an
|
|
2845
|
-
* `AbortSignal.timeout(timeout)`: a server that never replies
|
|
2875
|
+
* `AbortSignal.timeout(timeout)`: a server that never replies rejects that pending
|
|
2846
2876
|
* request once the deadline fires. The initial discovery probe and every public request use a
|
|
2847
2877
|
* deadline. An omitted `timeout` selects {@link DEFAULT_MCP_REQUEST_TIMEOUT}; an explicit
|
|
2848
2878
|
* timeout applies that deadline to the probe. The client's
|
|
@@ -2870,7 +2900,7 @@ export declare interface MCPClientInterface {
|
|
|
2870
2900
|
*
|
|
2871
2901
|
* @remarks
|
|
2872
2902
|
* Always present, because the `tasks/*` methods are ordinary requests a client may
|
|
2873
|
-
* issue at any time; whether they
|
|
2903
|
+
* issue at any time; whether they succeed is the peer's decision, and a server that did not
|
|
2874
2904
|
* configure the extension answers each of them `-32601`. Nothing here is advertised, cached, or
|
|
2875
2905
|
* polled — see {@link MCPTaskClientInterface} for why the schedule stays the consumer's.
|
|
2876
2906
|
*/
|
|
@@ -2881,14 +2911,14 @@ export declare interface MCPClientInterface {
|
|
|
2881
2911
|
*
|
|
2882
2912
|
* @remarks
|
|
2883
2913
|
* Idempotent — a second `connect` while already connected is a no-op, and one issued
|
|
2884
|
-
* while the
|
|
2914
|
+
* while the current attempt is in flight joins that attempt and returns its outcome
|
|
2885
2915
|
* instead of opening a second connection. One issued while a {@link disconnect} is closing
|
|
2886
2916
|
* waits for that close first; one issued while an attempt that a {@link disconnect}
|
|
2887
|
-
* superseded is still unwinding
|
|
2917
|
+
* superseded is still unwinding outwaits it, because that attempt may still owe the close
|
|
2888
2918
|
* of a connection it opened, and then opens the next connection or joins whichever caller
|
|
2889
|
-
* reached it first. One issued while a close is still
|
|
2919
|
+
* reached it first. One issued while a close is still owed — an earlier `close` having failed,
|
|
2890
2920
|
* or having outrun its deadline without ever confirming that the connection ended — closes that
|
|
2891
|
-
* connection
|
|
2921
|
+
* connection first, joining a close still running rather than issuing a second one, and rejects
|
|
2892
2922
|
* with the fault if that close fails or goes unanswered again; so the transport is never opened
|
|
2893
2923
|
* beside a connection no path has closed. The client probes `server/discover`; an explicit legacy
|
|
2894
2924
|
* transport adapter owns any `initialize` handshake and presents a modern discovery result.
|
|
@@ -2933,7 +2963,7 @@ export declare interface MCPClientInterface {
|
|
|
2933
2963
|
* `start` does, because nothing here bounds the opening step. It closes the connection the
|
|
2934
2964
|
* client owns when it runs, and closes nothing for an attempt still inside the transport's
|
|
2935
2965
|
* `start` — that attempt owns nothing yet and closes what it opens itself. The transport's
|
|
2936
|
-
* `close` carries the per-request deadline on the
|
|
2966
|
+
* `close` carries the per-request deadline on the wait, so a shutdown the transport accepts and
|
|
2937
2967
|
* never answers rejects instead of holding this caller and every later {@link connect} — while
|
|
2938
2968
|
* that close itself keeps running, because the deadline only ends this client's waiting. A `close`
|
|
2939
2969
|
* that faults or goes unanswered rejects this call and leaves the connection owned, so the next
|
|
@@ -2977,17 +3007,17 @@ export declare interface MCPClientInterface {
|
|
|
2977
3007
|
*
|
|
2978
3008
|
* @remarks
|
|
2979
3009
|
* The answer is an {@link MCPCallOutcome} because the peer, not the caller, decides
|
|
2980
|
-
* whether the call finished: a modern server may
|
|
3010
|
+
* whether the call finished: a modern server may defer it into a durable task or ask
|
|
2981
3011
|
* for another round trip, and both are legal answers to an ordinary call. Narrow on
|
|
2982
3012
|
* `resultType`; the `'complete'` arm carries the tool's `value` — the peer's
|
|
2983
3013
|
* `structuredContent` when it sent one, otherwise its concatenated `text` parsed as
|
|
2984
|
-
* JSON (falling back to the raw string). A remote tool
|
|
2985
|
-
*
|
|
3014
|
+
* JSON (falling back to the raw string). A remote tool failure (`isError: true`)
|
|
3015
|
+
* throws an `Error` carrying the error text instead, so an agent's
|
|
2986
3016
|
* {@link ToolManagerInterface} isolates it into a `success: false` result exactly as
|
|
2987
3017
|
* it would a local tool throw. A `resultType` this client cannot name is refused.
|
|
2988
3018
|
*
|
|
2989
|
-
* `options.signal` cancels
|
|
2990
|
-
* request rejects, and the peer is
|
|
3019
|
+
* `options.signal` cancels this request only — the caller stops waiting, the pending
|
|
3020
|
+
* request rejects, and the peer is told on a carrier that can carry a client
|
|
2991
3021
|
* notification (see {@link MCPMessageTransportInterface.duplex}). MCP cancellation is
|
|
2992
3022
|
* advisory: the peer may answer anyway, and that late answer is discarded rather than
|
|
2993
3023
|
* raised. `options.progress` receives this request's progress frames.
|
|
@@ -3006,7 +3036,7 @@ export declare interface MCPClientInterface {
|
|
|
3006
3036
|
* `on` hooks.
|
|
3007
3037
|
*
|
|
3008
3038
|
* @remarks
|
|
3009
|
-
* - `transport` — the carrier the client drives a remote MCP server over (
|
|
3039
|
+
* - `transport` — the carrier the client drives a remote MCP server over (required;
|
|
3010
3040
|
* a concrete one from `src/server/mcp`, or an in-process loopback). The bare client negotiates
|
|
3011
3041
|
* the modern revision through `server/discover`; wrap the carrier with
|
|
3012
3042
|
* {@link import('./factories.js').createMCPLegacyClientTransport} for a legacy peer.
|
|
@@ -3017,9 +3047,9 @@ export declare interface MCPClientInterface {
|
|
|
3017
3047
|
* request; defaults to an empty record.
|
|
3018
3048
|
* - `version` — an optional modern protocol pin; absence lets `server/discover` negotiate.
|
|
3019
3049
|
* - `timeout` — the per-request deadline in milliseconds: a `server/discover` / `tools/list` /
|
|
3020
|
-
* `tools/call` that the server does not answer within it
|
|
3050
|
+
* `tools/call` that the server does not answer within it rejects (the pending
|
|
3021
3051
|
* request is settled by an `AbortSignal.timeout(timeout)` deadline — never a raw
|
|
3022
|
-
* `setTimeout`). The same deadline bounds the client's
|
|
3052
|
+
* `setTimeout`). The same deadline bounds the client's wait on the transport's `close`, so a
|
|
3023
3053
|
* shutdown the transport accepts and never answers rejects its caller instead of wedging the
|
|
3024
3054
|
* client — which makes a short `timeout` a short shutdown grace as well as a short request
|
|
3025
3055
|
* deadline. Defaults to {@link import('./constants.js').DEFAULT_MCP_REQUEST_TIMEOUT}.
|
|
@@ -3070,7 +3100,7 @@ export declare interface MCPCompletionContext {
|
|
|
3070
3100
|
* verbatim and performs no template parsing or expansion. Returning `undefined` means the
|
|
3071
3101
|
* referenced prompt or resource template does not exist.
|
|
3072
3102
|
*
|
|
3073
|
-
* This is the
|
|
3103
|
+
* This is the port that produces a {@link MCPCompletion}, not the behavioural face of one: the
|
|
3074
3104
|
* candidate set is the data type, and this contract is the single method a host answers it from.
|
|
3075
3105
|
*/
|
|
3076
3106
|
export declare interface MCPCompletionInterface {
|
|
@@ -3084,7 +3114,10 @@ export declare interface MCPCompletionInterface {
|
|
|
3084
3114
|
complete(params: MCPCompletionParams, options: MCPMethodOptions): MCPCompletion | undefined | Promise<MCPCompletion | undefined>;
|
|
3085
3115
|
}
|
|
3086
3116
|
|
|
3087
|
-
/**
|
|
3117
|
+
/**
|
|
3118
|
+
* Represents the parameters `completion/complete` accepts — a reference, the argument fragment
|
|
3119
|
+
* being completed, and the optional resolved context.
|
|
3120
|
+
*/
|
|
3088
3121
|
export declare interface MCPCompletionParams {
|
|
3089
3122
|
readonly ref: MCPCompletionReference;
|
|
3090
3123
|
readonly argument: MCPCompletionArgument;
|
|
@@ -3094,7 +3127,13 @@ export declare interface MCPCompletionParams {
|
|
|
3094
3127
|
/** Represents the prompt or resource-template reference accepted by `completion/complete`. */
|
|
3095
3128
|
export declare type MCPCompletionReference = MCPPromptReference | MCPResourceTemplateReference;
|
|
3096
3129
|
|
|
3097
|
-
/**
|
|
3130
|
+
/**
|
|
3131
|
+
* Represents the complete `completion/complete` result.
|
|
3132
|
+
*
|
|
3133
|
+
* @remarks
|
|
3134
|
+
* The candidate set is capped at 100 values, and `hasMore` reads `true` whenever that cap
|
|
3135
|
+
* truncated the host's own answer.
|
|
3136
|
+
*/
|
|
3098
3137
|
export declare interface MCPCompletionResult {
|
|
3099
3138
|
readonly resultType: 'complete';
|
|
3100
3139
|
readonly completion: MCPCompletion;
|
|
@@ -3174,7 +3213,7 @@ export declare interface MCPDispatcherInterface {
|
|
|
3174
3213
|
* Represents the per-request execution options every dispatched handler receives.
|
|
3175
3214
|
*
|
|
3176
3215
|
* @remarks
|
|
3177
|
-
* `caller` is consumer-ASSERTED and
|
|
3216
|
+
* `caller` is consumer-ASSERTED and never verified. Sessions mint transport identity, not
|
|
3178
3217
|
* caller identity, and nothing in MCP authenticates this value. This package carries it
|
|
3179
3218
|
* opaquely without inspecting, validating, or serializing it. A consumer must narrow it with
|
|
3180
3219
|
* its own total guard and treat absence as unauthenticated.
|
|
@@ -3277,7 +3316,12 @@ export declare interface MCPElicitSchema extends Readonly<Record<string, unknown
|
|
|
3277
3316
|
readonly required?: readonly string[];
|
|
3278
3317
|
}
|
|
3279
3318
|
|
|
3280
|
-
/**
|
|
3319
|
+
/**
|
|
3320
|
+
* Represents the parameters of a URL-mode `elicitation/create` request.
|
|
3321
|
+
*
|
|
3322
|
+
* @remarks
|
|
3323
|
+
* A consumer round may compose one, and the client must declare `elicitation.url` to receive it.
|
|
3324
|
+
*/
|
|
3281
3325
|
export declare interface MCPElicitURL {
|
|
3282
3326
|
readonly mode: 'url';
|
|
3283
3327
|
readonly message: string;
|
|
@@ -3449,10 +3493,10 @@ export declare interface MCPInputOptions {
|
|
|
3449
3493
|
* Represents one embedded multi-round-trip request.
|
|
3450
3494
|
*
|
|
3451
3495
|
* @remarks
|
|
3452
|
-
* A consumer composes any of the
|
|
3496
|
+
* A consumer composes any of the arms into an {@link MCPInputRound}, and this server
|
|
3453
3497
|
* issues whichever arms that round carries. The elicitation arm is fully typed because this
|
|
3454
3498
|
* package issues its schema and enforces the answer against it. The sampling and roots arms
|
|
3455
|
-
* keep
|
|
3499
|
+
* keep open parameter records: the dated schema leaves their request bodies to the caller, and
|
|
3456
3500
|
* narrowing them here would refuse parameters the protocol permits.
|
|
3457
3501
|
*/
|
|
3458
3502
|
export declare type MCPInputRequest = MCPElicitRequest | {
|
|
@@ -3473,7 +3517,7 @@ export declare type MCPInputRequestMap = Readonly<Record<string, MCPInputRequest
|
|
|
3473
3517
|
* The arms are discriminated by their own required members — `action` for an elicitation,
|
|
3474
3518
|
* `roots` for a roots listing, and `model` beside `role` for a sampling completion — because
|
|
3475
3519
|
* the protocol gives a response no `method` of its own. The server knows which arm applies
|
|
3476
|
-
* from the request it
|
|
3520
|
+
* from the request it issued under that key, so {@link MCPInputHandler} receives every answer
|
|
3477
3521
|
* already checked against the question it answers.
|
|
3478
3522
|
*/
|
|
3479
3523
|
export declare type MCPInputResponse = MCPElicitResult | MCPSampleResult | MCPRootResult;
|
|
@@ -3520,9 +3564,9 @@ export declare interface MCPInputRound {
|
|
|
3520
3564
|
* Represents the integrity-protected payload carried inside an opaque `requestState` token.
|
|
3521
3565
|
*
|
|
3522
3566
|
* @remarks
|
|
3523
|
-
* `id` is the
|
|
3567
|
+
* `id` is the first round's request id and stays bound across every later round, so a
|
|
3524
3568
|
* multi-round exchange remains one correlated call rather than a chain whose origin is lost
|
|
3525
|
-
* after the second hop. `requests` is the
|
|
3569
|
+
* after the second hop. `requests` is the exact round that was issued: it carries the keys the
|
|
3526
3570
|
* retry must answer and, for a form elicitation, the schema {@link isElicitContent} enforces
|
|
3527
3571
|
* an accepted answer against — a round that is bound but never enforced buys nothing.
|
|
3528
3572
|
* `requests` and `expiry` are re-minted every round; `principal`, `id`, `version`, `method`,
|
|
@@ -3657,7 +3701,7 @@ export declare interface MCPLegacyOptions {
|
|
|
3657
3701
|
*
|
|
3658
3702
|
* @remarks
|
|
3659
3703
|
* The legacy revision has no result-discriminator concept, so a legacy result
|
|
3660
|
-
* carries
|
|
3704
|
+
* carries no `resultType`. That absence is the whole distinction, which is why it is
|
|
3661
3705
|
* declared `never` rather than optional: an {@link MCPResult} is not assignable
|
|
3662
3706
|
* here, this type is not assignable to {@link MCPResult}, and
|
|
3663
3707
|
* `result.resultType === undefined` narrows a {@link JSONRPCResultResponse}'s
|
|
@@ -3728,13 +3772,13 @@ export declare type MCPLoggingLevel = 'debug' | 'info' | 'notice' | 'warning' |
|
|
|
3728
3772
|
* {@link MCPClientInterface} (and any tracer) subscribes to through `transport.emitter.on`.
|
|
3729
3773
|
*
|
|
3730
3774
|
* @remarks
|
|
3731
|
-
* - `message` — a JSON-RPC message
|
|
3775
|
+
* - `message` — a JSON-RPC message arrived from the remote server (a response the
|
|
3732
3776
|
* client correlates to a pending request by `id`, or a server-initiated
|
|
3733
3777
|
* notification). The transport decodes the wire bytes (a JSON body or an SSE
|
|
3734
3778
|
* `data:` event) and emits the parsed {@link JSONRPCMessage}.
|
|
3735
3779
|
* - `close` — the transport's connection ended (a stream closed, `close()` ran).
|
|
3736
3780
|
* - `error` — a transport-level fault (a malformed message, a network error); the
|
|
3737
|
-
* payload is typed `unknown`. This is a
|
|
3781
|
+
* payload is typed `unknown`. This is a domain event, distinct from the emitter's
|
|
3738
3782
|
* own listener-error channel: a listener throw is routed to the emitter's `error` handler
|
|
3739
3783
|
* (the `error` option), never onto this map. Declared as a `type` alias so the
|
|
3740
3784
|
* type-literal satisfies `EventMap` structurally.
|
|
@@ -3768,7 +3812,7 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3768
3812
|
/** Holds a server-assigned session id after a stateful transport has one; `undefined` otherwise. */
|
|
3769
3813
|
readonly session: string | undefined;
|
|
3770
3814
|
/**
|
|
3771
|
-
* Reports whether this carrier accepts a
|
|
3815
|
+
* Reports whether this carrier accepts a client-initiated notification — one written with
|
|
3772
3816
|
* no `id`, which no response will ever answer.
|
|
3773
3817
|
*
|
|
3774
3818
|
* @remarks
|
|
@@ -3779,7 +3823,7 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3779
3823
|
* `true` for a genuinely bidirectional channel — a WebSocket, a stdio pipe pair, an
|
|
3780
3824
|
* in-process duplex port — where a frame the client writes at any moment reaches the
|
|
3781
3825
|
* peer. `false` for a request/response carrier such as Streamable HTTP: the dated
|
|
3782
|
-
* revision defines
|
|
3826
|
+
* revision defines no client-to-server notification over it, and the cancellation
|
|
3783
3827
|
* signal there is closing the response stream rather than a frame. A `false` carrier
|
|
3784
3828
|
* is not a degraded one — it has its own signal — so the client withholds the frame
|
|
3785
3829
|
* rather than writing one nothing will read.
|
|
@@ -3789,7 +3833,7 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3789
3833
|
* Opens the transport — establishes the connection and arms any reply reader.
|
|
3790
3834
|
*
|
|
3791
3835
|
* @remarks
|
|
3792
|
-
* A `start` that
|
|
3836
|
+
* A `start` that rejects must first release whatever it had already acquired. The
|
|
3793
3837
|
* {@link MCPClientInterface} claims a connection only once `start` resolves, so a rejection
|
|
3794
3838
|
* leaves it holding an error and no claim: a socket, session, or reader the transport opened
|
|
3795
3839
|
* before failing is reachable by nothing the client can call, and no client-side mechanism can
|
|
@@ -3807,7 +3851,7 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3807
3851
|
* transport, its synchronous reply emitted), not when a logical response arrives;
|
|
3808
3852
|
* the {@link MCPClientInterface} awaits the response through its `id` correlation.
|
|
3809
3853
|
*
|
|
3810
|
-
* A `send` that
|
|
3854
|
+
* A `send` that fails must fail by rejecting, never by throwing synchronously. The
|
|
3811
3855
|
* {@link MCPClientInterface} registers the write inside the same promise executor that
|
|
3812
3856
|
* records the request's pending entry, so a synchronous throw leaves no promise for that
|
|
3813
3857
|
* registration to attach to: the entry set one statement earlier is never settled, and a
|
|
@@ -3831,18 +3875,18 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3831
3875
|
* Closes the transport — ends the connection and releases resources.
|
|
3832
3876
|
*
|
|
3833
3877
|
* @remarks
|
|
3834
|
-
* A `close` must
|
|
3878
|
+
* A `close` must settle, and its settlements mean different things to its caller: resolving
|
|
3835
3879
|
* says the connection ended, rejecting says it did not. The
|
|
3836
3880
|
* {@link MCPClientInterface}'s only other bound is a deadline, which reports that the shutdown
|
|
3837
|
-
* did not
|
|
3881
|
+
* did not answer and never that it did not happen — so a `close` that resolves or rejects hours
|
|
3838
3882
|
* late still decides the outcome, and one that never settles leaves the connection owed for the
|
|
3839
3883
|
* client's life. `close` is never called twice concurrently for one connection: a caller that
|
|
3840
|
-
* gave up waiting
|
|
3841
|
-
* again after an earlier `close`
|
|
3884
|
+
* gave up waiting joins the `close` still running rather than issuing another. It is called
|
|
3885
|
+
* again after an earlier `close` rejected, because a rejected close ended nothing.
|
|
3842
3886
|
*
|
|
3843
|
-
* `close` is
|
|
3887
|
+
* `close` is idempotent: a call on a transport an earlier `close` already ended resolves
|
|
3844
3888
|
* without emitting `close` again and without releasing anything a second time. Idempotence
|
|
3845
|
-
* bounds
|
|
3889
|
+
* bounds one closed lifetime rather than the object — a transport that reopens on `start`
|
|
3846
3890
|
* arms itself there, and its next `close` ends that connection and emits once for it.
|
|
3847
3891
|
*
|
|
3848
3892
|
* @returns Resolves once the transport is closed
|
|
@@ -3854,7 +3898,7 @@ export declare interface MCPMessageTransportInterface {
|
|
|
3854
3898
|
* Represents the exact finite JSON metadata carried by MCP `_meta` envelopes.
|
|
3855
3899
|
*
|
|
3856
3900
|
* @remarks
|
|
3857
|
-
* The `Object` suffix is not a role suffix from the type table — it
|
|
3901
|
+
* The `Object` suffix is not a role suffix from the type table — it names the shape.
|
|
3858
3902
|
* `_meta` is a JSON object whose values are exact JSON, and a reader who sees
|
|
3859
3903
|
* `MCPMeta` cannot tell that from a key, a string, or an entry. The same holds for
|
|
3860
3904
|
* {@link MCPResultMetaObject} and {@link MCPSubscriptionResultMetaObject}, which are
|
|
@@ -3868,21 +3912,21 @@ export declare type MCPMetaObject = Readonly<Record<string, JSONValue>>;
|
|
|
3868
3912
|
* @remarks
|
|
3869
3913
|
* A registered method answers a {@link JSONRPCRequest} — with a terminating
|
|
3870
3914
|
* {@link JSONRPCResponse}, or by holding the exchange open as an {@link MCPStream}. It is
|
|
3871
|
-
* invoked for nothing else: dispatch short-circuits a {@link JSONRPCNotification}
|
|
3915
|
+
* invoked for nothing else: dispatch short-circuits a {@link JSONRPCNotification} before the
|
|
3872
3916
|
* registry is read, so the notification arm never arrives here and no handler has to narrow
|
|
3873
3917
|
* one away.
|
|
3874
3918
|
*
|
|
3875
3919
|
* The seam is this narrow because the future a wider one was kept for is structurally
|
|
3876
3920
|
* unavailable. The only client-to-server notification the core protocol defines is
|
|
3877
|
-
* `notifications/cancelled`, and a handler acting on one must reach the
|
|
3878
|
-
* `AbortController` — which dispatch creates per request,
|
|
3921
|
+
* `notifications/cancelled`, and a handler acting on one must reach the other request's
|
|
3922
|
+
* `AbortController` — which dispatch creates per request, after the notification
|
|
3879
3923
|
* short-circuit, and publishes to no registry and no member. Admitting a cancellation
|
|
3880
3924
|
* handler therefore needs a live request-id-to-controller registry — new cross-request
|
|
3881
3925
|
* server state — before the parameter's width ever becomes the obstacle.
|
|
3882
3926
|
*
|
|
3883
3927
|
* Answering is not optional either, and that is a runtime rule as well as a type. A handler
|
|
3884
3928
|
* resolving `undefined` for a request contradicts `dispatch`'s own overloads and leaves the
|
|
3885
|
-
* caller waiting until its deadline, so dispatch
|
|
3929
|
+
* caller waiting until its deadline, so dispatch contains one as `-32603` plus a single
|
|
3886
3930
|
* `error` event rather than passing the absence on.
|
|
3887
3931
|
*
|
|
3888
3932
|
* `options.signal` is already resolved and always present — what a handler does with it
|
|
@@ -3902,10 +3946,10 @@ export declare type MCPMethodHandler = (request: JSONRPCRequest, options: MCPMet
|
|
|
3902
3946
|
*
|
|
3903
3947
|
* @remarks
|
|
3904
3948
|
* - **One seam.** The server registers its built-in modern methods here at construction
|
|
3905
|
-
* and resolves
|
|
3949
|
+
* and resolves every modern method from here, so a consumer's method and a built-in
|
|
3906
3950
|
* are the same kind of thing on the same path.
|
|
3907
3951
|
* - **Registration is a write, not a merge.** `add` under a name already present
|
|
3908
|
-
*
|
|
3952
|
+
* replaces it, which is how a consumer overrides a built-in; there is no precedence
|
|
3909
3953
|
* rule to remember.
|
|
3910
3954
|
* - **A narrower contract than a `Map`.** Callers register and resolve; they cannot
|
|
3911
3955
|
* iterate, clear, or otherwise reach the server's internal state through it.
|
|
@@ -3926,12 +3970,12 @@ export declare class MCPMethodManager implements MCPMethodManagerInterface {
|
|
|
3926
3970
|
|
|
3927
3971
|
/**
|
|
3928
3972
|
* Represents the modern method registry an {@link MCPServerInterface} dispatches through —
|
|
3929
|
-
* the
|
|
3973
|
+
* the one seam carrying both the built-in methods and any method a consumer adds.
|
|
3930
3974
|
*
|
|
3931
3975
|
* @remarks
|
|
3932
3976
|
* `server/discover`, `tools/list`, `tools/call`, and `subscriptions/listen` are registered here at construction,
|
|
3933
|
-
* so they travel the
|
|
3934
|
-
* and no precedence puzzle. `add` under an existing name
|
|
3977
|
+
* so they travel the same path as every later method: there is no second dispatch route
|
|
3978
|
+
* and no precedence puzzle. `add` under an existing name replaces that method — a
|
|
3935
3979
|
* consumer overriding a built-in is an ordinary registration, not a special case. A name
|
|
3936
3980
|
* with no handler is not an error state to model: {@link method} answers `undefined` and
|
|
3937
3981
|
* the dispatch branch turns that into `-32601`.
|
|
@@ -3954,12 +3998,12 @@ export declare interface MCPMethodManagerInterface {
|
|
|
3954
3998
|
}
|
|
3955
3999
|
|
|
3956
4000
|
/**
|
|
3957
|
-
* Represents the
|
|
4001
|
+
* Represents the resolved per-request options one dispatched method receives.
|
|
3958
4002
|
*
|
|
3959
4003
|
* @remarks
|
|
3960
|
-
* The mirror of {@link MCPDispatchOptions} on the far side of dispatch: a
|
|
4004
|
+
* The mirror of {@link MCPDispatchOptions} on the far side of dispatch: a caller may
|
|
3961
4005
|
* have no signal to offer, but a dispatched method always has one to observe, so
|
|
3962
|
-
* `signal` is
|
|
4006
|
+
* `signal` is required here. Dispatch resolves it once, at the single ingress, and
|
|
3963
4007
|
* supplies the same value to every handler, input, principal, and subscription
|
|
3964
4008
|
* producer the request reaches — none of them may reinvent a cancellation source or
|
|
3965
4009
|
* treat absence as a case.
|
|
@@ -3967,14 +4011,14 @@ export declare interface MCPMethodManagerInterface {
|
|
|
3967
4011
|
* Distinct from {@link MCPExecutionContext}, which is scoped to one tool execution
|
|
3968
4012
|
* and carries the call and registry alongside the signal.
|
|
3969
4013
|
*
|
|
3970
|
-
* The resolved signal is the request's
|
|
3971
|
-
* the caller's own signal aborts
|
|
4014
|
+
* The resolved signal is the request's lifetime, not merely the caller's: it aborts when
|
|
4015
|
+
* the caller's own signal aborts and when the answer this request produced is finished —
|
|
3972
4016
|
* a held-open stream that completed, that its consumer returned, or that an owner stopped.
|
|
3973
4017
|
* A producer parked on an event that will never arrive is woken by exactly that, which is
|
|
3974
4018
|
* why a custom stream producer observes this signal for its own cleanup instead of
|
|
3975
4019
|
* relying on the consumer to iterate it to the end.
|
|
3976
4020
|
*
|
|
3977
|
-
* `caller` is consumer-ASSERTED and
|
|
4021
|
+
* `caller` is consumer-ASSERTED and never verified, and is carried by identity: this
|
|
3978
4022
|
* package neither inspects, validates, clones, nor serializes it.
|
|
3979
4023
|
*/
|
|
3980
4024
|
export declare interface MCPMethodOptions {
|
|
@@ -3991,13 +4035,13 @@ export declare type MCPModernVersion = '2026-07-28';
|
|
|
3991
4035
|
* Carries open notification metadata with the dated reserved subscription field.
|
|
3992
4036
|
*
|
|
3993
4037
|
* @remarks
|
|
3994
|
-
* The subscription id is
|
|
4038
|
+
* The subscription id is optional here, and that is the schema's own split rather than
|
|
3995
4039
|
* this package hedging. A frame delivered down a `subscriptions/listen` stream carries the
|
|
3996
4040
|
* stamp naming the listen request that agreed to it; the same notification delivered any
|
|
3997
4041
|
* other way carries no stamp, because there is no subscription to name. A required key
|
|
3998
4042
|
* would refuse a frame the protocol permits.
|
|
3999
4043
|
*
|
|
4000
|
-
* Compare {@link MCPSubscriptionResultMetaObject}, where the same key is
|
|
4044
|
+
* Compare {@link MCPSubscriptionResultMetaObject}, where the same key is required: that one
|
|
4001
4045
|
* sits on the terminating result of a stream, so a subscription always exists to name.
|
|
4002
4046
|
*/
|
|
4003
4047
|
export declare type MCPNotificationMetaObject = MCPMetaObject & {
|
|
@@ -4007,13 +4051,23 @@ export declare type MCPNotificationMetaObject = MCPMetaObject & {
|
|
|
4007
4051
|
readonly 'io.modelcontextprotocol/subscriptionId'?: JSONRPCId;
|
|
4008
4052
|
};
|
|
4009
4053
|
|
|
4010
|
-
/**
|
|
4054
|
+
/**
|
|
4055
|
+
* Represents the cursor parameters shared by every paginated modern list method.
|
|
4056
|
+
*
|
|
4057
|
+
* @remarks
|
|
4058
|
+
* The cursor is opaque to this package, and the consumer's own manager mints it.
|
|
4059
|
+
*/
|
|
4011
4060
|
export declare interface MCPPaginationParams {
|
|
4012
4061
|
/** Holds the opaque cursor returned by the preceding page. */
|
|
4013
4062
|
readonly cursor?: string;
|
|
4014
4063
|
}
|
|
4015
4064
|
|
|
4016
|
-
/**
|
|
4065
|
+
/**
|
|
4066
|
+
* Represents the cursor result fields shared by every paginated modern list method.
|
|
4067
|
+
*
|
|
4068
|
+
* @remarks
|
|
4069
|
+
* An absent `nextCursor` member means the answered page was the final one.
|
|
4070
|
+
*/
|
|
4017
4071
|
export declare interface MCPPaginationResult {
|
|
4018
4072
|
/** Holds the opaque cursor for the following page; absent when this is the final page. */
|
|
4019
4073
|
readonly nextCursor?: string;
|
|
@@ -4039,14 +4093,14 @@ export declare interface MCPProgress {
|
|
|
4039
4093
|
* Receives one progress report a peer published for a request this client issued.
|
|
4040
4094
|
*
|
|
4041
4095
|
* @remarks
|
|
4042
|
-
* The
|
|
4096
|
+
* The receiving half of {@link MCPProgressInterface}, and deliberately not its mirror:
|
|
4043
4097
|
* the reporter awaits consumption because a server must not outrun the stream carrying
|
|
4044
4098
|
* its frames, while a client consuming an already-delivered frame has nothing left to
|
|
4045
4099
|
* push back on. So this returns `void` — a handler that throws is isolated by nothing
|
|
4046
4100
|
* and would surface on the client's `error` event, and one that needs to await
|
|
4047
4101
|
* something owns that lifetime itself.
|
|
4048
4102
|
*
|
|
4049
|
-
* The handler is registered for the
|
|
4103
|
+
* The handler is registered for the lifetime of one request and is released the moment
|
|
4050
4104
|
* that request settles, whichever way it settles. A frame that arrives afterwards is a
|
|
4051
4105
|
* late frame for a request nobody is waiting on, and reaches the `notification` event
|
|
4052
4106
|
* like any other unclaimed server-initiated message.
|
|
@@ -4063,12 +4117,12 @@ export declare interface MCPProgressInterface {
|
|
|
4063
4117
|
}
|
|
4064
4118
|
|
|
4065
4119
|
/**
|
|
4066
|
-
* Represents the
|
|
4120
|
+
* Represents the owning half of one progress slot — {@link MCPProgressInterface} plus the
|
|
4067
4121
|
* consuming and stopping the slot's owner performs.
|
|
4068
4122
|
*
|
|
4069
4123
|
* @remarks
|
|
4070
|
-
*
|
|
4071
|
-
* powers. An executor receives the narrow {@link MCPProgressInterface} through
|
|
4124
|
+
* A second interface over one entity because the executor and the owner hold it and they are
|
|
4125
|
+
* owed different powers. An executor receives the narrow {@link MCPProgressInterface} through
|
|
4072
4126
|
* {@link MCPExecutionContext} and can publish and nothing else; the MCP-owned response stream
|
|
4073
4127
|
* that created the slot holds this one and also drains it and shuts it down. Naming the owner's
|
|
4074
4128
|
* half is what keeps `take` and `stop` documented as contract rather than as extra surface a
|
|
@@ -4165,7 +4219,13 @@ export declare interface MCPPromptArgument {
|
|
|
4165
4219
|
readonly required?: boolean;
|
|
4166
4220
|
}
|
|
4167
4221
|
|
|
4168
|
-
/**
|
|
4222
|
+
/**
|
|
4223
|
+
* Represents the parameters `prompts/get` accepts — a prompt name plus the optional argument
|
|
4224
|
+
* values and multi-round continuation carriers.
|
|
4225
|
+
*
|
|
4226
|
+
* @remarks
|
|
4227
|
+
* Argument values are strings by contract, which is what the prompt wire shape requires.
|
|
4228
|
+
*/
|
|
4169
4229
|
export declare interface MCPPromptGetParams {
|
|
4170
4230
|
readonly name: string;
|
|
4171
4231
|
readonly arguments?: Readonly<Record<string, string>>;
|
|
@@ -4258,8 +4318,8 @@ export declare interface MCPRequestContext {
|
|
|
4258
4318
|
* correlated-request path here, so a task read travels the exact channel `call` and `tools`
|
|
4259
4319
|
* travel — one id space, one pending table, one drain on `disconnect`.
|
|
4260
4320
|
*
|
|
4261
|
-
* It resolves the peer's `result`
|
|
4262
|
-
* every caller wants a different shape. It
|
|
4321
|
+
* It resolves the peer's `result` unvalidated, because validating it is the caller's job and
|
|
4322
|
+
* every caller wants a different shape. It rejects with an
|
|
4263
4323
|
* {@link import('./errors.js').MCPError} for an error response, and with an ordinary `Error`
|
|
4264
4324
|
* for a deadline, an abort, or a transport write that failed.
|
|
4265
4325
|
*
|
|
@@ -4322,8 +4382,8 @@ export declare type MCPResourceListResult = MCPResourcePage & {
|
|
|
4322
4382
|
* Represents the consumer-supplied resource registry port.
|
|
4323
4383
|
*
|
|
4324
4384
|
* @remarks
|
|
4325
|
-
* MCP owns no storage. The host may back this port with memory, a
|
|
4326
|
-
* or any other registry. The list methods carry the shared cursor contract verbatim;
|
|
4385
|
+
* MCP owns no storage and no template engine. The host may back this port with memory, a
|
|
4386
|
+
* workspace, a database, or any other registry. The list methods carry the shared cursor contract verbatim;
|
|
4327
4387
|
* `resource` returns `undefined` when the URI does not resolve and may instead return an
|
|
4328
4388
|
* {@link MCPInputResult} for a modern multi-round interaction.
|
|
4329
4389
|
*/
|
|
@@ -4363,7 +4423,10 @@ export declare interface MCPResourcePage extends MCPPaginationResult {
|
|
|
4363
4423
|
readonly resources: readonly MCPResource[];
|
|
4364
4424
|
}
|
|
4365
4425
|
|
|
4366
|
-
/**
|
|
4426
|
+
/**
|
|
4427
|
+
* Represents the parameters `resources/read` accepts — a concrete `uri` plus the optional
|
|
4428
|
+
* multi-round continuation carriers.
|
|
4429
|
+
*/
|
|
4367
4430
|
export declare interface MCPResourceReadParams {
|
|
4368
4431
|
readonly uri: string;
|
|
4369
4432
|
readonly inputResponses?: Readonly<Record<string, unknown>>;
|
|
@@ -4379,7 +4442,13 @@ export declare type MCPResourceReadResult = {
|
|
|
4379
4442
|
readonly _meta?: MCPResultMetaObject;
|
|
4380
4443
|
};
|
|
4381
4444
|
|
|
4382
|
-
/**
|
|
4445
|
+
/**
|
|
4446
|
+
* Represents one RFC 6570 resource-template descriptor advertised by `resources/templates/list`.
|
|
4447
|
+
*
|
|
4448
|
+
* @remarks
|
|
4449
|
+
* The `uriTemplate` member is published as a string and forwarded verbatim: this package never
|
|
4450
|
+
* parses or expands it, and no RFC 6570 level is implied.
|
|
4451
|
+
*/
|
|
4383
4452
|
export declare interface MCPResourceTemplate {
|
|
4384
4453
|
readonly uriTemplate: string;
|
|
4385
4454
|
readonly name: string;
|
|
@@ -4404,7 +4473,12 @@ export declare interface MCPResourceTemplatePage extends MCPPaginationResult {
|
|
|
4404
4473
|
readonly resourceTemplates: readonly MCPResourceTemplate[];
|
|
4405
4474
|
}
|
|
4406
4475
|
|
|
4407
|
-
/**
|
|
4476
|
+
/**
|
|
4477
|
+
* Represents a completion reference to one resource-template URI descriptor.
|
|
4478
|
+
*
|
|
4479
|
+
* @remarks
|
|
4480
|
+
* The `uri` member may itself be a template, and it is forwarded to the host verbatim.
|
|
4481
|
+
*/
|
|
4408
4482
|
export declare interface MCPResourceTemplateReference {
|
|
4409
4483
|
readonly type: 'ref/resource';
|
|
4410
4484
|
readonly uri: string;
|
|
@@ -4414,7 +4488,7 @@ export declare interface MCPResourceTemplateReference {
|
|
|
4414
4488
|
* Represents one modern MCP result — the open contract every dated-revision result satisfies.
|
|
4415
4489
|
*
|
|
4416
4490
|
* @remarks
|
|
4417
|
-
* The dated schema requires a `resultType` on
|
|
4491
|
+
* The dated schema requires a `resultType` on every modern result and leaves the
|
|
4418
4492
|
* rest of the object open, so this contract does the same: `resultType` is a string
|
|
4419
4493
|
* rather than a closed union because the protocol keeps issuing new ones (`task`
|
|
4420
4494
|
* alongside `complete` and `input_required`), and the index signature is the
|
|
@@ -4423,7 +4497,7 @@ export declare interface MCPResourceTemplateReference {
|
|
|
4423
4497
|
* Concrete results — {@link MCPCallResult}, {@link MCPDiscoverResult},
|
|
4424
4498
|
* {@link MCPListResult}, {@link MCPPromptListResult}, {@link MCPPromptGetResult},
|
|
4425
4499
|
* {@link MCPCompletionResult}, {@link MCPInputResult}, and
|
|
4426
|
-
* {@link MCPSubscriptionResult} — stay
|
|
4500
|
+
* {@link MCPSubscriptionResult} — stay closed and keep their literal
|
|
4427
4501
|
* `resultType`, so a caller that knows which method it called still narrows to a
|
|
4428
4502
|
* literal through that result's guard. Openness lives here, at the arm a server may
|
|
4429
4503
|
* answer any registered method through, and nowhere else.
|
|
@@ -4464,7 +4538,7 @@ export declare interface MCPRootResult {
|
|
|
4464
4538
|
*
|
|
4465
4539
|
* @remarks
|
|
4466
4540
|
* The dated schema's `SamplingMessageContentBlock`: the text, image, and audio blocks
|
|
4467
|
-
* {@link MCPContent} also admits, plus the
|
|
4541
|
+
* {@link MCPContent} also admits, plus the tool blocks a tool-using model produces. The
|
|
4468
4542
|
* resource arms of {@link MCPContent} are deliberately absent — the schema leaves them out of
|
|
4469
4543
|
* a sampling completion.
|
|
4470
4544
|
*/
|
|
@@ -4490,7 +4564,7 @@ export declare interface MCPSampleResult {
|
|
|
4490
4564
|
}
|
|
4491
4565
|
|
|
4492
4566
|
/**
|
|
4493
|
-
* Dispatches JSON-RPC 2.0 requests over a live {@link ToolManagerInterface}, with
|
|
4567
|
+
* Dispatches JSON-RPC 2.0 requests over a live {@link ToolManagerInterface}, with no
|
|
4494
4568
|
* transport coupling.
|
|
4495
4569
|
*
|
|
4496
4570
|
* @remarks
|
|
@@ -4500,7 +4574,7 @@ export declare interface MCPSampleResult {
|
|
|
4500
4574
|
* `handle(message)` is the string boundary: it
|
|
4501
4575
|
* `JSON.parse`s the raw message (a failure → a `-32700` response), narrows it to
|
|
4502
4576
|
* an invocation (a non-invocation → a `-32600` response, with the unreadable `id`
|
|
4503
|
-
*
|
|
4577
|
+
* omitted rather than nulled), dispatches, and serializes the
|
|
4504
4578
|
* response back to a string (`undefined` for a notification).
|
|
4505
4579
|
* - **One modern seam.** `server/discover`, `tools/list`, `tools/call`, and
|
|
4506
4580
|
* `subscriptions/listen` are always registered; `resources/*`, `prompts/*`, and
|
|
@@ -4561,8 +4635,8 @@ export declare type MCPServerCapabilities = Readonly<Record<string, MCPMetaObjec
|
|
|
4561
4635
|
* through `server.emitter.on`.
|
|
4562
4636
|
*
|
|
4563
4637
|
* @remarks
|
|
4564
|
-
* `request` fires at the
|
|
4565
|
-
* (
|
|
4638
|
+
* `request` fires at the top of every `dispatch` with the method, correlating id
|
|
4639
|
+
* (absent for a notification, which has none), and structurally selected wire era, before the
|
|
4566
4640
|
* method runs — so an observer sees every inbound call. Listener isolation is the emitter's: a
|
|
4567
4641
|
* listener throw is routed to the emitter's `error` handler (the `error` option),
|
|
4568
4642
|
* never onto this map, so a buggy observer can never corrupt a dispatch. Declared as
|
|
@@ -4577,14 +4651,14 @@ export declare type MCPServerEventMap = {
|
|
|
4577
4651
|
* Fires ahead of the `_meta` bound check, so an observer sees a call the server is about
|
|
4578
4652
|
* to refuse for exceeding its metadata budget exactly as it sees one that passes — an
|
|
4579
4653
|
* observation surface that skipped the refused calls could not be used to account for
|
|
4580
|
-
* inbound traffic. Only
|
|
4654
|
+
* inbound traffic. Only scalars are reported: nothing read out of the request graph
|
|
4581
4655
|
* escapes here, so a listener can never observe a value the ownership seam has not yet
|
|
4582
4656
|
* bounded.
|
|
4583
4657
|
*
|
|
4584
4658
|
* Not every reported invocation arrived from a peer. A modern `tools/call` reaching the
|
|
4585
|
-
* HTTP POST handler (`createMCPPostHandler`) reports the
|
|
4659
|
+
* HTTP POST handler (`createMCPPostHandler`) reports the synthetic `tools/list` that
|
|
4586
4660
|
* handler dispatches to read the called tool's `x-mcp-header` annotations, ahead of the
|
|
4587
|
-
* call itself. Each carries the
|
|
4661
|
+
* call itself. Each carries the reserved id `0`, and one fires per page the handler
|
|
4588
4662
|
* walks, up to {@link MCP_LOOKUP_PAGES}. So an observer accounting for inbound traffic
|
|
4589
4663
|
* subtracts a `('tools/list', 0, 'modern')` that precedes a `tools/call`, and one
|
|
4590
4664
|
* tracing the server's own work keeps it. The id is reserved by convention rather than
|
|
@@ -4592,7 +4666,7 @@ export declare type MCPServerEventMap = {
|
|
|
4592
4666
|
*/
|
|
4593
4667
|
readonly request: readonly [method: string, id: JSONRPCId | undefined, era: MCPEra];
|
|
4594
4668
|
/**
|
|
4595
|
-
* Reports an operational fault the server
|
|
4669
|
+
* Reports an operational fault the server contained — the caught value, exactly once per
|
|
4596
4670
|
* fault.
|
|
4597
4671
|
*
|
|
4598
4672
|
* @remarks
|
|
@@ -4602,11 +4676,11 @@ export declare type MCPServerEventMap = {
|
|
|
4602
4676
|
* fault surfaced while a bound {@link MCPTransportInterface} was piping a reply out (a
|
|
4603
4677
|
* `send` throw or rejection from `bindServer`).
|
|
4604
4678
|
*
|
|
4605
|
-
* This is the
|
|
4606
|
-
* construction, so an operator who wants to know
|
|
4679
|
+
* This is the one place a caught detail is legible. The wire answer is detail-free by
|
|
4680
|
+
* construction, so an operator who wants to know why a request failed subscribes here;
|
|
4607
4681
|
* a peer never learns it. Payload typed `unknown` because a thrown value is.
|
|
4608
4682
|
*
|
|
4609
|
-
* A
|
|
4683
|
+
* A domain event, distinct from the emitter's own listener-error channel: a listener
|
|
4610
4684
|
* that throws while observing this event is routed to the emitter's `error` handler
|
|
4611
4685
|
* (the `error` option) and never back onto this map.
|
|
4612
4686
|
*/
|
|
@@ -4615,21 +4689,21 @@ export declare type MCPServerEventMap = {
|
|
|
4615
4689
|
|
|
4616
4690
|
/**
|
|
4617
4691
|
* Dispatches JSON-RPC 2.0 modern requests over a live
|
|
4618
|
-
* {@link ToolManagerInterface}, with
|
|
4692
|
+
* {@link ToolManagerInterface}, with no transport coupling (a transport layer
|
|
4619
4693
|
* pumps strings through `handle`).
|
|
4620
4694
|
*
|
|
4621
4695
|
* @remarks
|
|
4622
|
-
* - **`dispatch` and `handle`.** `dispatch(invocation)` is the
|
|
4696
|
+
* - **`dispatch` and `handle`.** `dispatch(invocation)` is the typed core: it takes an
|
|
4623
4697
|
* already-parsed {@link JSONRPCInvocation}, runs the method, and resolves a
|
|
4624
4698
|
* {@link JSONRPCResponse} — or an {@link MCPStream} for a held-open modern method — for
|
|
4625
4699
|
* a {@link JSONRPCRequest}, and `undefined` for a {@link JSONRPCNotification}. Its
|
|
4626
4700
|
* overloads say exactly that, so a caller dispatching a request never handles an
|
|
4627
4701
|
* `undefined` answer and a caller dispatching a notification never handles a response.
|
|
4628
|
-
* `handle(message)` is the
|
|
4702
|
+
* `handle(message)` is the string boundary: it `JSON.parse`s the raw message, narrows it
|
|
4629
4703
|
* to an invocation, dispatches, and serializes the answer back to a string (or an
|
|
4630
4704
|
* {@link MCPTextStream}, the same sequence already serialized) — turning a parse failure
|
|
4631
4705
|
* into a `-32700` response and a non-invocation into a `-32600` response, and returning
|
|
4632
|
-
* `undefined` for a notification. Both error envelopes
|
|
4706
|
+
* `undefined` for a notification. Both error envelopes omit the `id` they could not read.
|
|
4633
4707
|
* - **One method seam.** Every modern method — the built-in `server/discover` /
|
|
4634
4708
|
* `tools/list` / `tools/call` / `subscriptions/listen` and configured resource methods
|
|
4635
4709
|
* included — is registered on `methods` and dispatched
|
|
@@ -4651,7 +4725,7 @@ export declare interface MCPServerInterface extends MCPDispatcherInterface {
|
|
|
4651
4725
|
* @remarks
|
|
4652
4726
|
* Derived from {@link MCPServerOptions.limit} at construction and stored nowhere else, so
|
|
4653
4727
|
* it cannot drift from the value the boundary checks read. It is published because the
|
|
4654
|
-
* code in front of the server needs the
|
|
4728
|
+
* code in front of the server needs the same number: a binder that decodes an inbound
|
|
4655
4729
|
* message before handing it on must refuse at the byte the server would have refused at,
|
|
4656
4730
|
* and the alternative — a second configured copy of one bound, on the binder's own options
|
|
4657
4731
|
* — is a second number that will disagree the first time either is changed.
|
|
@@ -4661,11 +4735,11 @@ export declare interface MCPServerInterface extends MCPDispatcherInterface {
|
|
|
4661
4735
|
* Dispatches an already-parsed request — runs its method and resolves its answer.
|
|
4662
4736
|
*
|
|
4663
4737
|
* @remarks
|
|
4664
|
-
* A held-open modern method answers with a
|
|
4738
|
+
* A held-open modern method answers with a controlled stream instead of a response:
|
|
4665
4739
|
* narrow a stream from a response with `Symbol.asyncIterator in answer`. Whatever the method
|
|
4666
4740
|
* produced, what leaves here is an {@link MCPStreamControllerInterface} — dispatch is
|
|
4667
4741
|
* the one wrapping seam — so a caller may end the exchange promptly without waiting on
|
|
4668
|
-
* the producer. `options` is optional, so a caller that cannot abort
|
|
4742
|
+
* the producer. `options` is optional, so a caller that cannot abort never
|
|
4669
4743
|
* supplies one; dispatch resolves the signal every method observes.
|
|
4670
4744
|
*
|
|
4671
4745
|
* @param request - The parsed JSON-RPC request to dispatch
|
|
@@ -4687,7 +4761,7 @@ export declare interface MCPServerInterface extends MCPDispatcherInterface {
|
|
|
4687
4761
|
* @remarks
|
|
4688
4762
|
* The union arm a transport uses when it has narrowed a message no further than
|
|
4689
4763
|
* {@link JSONRPCInvocation}. A value that is not structurally an invocation at
|
|
4690
|
-
*
|
|
4764
|
+
* runtime — which only a caller defeating these types can produce — answers a
|
|
4691
4765
|
* `-32600` error response with no `id`.
|
|
4692
4766
|
*
|
|
4693
4767
|
* @param invocation - The parsed JSON-RPC invocation to dispatch
|
|
@@ -4701,13 +4775,13 @@ export declare interface MCPServerInterface extends MCPDispatcherInterface {
|
|
|
4701
4775
|
* @remarks
|
|
4702
4776
|
* A `JSON.parse` failure resolves a serialized `-32700` (Parse error) response;
|
|
4703
4777
|
* a parsed value that is not a valid invocation resolves a serialized `-32600`
|
|
4704
|
-
* (Invalid Request) response — each with its unreadable `id`
|
|
4778
|
+
* (Invalid Request) response — each with its unreadable `id` omitted, never `null`;
|
|
4705
4779
|
* a notification resolves `undefined` (no response). A
|
|
4706
4780
|
* held-open method resolves an {@link MCPTextStreamControllerInterface} — the controlled
|
|
4707
4781
|
* typed stream's mirror, already serialized — so a transport writes each message with no
|
|
4708
4782
|
* second parse and can still end the exchange it is writing.
|
|
4709
4783
|
*
|
|
4710
|
-
* The vague-verb prohibition (`process`, `handle`) governs
|
|
4784
|
+
* The vague-verb prohibition (`process`, `handle`) governs standalone helpers,
|
|
4711
4785
|
* which carry no entity to supply their object. Here the entity does: `server.handle`
|
|
4712
4786
|
* reads as "the server handles this message", and it is the string-boundary twin of
|
|
4713
4787
|
* {@link dispatch} — one verb per entry point, the same act at the typed and string levels.
|
|
@@ -4766,7 +4840,7 @@ export declare interface MCPServerOptions {
|
|
|
4766
4840
|
* Holds the optional explicit execution policy above the canonical live tool registry.
|
|
4767
4841
|
*
|
|
4768
4842
|
* @remarks
|
|
4769
|
-
* This is also the
|
|
4843
|
+
* This is also the only way a tool observes cancellation. The default path calls
|
|
4770
4844
|
* {@link ToolManagerInterface.execute}, whose signature takes a call and nothing else, so
|
|
4771
4845
|
* there is no seam to hand a signal through — a server with no `execution` runs its tool to
|
|
4772
4846
|
* completion even after the request that asked for it has ended, and abandons the result.
|
|
@@ -4799,7 +4873,7 @@ export declare interface MCPServerOptions {
|
|
|
4799
4873
|
*
|
|
4800
4874
|
* @remarks
|
|
4801
4875
|
* Omitting it leaves every existing path untouched — nothing is advertised, no call is
|
|
4802
|
-
* deferred, and `tasks/*` stays unregistered. The extension is the
|
|
4876
|
+
* deferred, and `tasks/*` stays unregistered. The extension is the stable, immutable
|
|
4803
4877
|
* snapshot dated 2026-07-28, so the shape this option admits is fixed.
|
|
4804
4878
|
*/
|
|
4805
4879
|
readonly task?: MCPTaskOptions;
|
|
@@ -4812,14 +4886,14 @@ export declare interface MCPServerOptions {
|
|
|
4812
4886
|
* `return` value is the terminating response.
|
|
4813
4887
|
*
|
|
4814
4888
|
* @remarks
|
|
4815
|
-
* A stream yields
|
|
4889
|
+
* A stream yields notifications and never requests — the yield type forbids an `id`,
|
|
4816
4890
|
* so a producer cannot put a call the peer is expected to answer onto a stream that
|
|
4817
4891
|
* has no way to carry the answer back.
|
|
4818
4892
|
*
|
|
4819
|
-
* Held-open closure is a
|
|
4893
|
+
* Held-open closure is a result in the modern revision, not an out-of-band event, so it
|
|
4820
4894
|
* arrives where a result arrives — the generator's `return`. Consuming a stream and
|
|
4821
4895
|
* consuming a unary response therefore end the same way, and a transport narrows a stream
|
|
4822
|
-
* from a response at
|
|
4896
|
+
* from a response at one point (`Symbol.asyncIterator in answer`), at the place that already pumps
|
|
4823
4897
|
* messages onto the wire. The `TNext` type parameter is stated explicitly because a stream
|
|
4824
4898
|
* accepts nothing back from its consumer.
|
|
4825
4899
|
*/
|
|
@@ -4830,16 +4904,16 @@ export declare type MCPStream = AsyncGenerator<JSONRPCNotification, JSONRPCRespo
|
|
|
4830
4904
|
* through.
|
|
4831
4905
|
*
|
|
4832
4906
|
* @remarks
|
|
4833
|
-
* A native async generator decides cancellation with a
|
|
4907
|
+
* A native async generator decides cancellation with a queue: `return()` and `throw()` wait
|
|
4834
4908
|
* behind a `next()` the producer has not answered, so a consumer abandoning a source parked
|
|
4835
4909
|
* on an event that will never arrive waits forever for its own cancellation. This class
|
|
4836
|
-
* arbitrates instead of queueing. It keeps at most
|
|
4837
|
-
* settles the consumer's read itself, aborts the request's lifetime
|
|
4910
|
+
* arbitrates instead of queueing. It keeps at most one read outstanding against the source,
|
|
4911
|
+
* settles the consumer's read itself, aborts the request's lifetime before it delegates
|
|
4838
4912
|
* cleanup to the producer — so a cooperating producer is woken rather than waited on —
|
|
4839
4913
|
* contains every promise the producer settles late, and makes every closure path idempotent.
|
|
4840
4914
|
*
|
|
4841
4915
|
* The closures are deliberately different answers: the source's own return is the
|
|
4842
|
-
* terminal
|
|
4916
|
+
* terminal response, `return(value)` is the consumer saying it has the answer already, and
|
|
4843
4917
|
* {@link stop} is an owner saying there will be no answer at all. Only the source's own
|
|
4844
4918
|
* return is a message a peer ever sees.
|
|
4845
4919
|
*
|
|
@@ -4847,7 +4921,7 @@ export declare type MCPStream = AsyncGenerator<JSONRPCNotification, JSONRPCRespo
|
|
|
4847
4921
|
* generator is suspended inside, so the signal is how an uncooperative producer is asked to
|
|
4848
4922
|
* finish, and this controller never blocks its consumer on the answer.
|
|
4849
4923
|
*
|
|
4850
|
-
* **What this class does
|
|
4924
|
+
* **What this class does not have is an owner of last resort.** No finalizer, no timer, no
|
|
4851
4925
|
* timeout ends an exchange nobody released. That absence is the design: an exchange holds a
|
|
4852
4926
|
* producer, a request lifetime and a live server slot, so a silent background release would
|
|
4853
4927
|
* turn "a pump forgot its obligation" from a reproducible defect into a nondeterministic one,
|
|
@@ -4933,28 +5007,28 @@ export declare class MCPStreamController implements MCPStreamControllerInterface
|
|
|
4933
5007
|
}
|
|
4934
5008
|
|
|
4935
5009
|
/**
|
|
4936
|
-
* Represents a held-open modern result whose cancellation
|
|
5010
|
+
* Represents a held-open modern result whose cancellation one owner arbitrates — the arm
|
|
4937
5011
|
* every stream leaving `MCPServer.dispatch` takes.
|
|
4938
5012
|
*
|
|
4939
5013
|
* @remarks
|
|
4940
5014
|
* The generator protocol states what a stream yields and says nothing about who ends one,
|
|
4941
|
-
* and a native async generator answers that badly: `return()` and `throw()`
|
|
5015
|
+
* and a native async generator answers that badly: `return()` and `throw()` queue behind a
|
|
4942
5016
|
* `next()` the producer has not answered yet, so a consumer walking away from a source
|
|
4943
5017
|
* parked on an event that will never arrive waits forever for its own cancellation. A
|
|
4944
|
-
* controller settles the consumer's read
|
|
5018
|
+
* controller settles the consumer's read itself, aborts the request's signal before it
|
|
4945
5019
|
* delegates cleanup to the producer, contains every promise the producer settles late, and
|
|
4946
5020
|
* makes every closure path idempotent.
|
|
4947
5021
|
*
|
|
4948
|
-
* {@link stop} is the operation the protocol has no member for: end the exchange with
|
|
5022
|
+
* {@link stop} is the operation the protocol has no member for: end the exchange with no
|
|
4949
5023
|
* terminal, from an owner that is not the consumer of the iteration — a transport whose
|
|
4950
5024
|
* connection closed, a pump whose write failed. `return(value)` says "here is the answer";
|
|
4951
5025
|
* `stop()` says "there will be no answer", and that is exactly the difference a cancelled
|
|
4952
5026
|
* request and a completed one must not blur.
|
|
4953
5027
|
*
|
|
4954
|
-
* **Ending a controlled exchange is the obligation of whoever is handed it, on
|
|
5028
|
+
* **Ending a controlled exchange is the obligation of whoever is handed it, on every exit —
|
|
4955
5029
|
* including the exits where nothing was cancelled.** One of these holds a producer, a request
|
|
4956
5030
|
* lifetime, and (for the built-in `subscriptions/listen`) one of a finite number of live
|
|
4957
|
-
* server slots, and a consumer that
|
|
5031
|
+
* server slots, and a consumer that walks away releases none of them: no signal fires
|
|
4958
5032
|
* when nobody aborts anything. So an owner releases through {@link stop} or
|
|
4959
5033
|
* {@link MCPStreamControllerInterface.[Symbol.asyncDispose] | asyncDispose} on the normal
|
|
4960
5034
|
* return, on a mid-loop throw, and on a transport that closed underneath the pump alike —
|
|
@@ -4962,10 +5036,10 @@ export declare class MCPStreamController implements MCPStreamControllerInterface
|
|
|
4962
5036
|
* floor, is for.
|
|
4963
5037
|
*
|
|
4964
5038
|
* A conforming {@link MCPStreamControllerInterface.[Symbol.asyncDispose] | asyncDispose}
|
|
4965
|
-
* releases the producer, request lifetime, and live slot
|
|
5039
|
+
* releases the producer, request lifetime, and live slot before it may reject. Throwing before
|
|
4966
5040
|
* release would let a disposal fault mask the pump's original failure while leaking the exchange.
|
|
4967
5041
|
*
|
|
4968
|
-
* There is deliberately
|
|
5042
|
+
* There is deliberately no owner of last resort — no finalizer, no timer, no timeout. One
|
|
4969
5043
|
* would convert a missing obligation into a nondeterministic one and hide the very defect
|
|
4970
5044
|
* this sentence exists to make visible, and GC timing is not a lifecycle.
|
|
4971
5045
|
*/
|
|
@@ -4974,7 +5048,7 @@ export declare interface MCPStreamControllerInterface extends MCPStream {
|
|
|
4974
5048
|
* Reads the next notification, or the terminating response that ends the exchange.
|
|
4975
5049
|
*
|
|
4976
5050
|
* @remarks
|
|
4977
|
-
* At most
|
|
5051
|
+
* At most one read is outstanding against the producer, and a rival read is refused
|
|
4978
5052
|
* rather than queued: two live consumers on one held-open answer would split a sequence
|
|
4979
5053
|
* neither could reassemble. A read parked on the producer settles the moment the exchange
|
|
4980
5054
|
* closes, however long the producer takes to notice.
|
|
@@ -5026,11 +5100,11 @@ export declare interface MCPStreamControllerInterface extends MCPStream {
|
|
|
5026
5100
|
* Names the notification families a client may opt in to on a `subscriptions/listen` stream.
|
|
5027
5101
|
*
|
|
5028
5102
|
* @remarks
|
|
5029
|
-
* Every key here is a
|
|
5103
|
+
* Every key here is a wire spelling, carried verbatim from the dated schema's
|
|
5030
5104
|
* `params.notifications` object. They are the one place in this file where the
|
|
5031
5105
|
* compound-key prohibition does not apply, because these strings are not this
|
|
5032
5106
|
* package's to choose: grouping them into `{ tools: { changed } }` would read better
|
|
5033
|
-
* and would speak a protocol no peer implements. The type
|
|
5107
|
+
* and would speak a protocol no peer implements. The type name is the library's own
|
|
5034
5108
|
* and takes the `MCP` prefix; the keys are the protocol's and do not change.
|
|
5035
5109
|
*/
|
|
5036
5110
|
export declare interface MCPSubscriptionFilter {
|
|
@@ -5047,17 +5121,17 @@ export declare interface MCPSubscriptionFilter {
|
|
|
5047
5121
|
*
|
|
5048
5122
|
* @remarks
|
|
5049
5123
|
* The wire placement is `params.notifications.taskIds`, beside `resourceSubscriptions`,
|
|
5050
|
-
* and that placement is
|
|
5124
|
+
* and that placement is this package's reading rather than a settled fact: the Tasks
|
|
5051
5125
|
* extension declares the fragment carrying this member without composing it into the
|
|
5052
5126
|
* `subscriptions/listen` request, so no source states where the fragment lands. The
|
|
5053
5127
|
* spelling itself is the schema's and is carried verbatim under the same wire-key
|
|
5054
5128
|
* exemption as its siblings.
|
|
5055
5129
|
*
|
|
5056
|
-
* The server honours the member only when a consumer configured
|
|
5130
|
+
* The server honours the member only when a consumer configured both a task manager and
|
|
5057
5131
|
* a subscription producer: the manager resolves each requested identifier before the
|
|
5058
5132
|
* acknowledgement agrees to it, and the producer is what a transition frame arrives
|
|
5059
5133
|
* through. Either one missing leaves nothing to deliver, so the acknowledgement omits
|
|
5060
|
-
* the member. That fact is
|
|
5134
|
+
* the member. That fact is derived from the configured options at the moment the
|
|
5061
5135
|
* listen request is answered; no third flag records it, so it cannot drift from them.
|
|
5062
5136
|
*/
|
|
5063
5137
|
readonly taskIds?: readonly string[];
|
|
@@ -5108,14 +5182,14 @@ export declare type MCPSubscriptionStream = AsyncGenerator<JSONRPCNotification,
|
|
|
5108
5182
|
* with.
|
|
5109
5183
|
*
|
|
5110
5184
|
* @remarks
|
|
5111
|
-
* Every field name here is a
|
|
5112
|
-
* schema, so the compound-member prohibition does not reach them; the type
|
|
5185
|
+
* Every field name here is a wire spelling carried verbatim from the extension's
|
|
5186
|
+
* schema, so the compound-member prohibition does not reach them; the type name is
|
|
5113
5187
|
* this library's own. `ttlMs` is `null` — not absent — when the task has no expiry,
|
|
5114
5188
|
* because the schema distinguishes absence from `null`. `createdAt` and `lastUpdatedAt` are
|
|
5115
5189
|
* described as ISO 8601 instants, though the generated schema validates only a
|
|
5116
5190
|
* string, so this package carries whatever the manager produced without reformatting
|
|
5117
5191
|
* it. `pollIntervalMs` is the manager's hint about how often the client can ask
|
|
5118
|
-
* again; a manager that pushes notifications instead
|
|
5192
|
+
* again; a manager that pushes notifications instead omits it.
|
|
5119
5193
|
*/
|
|
5120
5194
|
export declare type MCPTask = {
|
|
5121
5195
|
/** Holds the durable handle a later `tasks/get` / `tasks/update` / `tasks/cancel` names. */
|
|
@@ -5132,19 +5206,19 @@ export declare type MCPTask = {
|
|
|
5132
5206
|
};
|
|
5133
5207
|
|
|
5134
5208
|
/**
|
|
5135
|
-
* Issues the `tasks/*` methods over one correlated-request door — the
|
|
5209
|
+
* Issues the `tasks/*` methods over one correlated-request door — the client half of the
|
|
5136
5210
|
* stable Tasks extension, exposed as an {@link import('./types.js').MCPClientInterface}'s
|
|
5137
5211
|
* `tasks`.
|
|
5138
5212
|
*
|
|
5139
5213
|
* @remarks
|
|
5140
5214
|
* - **The mirror of the server-side port, minus `start`.** An
|
|
5141
5215
|
* {@link import('./types.js').MCPTaskManagerInterface} is the consumer's durable store the
|
|
5142
|
-
*
|
|
5216
|
+
* server creates tasks in; this is the client's read/answer/stop access to the tasks a peer
|
|
5143
5217
|
* already created. Creation is missing on purpose: the extension gives a client no flag and
|
|
5144
5218
|
* no parameter to ask for a task, so `start` has no wire method to be.
|
|
5145
5219
|
* - **No plural accessor, no loop, no cache.** MCP defines no `tasks/list`, so nothing here
|
|
5146
5220
|
* enumerates. A task snapshot's `pollIntervalMs` is carried untouched and a one-shot read
|
|
5147
|
-
* sits beside it; the
|
|
5221
|
+
* sits beside it; the schedule is the consumer's, because this package has no durable place
|
|
5148
5222
|
* to keep a task, no idea when the application still cares, and no lifetime to hang a timer
|
|
5149
5223
|
* on that outlives the request it was born from. An instance left alone writes nothing.
|
|
5150
5224
|
* - **One channel.** Every request goes through the injected
|
|
@@ -5176,16 +5250,16 @@ export declare class MCPTaskClient implements MCPTaskClientInterface {
|
|
|
5176
5250
|
}
|
|
5177
5251
|
|
|
5178
5252
|
/**
|
|
5179
|
-
* Reads, answers, and stops a durable task the peer created — the
|
|
5253
|
+
* Reads, answers, and stops a durable task the peer created — the client half of the stable
|
|
5180
5254
|
* Tasks extension.
|
|
5181
5255
|
*
|
|
5182
5256
|
* @remarks
|
|
5183
5257
|
* The mirror of {@link MCPTaskManagerInterface} minus `start`, because creating a task is
|
|
5184
5258
|
* never the client's decision: the extension gives a client no flag and no parameter to ask
|
|
5185
|
-
* for one, and a task exists only because the
|
|
5259
|
+
* for one, and a task exists only because the server deferred a `tools/call` it received. The
|
|
5186
5260
|
* methods that remain are the `tasks/*` methods on the wire.
|
|
5187
5261
|
*
|
|
5188
|
-
* There is deliberately
|
|
5262
|
+
* There is deliberately no plural accessor, for the same reason the server-side port has none:
|
|
5189
5263
|
* the extension defines no `tasks/list`, and an accessor that could enumerate tasks would
|
|
5190
5264
|
* invite one. The absence is how this contract states that.
|
|
5191
5265
|
*
|
|
@@ -5210,13 +5284,13 @@ export declare interface MCPTaskClientInterface {
|
|
|
5210
5284
|
* Reads one durable task's current snapshot.
|
|
5211
5285
|
*
|
|
5212
5286
|
* @remarks
|
|
5213
|
-
*
|
|
5287
|
+
* rejects rather than answering `undefined` for a task it cannot read. The peer's refusal
|
|
5214
5288
|
* is byte-identical across a task that never existed, one whose TTL purged it, and one this
|
|
5215
5289
|
* caller is not entitled to see — that indistinguishability is the extension's whole
|
|
5216
5290
|
* anti-enumeration property — so manufacturing a lookup-miss here would mean matching on
|
|
5217
5291
|
* the peer's message text and publishing a difference the peer refused to publish.
|
|
5218
5292
|
*
|
|
5219
|
-
* The peer's payload is carried
|
|
5293
|
+
* The peer's payload is carried verbatim once it proves well-formed. A modern result's own
|
|
5220
5294
|
* `resultType: 'complete'` and `_meta` stamps therefore ride along on the snapshot, because
|
|
5221
5295
|
* rebuilding the object to drop them would also drop the unrecognized members this
|
|
5222
5296
|
* package deliberately preserves.
|
|
@@ -5237,7 +5311,7 @@ export declare interface MCPTaskClientInterface {
|
|
|
5237
5311
|
*
|
|
5238
5312
|
* @remarks
|
|
5239
5313
|
* The responses are keyed by the request keys the task itself published, and they travel
|
|
5240
|
-
*
|
|
5314
|
+
* verbatim: a key the task does not recognize, or has already answered, is the manager's to
|
|
5241
5315
|
* ignore rather than this client's to refuse. A partial set of answers is legal.
|
|
5242
5316
|
*
|
|
5243
5317
|
* @param id - The `taskId` the responses belong to
|
|
@@ -5255,14 +5329,14 @@ export declare interface MCPTaskClientInterface {
|
|
|
5255
5329
|
* Asks one durable task to stop.
|
|
5256
5330
|
*
|
|
5257
5331
|
* @remarks
|
|
5258
|
-
*
|
|
5332
|
+
* advisory, exactly like the server-side port it mirrors: the acknowledgement reports that
|
|
5259
5333
|
* the request was accepted, never that the task stopped, and a task whose work cannot be
|
|
5260
5334
|
* interrupted may legally reach `completed` afterwards. Read the task again to learn what
|
|
5261
5335
|
* happened.
|
|
5262
5336
|
*
|
|
5263
5337
|
* This is a different mechanism from `call`'s `options.signal`, which withdraws one caller
|
|
5264
5338
|
* from one in-flight request and never reaches a task. A call that already answered
|
|
5265
|
-
* `resultType: 'task'` is a request that is
|
|
5339
|
+
* `resultType: 'task'` is a request that is over; only this method reaches the work it left
|
|
5266
5340
|
* behind.
|
|
5267
5341
|
*
|
|
5268
5342
|
* @param id - The `taskId` to stop
|
|
@@ -5298,14 +5372,14 @@ export declare interface MCPTaskClientOptions {
|
|
|
5298
5372
|
* {@link MCPTaskManagerInterface.start}.
|
|
5299
5373
|
*
|
|
5300
5374
|
* @remarks
|
|
5301
|
-
* It carries
|
|
5302
|
-
* omission. The signal on the accompanying {@link MCPMethodOptions} is the
|
|
5375
|
+
* It carries no cancellation signal, and that absence is deliberate rather than an
|
|
5376
|
+
* omission. The signal on the accompanying {@link MCPMethodOptions} is the request's
|
|
5303
5377
|
* lifetime, and a deferred request ends the moment its `resultType: 'task'` answer is
|
|
5304
5378
|
* written — a transport aborts it as soon as the response body is flushed. A manager
|
|
5305
5379
|
* that plumbs `options.signal` into the task's work therefore loses every task it
|
|
5306
5380
|
* creates, milliseconds after creating it, and the loss looks exactly like a client
|
|
5307
5381
|
* that disconnected. Use `options.signal` for work that must finish before the
|
|
5308
|
-
*
|
|
5382
|
+
* answer is written, and give the task's own work a lifetime the manager owns.
|
|
5309
5383
|
*
|
|
5310
5384
|
* `call` is the canonical tool call the deferral is standing in for, so a manager
|
|
5311
5385
|
* needs nothing from `request.params` to run the work; `request` is supplied whole
|
|
@@ -5327,7 +5401,7 @@ export declare interface MCPTaskContext {
|
|
|
5327
5401
|
* `completed` carries the deferred call's result, `failed` carries the JSON-RPC error
|
|
5328
5402
|
* that ended it, and `working` / `cancelled` carry nothing extra. Narrow on `status`.
|
|
5329
5403
|
*
|
|
5330
|
-
* `result` is an
|
|
5404
|
+
* `result` is an open record rather than an {@link MCPResult} or an
|
|
5331
5405
|
* {@link MCPCallResult}, because the schema declares it one: a completed task's payload
|
|
5332
5406
|
* is whatever the deferred method answered, and the extension constrains nothing inside
|
|
5333
5407
|
* it — not even a `resultType`. Only `tools/call` can be deferred today, and the
|
|
@@ -5353,9 +5427,9 @@ export declare type MCPTaskDetail = (MCPTask & {
|
|
|
5353
5427
|
* Represents the wire answer to `tasks/get` — one snapshot under the completed-result stamp.
|
|
5354
5428
|
*
|
|
5355
5429
|
* @remarks
|
|
5356
|
-
*
|
|
5430
|
+
* distinct from {@link MCPTaskDetail}, and the distinction is the whole point. A detail is
|
|
5357
5431
|
* what the consumer's {@link MCPTaskManagerInterface} answers, unstamped, because a durable
|
|
5358
|
-
* store knows nothing about the request that read it. This is what a `tasks/get`
|
|
5432
|
+
* store knows nothing about the request that read it. This is what a `tasks/get` reply
|
|
5359
5433
|
* carries: the schema types that reply as the detail intersected with the standard result,
|
|
5360
5434
|
* so `resultType: 'complete'` is required rather than incidental and a peer that omits it
|
|
5361
5435
|
* has answered something other than the method's declared result.
|
|
@@ -5374,15 +5448,15 @@ export declare type MCPTaskDetailResult = MCPTaskDetail & {
|
|
|
5374
5448
|
* Decides whether the `tools/call` in hand becomes a durable task.
|
|
5375
5449
|
*
|
|
5376
5450
|
* @remarks
|
|
5377
|
-
* Deferral is entirely the
|
|
5451
|
+
* Deferral is entirely the server's decision. The extension gives a client no flag and
|
|
5378
5452
|
* no parameter to ask for a task; the client only declares that it can cope with one.
|
|
5379
5453
|
* So this handler is where the policy lives — long-running tool, queue depth, caller
|
|
5380
5454
|
* tier, time of day — and it is consulted only for a client that declared the
|
|
5381
5455
|
* capability on the request in hand.
|
|
5382
5456
|
*
|
|
5383
|
-
* The returned string is the
|
|
5457
|
+
* The returned string is the stable operation key the manager deduplicates on: the same
|
|
5384
5458
|
* logical call must produce the same key, and two different calls must not. Mint it from
|
|
5385
|
-
* the
|
|
5459
|
+
* the caller and the canonical call — never from `call.id`, which is the client's own
|
|
5386
5460
|
* JSON-RPC request id: a retry of one logical call changes it, so dedup never fires, and
|
|
5387
5461
|
* two principals whose clients both started counting at 1 collide on it.
|
|
5388
5462
|
*
|
|
@@ -5402,18 +5476,18 @@ export declare type MCPTaskHandler = (context: MCPTaskContext, options: MCPMetho
|
|
|
5402
5476
|
* package creates tasks through and reads them back from.
|
|
5403
5477
|
*
|
|
5404
5478
|
* @remarks
|
|
5405
|
-
* There is deliberately
|
|
5479
|
+
* There is deliberately no plural accessor. The extension defines no `tasks/list`, and
|
|
5406
5480
|
* a port that could enumerate tasks would invite one; the absence is how this contract
|
|
5407
5481
|
* states the non-goal.
|
|
5408
5482
|
*
|
|
5409
5483
|
* {@link task} answers `undefined` for a task that never existed, one whose TTL purged
|
|
5410
|
-
* it,
|
|
5411
|
-
*
|
|
5484
|
+
* it, and one this caller is not entitled to see. They are indistinguishable on
|
|
5485
|
+
* purpose: they all become the same `-32602`, so a `taskId` cannot be probed for
|
|
5412
5486
|
* existence. A manager that distinguishes them — by throwing for the unauthorized case,
|
|
5413
5487
|
* say — turns its own store into an enumeration oracle no matter what this package does.
|
|
5414
5488
|
*
|
|
5415
5489
|
* Every method receives the resolved per-request options and is expected to
|
|
5416
|
-
*
|
|
5490
|
+
* authorize the call itself: the extension requires authorization on each task request,
|
|
5417
5491
|
* and this package has no principal of its own to check one against.
|
|
5418
5492
|
*/
|
|
5419
5493
|
export declare interface MCPTaskManagerInterface {
|
|
@@ -5421,8 +5495,7 @@ export declare interface MCPTaskManagerInterface {
|
|
|
5421
5495
|
* Creates — or returns the existing — durable task for one stable operation key.
|
|
5422
5496
|
*
|
|
5423
5497
|
* @remarks
|
|
5424
|
-
* The obligations this package cannot enforce, and one consequence
|
|
5425
|
-
* to miss:
|
|
5498
|
+
* The obligations this package cannot enforce, and one consequence a reader can miss:
|
|
5426
5499
|
*
|
|
5427
5500
|
* - **Durability before return.** The returned task MUST already be retrievable by
|
|
5428
5501
|
* {@link task} when this resolves. This package awaits `start` before it builds the
|
|
@@ -5431,10 +5504,10 @@ export declare interface MCPTaskManagerInterface {
|
|
|
5431
5504
|
* - **A `taskId` must resist enumeration.** It is a bearer handle over a durable
|
|
5432
5505
|
* operation. Mint it from a cryptographic source; do not derive it from `key`, from
|
|
5433
5506
|
* a counter, or from anything a caller can predict.
|
|
5434
|
-
* - **Deduplicate by key, and
|
|
5507
|
+
* - **Deduplicate by key, and scope the key to its principal.** Returning the existing
|
|
5435
5508
|
* task for a repeated key is what makes a retried call idempotent. But a key that is
|
|
5436
5509
|
* not scoped to the caller means two principals submitting the same key receive the
|
|
5437
|
-
*
|
|
5510
|
+
* same task — one principal reading another's work through a handle it merely
|
|
5438
5511
|
* guessed. This package forwards `key` unchanged, exactly as the handler produced
|
|
5439
5512
|
* it, and has no principal to scope it by; the scoping belongs here, or in the
|
|
5440
5513
|
* handler that mints the key.
|
|
@@ -5449,7 +5522,7 @@ export declare interface MCPTaskManagerInterface {
|
|
|
5449
5522
|
* Reads one task's current snapshot.
|
|
5450
5523
|
*
|
|
5451
5524
|
* @remarks
|
|
5452
|
-
*
|
|
5525
|
+
* every `tasks/*` method runs through here first, not only `tasks/get`. {@link update}
|
|
5453
5526
|
* and {@link abort} answer `void`, so neither has a way to say "no such task" and neither
|
|
5454
5527
|
* can be the place authorization is decided; this is. Expect one read of the named task
|
|
5455
5528
|
* before every update and every cancellation, and expect an `undefined` answer to end that
|
|
@@ -5465,11 +5538,11 @@ export declare interface MCPTaskManagerInterface {
|
|
|
5465
5538
|
*
|
|
5466
5539
|
* @remarks
|
|
5467
5540
|
* Responses are keyed by the request keys the task published. A key the task does not
|
|
5468
|
-
* recognize, or has already been answered, is
|
|
5541
|
+
* recognize, or has already been answered, is ignored rather than refused, and a
|
|
5469
5542
|
* partial set of answers is acceptable. This package forwards the client's record
|
|
5470
|
-
*
|
|
5543
|
+
* verbatim — it holds none of the task's keys, so the ignoring is this method's to do.
|
|
5471
5544
|
*
|
|
5472
|
-
* This is the
|
|
5545
|
+
* This is the second multi-round-trip mechanism in the package, and it is the weaker one.
|
|
5473
5546
|
* The built-in input path binds each round with a sealed `requestState`, an argument digest,
|
|
5474
5547
|
* an absolute expiry, and the resolved principal; this path has none of them, because MCP
|
|
5475
5548
|
* neither issued the question nor owns the channel it is answered on. Anything equivalent
|
|
@@ -5485,7 +5558,7 @@ export declare interface MCPTaskManagerInterface {
|
|
|
5485
5558
|
* Asks one task to stop.
|
|
5486
5559
|
*
|
|
5487
5560
|
* @remarks
|
|
5488
|
-
* Cancellation is
|
|
5561
|
+
* Cancellation is cooperative: a task that has already finished, or one whose work
|
|
5489
5562
|
* cannot be interrupted, may legally reach `completed` after this resolves. The
|
|
5490
5563
|
* acknowledgement says the request was accepted, never that the task stopped.
|
|
5491
5564
|
*
|
|
@@ -5514,7 +5587,7 @@ export declare type MCPTaskNotification = JSONRPCNotification & {
|
|
|
5514
5587
|
* stamped with the subscription that delivered it.
|
|
5515
5588
|
*
|
|
5516
5589
|
* @remarks
|
|
5517
|
-
*
|
|
5590
|
+
* flat, and that is the schema's shape rather than a choice: the extension types these
|
|
5518
5591
|
* parameters as the notification envelope intersected with the detail, so every task field
|
|
5519
5592
|
* sits directly under `params` and no `task` wrapper member exists. Narrow on `status`
|
|
5520
5593
|
* exactly as with {@link MCPTaskDetail}.
|
|
@@ -5549,9 +5622,9 @@ export declare interface MCPTaskOptions {
|
|
|
5549
5622
|
* Represents the modern `tools/call` result announcing that the call became a durable task.
|
|
5550
5623
|
*
|
|
5551
5624
|
* @remarks
|
|
5552
|
-
* The only result in this package whose `resultType` is `'task'`. It is
|
|
5625
|
+
* The only result in this package whose `resultType` is `'task'`. It is flat — the
|
|
5553
5626
|
* task's fields sit beside the discriminator rather than under a `task` member — and
|
|
5554
|
-
* it carries no terminal payload, because a task
|
|
5627
|
+
* it carries no terminal payload, because a task at creation has no
|
|
5555
5628
|
* outcome yet. The outcome arrives through {@link MCPTaskDetail}.
|
|
5556
5629
|
*/
|
|
5557
5630
|
export declare type MCPTaskResult = MCPTask & {
|
|
@@ -5564,14 +5637,14 @@ export declare type MCPTaskResult = MCPTask & {
|
|
|
5564
5637
|
* Names the lifecycle state of one durable task.
|
|
5565
5638
|
*
|
|
5566
5639
|
* @remarks
|
|
5567
|
-
* `completed`, `failed`, and `cancelled` are
|
|
5640
|
+
* `completed`, `failed`, and `cancelled` are terminal: a task that reaches one never
|
|
5568
5641
|
* moves again. `failed` reports that the deferred call could not be executed at all —
|
|
5569
|
-
* a JSON-RPC-level failure. A tool that
|
|
5642
|
+
* a JSON-RPC-level failure. A tool that ran and returned an error is `completed`
|
|
5570
5643
|
* carrying an `isError: true` result, exactly as an inline `tools/call` would answer,
|
|
5571
5644
|
* because the deferral must not change what the tool's own failure means.
|
|
5572
5645
|
*
|
|
5573
5646
|
* `input_required` collides by spelling with {@link MCPInputResult}'s `resultType`
|
|
5574
|
-
* and is a
|
|
5647
|
+
* and is a different mechanism: that one suspends a live request and resumes through
|
|
5575
5648
|
* a protected `requestState` on the next `tools/call`, while this one suspends a
|
|
5576
5649
|
* durable task and resumes through `tasks/update`. Neither spelling is this package's
|
|
5577
5650
|
* to change — both are on the wire.
|
|
@@ -5602,15 +5675,15 @@ export declare type MCPTextStream = AsyncGenerator<string, string, unknown>;
|
|
|
5602
5675
|
* serialized.
|
|
5603
5676
|
*
|
|
5604
5677
|
* @remarks
|
|
5605
|
-
* A
|
|
5678
|
+
* A translation boundary and deliberately nothing else. It serializes each message and the
|
|
5606
5679
|
* terminating response, and every lifecycle decision — return, throw, dispose, stop — ends
|
|
5607
5680
|
* the typed exchange beneath it rather than this face. That is the whole design constraint: a
|
|
5608
|
-
* serialized face implemented as its own async generator would add a
|
|
5681
|
+
* serialized face implemented as its own async generator would add a second operation queue,
|
|
5609
5682
|
* and the queue is exactly the defect the typed controller exists to remove — a `return()`
|
|
5610
5683
|
* promptly settled at the text face and left queued at the typed one cancels nothing.
|
|
5611
5684
|
*
|
|
5612
5685
|
* One member is a narrowing rather than a pass-through, and it is worth knowing before it
|
|
5613
|
-
* surprises a producer. `return` receives a
|
|
5686
|
+
* surprises a producer. `return` receives a string; it cannot rebuild the typed
|
|
5614
5687
|
* `JSONRPCResponse` the typed face would close on, and inventing one by parsing the
|
|
5615
5688
|
* argument back would make this face decide what the exchange ended with. So it ends the
|
|
5616
5689
|
* typed exchange with {@link MCPStreamControllerInterface.stop} — no terminal — and answers
|
|
@@ -5619,11 +5692,11 @@ export declare type MCPTextStream = AsyncGenerator<string, string, unknown>;
|
|
|
5619
5692
|
* the honest translation of "the consumer already has its answer" when the answer is opaque
|
|
5620
5693
|
* text, not a downgrade to work around.
|
|
5621
5694
|
*
|
|
5622
|
-
* It accepts only a
|
|
5695
|
+
* It accepts only a controlled typed stream. A raw generator would have no lifecycle to
|
|
5623
5696
|
* delegate to, and this class refuses to grow one of its own.
|
|
5624
5697
|
*
|
|
5625
5698
|
* Delegation is total and it is what makes the ownership obligation transitive: `return`,
|
|
5626
|
-
* `throw`, `stop`, and dispose each end the
|
|
5699
|
+
* `throw`, `stop`, and dispose each end the typed exchange, so a pump holding only this
|
|
5627
5700
|
* serialized face still releases the producer, the request lifetime, and the live server slot
|
|
5628
5701
|
* behind it. There is no owner of last resort here either, for the same reason there is none
|
|
5629
5702
|
* on the typed face.
|
|
@@ -5658,7 +5731,7 @@ export declare class MCPTextStreamController implements MCPTextStreamControllerI
|
|
|
5658
5731
|
* @remarks
|
|
5659
5732
|
* The typed exchange ends with no terminal, because a string is not a
|
|
5660
5733
|
* `JSONRPCResponse` and this face never parses one back out of its argument. The
|
|
5661
|
-
* supplied text is the answer to
|
|
5734
|
+
* supplied text is the answer to this consumer, and a cooperating producer sees its
|
|
5662
5735
|
* cancellation path rather than its normal return.
|
|
5663
5736
|
*
|
|
5664
5737
|
* @param value - The serialized terminal the consumer is ending on
|
|
@@ -5684,7 +5757,7 @@ export declare class MCPTextStreamController implements MCPTextStreamControllerI
|
|
|
5684
5757
|
*
|
|
5685
5758
|
* @remarks
|
|
5686
5759
|
* Delegates downward exactly as {@link stop} does — disposing the serialized arm is
|
|
5687
|
-
* disposing the exchange, never
|
|
5760
|
+
* disposing the exchange, never this adapter alone.
|
|
5688
5761
|
*
|
|
5689
5762
|
* @returns Resolves once the typed exchange has ended
|
|
5690
5763
|
*/
|
|
@@ -5702,27 +5775,27 @@ export declare class MCPTextStreamController implements MCPTextStreamControllerI
|
|
|
5702
5775
|
* already serialized.
|
|
5703
5776
|
*
|
|
5704
5777
|
* @remarks
|
|
5705
|
-
* A
|
|
5778
|
+
* A translation boundary and nothing more: it serializes each message, and every lifecycle
|
|
5706
5779
|
* decision — cancellation, abort, closure — ends the controlled typed stream beneath it, so
|
|
5707
5780
|
* the string face never becomes a second cancellation engine with its own queue to fall
|
|
5708
5781
|
* behind. `stop()` reaches the typed producer, which is why a transport holding only the
|
|
5709
5782
|
* serialized arm can still end the exchange it is writing.
|
|
5710
5783
|
*
|
|
5711
5784
|
* {@link MCPTextStreamControllerInterface.return} is the one member that narrows rather than
|
|
5712
|
-
* passes through, and the narrowing is inherent: it is handed a
|
|
5785
|
+
* passes through, and the narrowing is inherent: it is handed a string, so it has no typed
|
|
5713
5786
|
* terminal to close the exchange on and never parses one back out of its argument. The typed
|
|
5714
|
-
* exchange therefore ends with
|
|
5787
|
+
* exchange therefore ends with no terminal while this face answers its own consumer with the
|
|
5715
5788
|
* supplied text — so a cooperating producer runs its cancellation path here where the typed
|
|
5716
5789
|
* {@link MCPStreamControllerInterface.return} would have run its normal return.
|
|
5717
5790
|
*
|
|
5718
5791
|
* **The ownership obligation is identical and it is not discharged twice.** Whoever is handed
|
|
5719
|
-
* this face ends it on
|
|
5792
|
+
* this face ends it on every exit, and every closure member here reaches the typed exchange
|
|
5720
5793
|
* beneath — so releasing the serialized arm releases the producer, the request lifetime, and
|
|
5721
5794
|
* the live server slot behind it. A serialized pump therefore owns exactly what a typed pump
|
|
5722
5795
|
* owns, and neither has an owner of last resort to fall back on.
|
|
5723
5796
|
*
|
|
5724
5797
|
* A conforming {@link MCPTextStreamControllerInterface.[Symbol.asyncDispose] | asyncDispose}
|
|
5725
|
-
* releases the typed producer, request lifetime, and live slot
|
|
5798
|
+
* releases the typed producer, request lifetime, and live slot before it may reject. Throwing
|
|
5726
5799
|
* before delegating would let a disposal fault mask the pump's original failure while leaking
|
|
5727
5800
|
* the exchange.
|
|
5728
5801
|
*/
|
|
@@ -5734,19 +5807,19 @@ export declare interface MCPTextStreamControllerInterface extends MCPTextStream
|
|
|
5734
5807
|
*/
|
|
5735
5808
|
next(): Promise<IteratorResult<string, string>>;
|
|
5736
5809
|
/**
|
|
5737
|
-
* Ends the exchange
|
|
5810
|
+
* Ends the serialized exchange on the text supplied by its consumer.
|
|
5738
5811
|
*
|
|
5739
5812
|
* @remarks
|
|
5740
|
-
* The typed exchange ends with
|
|
5813
|
+
* The typed exchange ends with no terminal: a string is not a {@link JSONRPCResponse}, and
|
|
5741
5814
|
* this face never parses one back out of its argument. The supplied text is the answer to
|
|
5742
|
-
*
|
|
5815
|
+
* this consumer alone.
|
|
5743
5816
|
*
|
|
5744
5817
|
* @param value - The serialized terminal the consumer is ending on
|
|
5745
5818
|
* @returns That terminal as the iteration's `return`
|
|
5746
5819
|
*/
|
|
5747
5820
|
return(value: string | PromiseLike<string>): Promise<IteratorResult<string, string>>;
|
|
5748
5821
|
/**
|
|
5749
|
-
* Ends the exchange with
|
|
5822
|
+
* Ends the serialized exchange with the failure supplied by its consumer.
|
|
5750
5823
|
*
|
|
5751
5824
|
* @param error - The failure to end the exchange with
|
|
5752
5825
|
* @returns Never — the returned promise always rejects with the supplied failure
|
|
@@ -5814,13 +5887,13 @@ export declare interface MCPToolUseContent {
|
|
|
5814
5887
|
* Messages are already-serialized JSON-RPC strings; the transport owns framing
|
|
5815
5888
|
* (a WS text frame, an SSE `data:` event, a newline-terminated stdio line, a
|
|
5816
5889
|
* `postMessage` payload) and never parses the string itself. `listen` and
|
|
5817
|
-
* `closed` each register
|
|
5818
|
-
*
|
|
5890
|
+
* `closed` each register the single handler for their event — a second call
|
|
5891
|
+
* replaces the first (matching the emitter-free, minimal-surface carrier idiom
|
|
5819
5892
|
* `bindServer` / `bindClient` themselves rely on), not an additive subscription
|
|
5820
5893
|
* list.
|
|
5821
5894
|
*
|
|
5822
5895
|
* `closed` reads as an adjective where the naming law asks for a verb, and it is
|
|
5823
|
-
*
|
|
5896
|
+
* kept: it is a registrar for the port's terminal event, paired with `listen` for
|
|
5824
5897
|
* the other one, and no verb states that without lying. `close()` is already taken
|
|
5825
5898
|
* by the imperative on the line below it, `end`/`stop` would read as a second way to
|
|
5826
5899
|
* close, and `onClose` is the `on`-prefixed shape the rules reject outright. The
|
|
@@ -5831,20 +5904,20 @@ export declare interface MCPToolUseContent {
|
|
|
5831
5904
|
export declare interface MCPTransportInterface {
|
|
5832
5905
|
/** Delivers one outbound JSON-RPC message (already serialized). */
|
|
5833
5906
|
readonly send: (message: string) => void | Promise<void>;
|
|
5834
|
-
/** Registers the single inbound-message handler — a second call
|
|
5907
|
+
/** Registers the single inbound-message handler — a second call replaces the first. */
|
|
5835
5908
|
readonly listen: (handler: (message: string) => void) => void;
|
|
5836
|
-
/** Registers the single closed handler — a second call
|
|
5909
|
+
/** Registers the single closed handler — a second call replaces the first. */
|
|
5837
5910
|
readonly closed: (handler: () => void) => void;
|
|
5838
5911
|
/** Closes the underlying channel. */
|
|
5839
5912
|
readonly close: () => void | Promise<void>;
|
|
5840
5913
|
}
|
|
5841
5914
|
|
|
5842
5915
|
/**
|
|
5843
|
-
* Represents a `tools/call` result
|
|
5916
|
+
* Represents a `tools/call` result before the modern stamp — the executed tool's output as
|
|
5844
5917
|
* `content` blocks, with `isError` flagging a tool failure.
|
|
5845
5918
|
*
|
|
5846
5919
|
* @remarks
|
|
5847
|
-
* The name states the whole distinction: this is the tool-call result
|
|
5920
|
+
* The name states the whole distinction: this is the tool-call result without
|
|
5848
5921
|
* `resultType`, which is the only shape the legacy revision has for one.
|
|
5849
5922
|
* {@link MCPCallResult} is this payload plus the modern `'complete'` stamp, so
|
|
5850
5923
|
* stamping is the one difference between the modern and legacy answers to `tools/call`.
|
|
@@ -5853,8 +5926,8 @@ export declare interface MCPTransportInterface {
|
|
|
5853
5926
|
*
|
|
5854
5927
|
* A success carries the tool's value unchanged as `structuredContent` alongside
|
|
5855
5928
|
* its serialized form in one `text` content block. A value-less success omits
|
|
5856
|
-
* `structuredContent`. A tool
|
|
5857
|
-
* isolated) carries its `error` text in `content`
|
|
5929
|
+
* `structuredContent`. A tool failure (the `success: false` branch the registry
|
|
5930
|
+
* isolated) carries its `error` text in `content` and sets `isError: true`, so the
|
|
5858
5931
|
* model sees the failure as a tool result it can react to rather than a protocol
|
|
5859
5932
|
* error.
|
|
5860
5933
|
*/
|
|
@@ -5901,19 +5974,19 @@ export declare function modernResultToLegacy(result: MCPResult | MCPLegacyResult
|
|
|
5901
5974
|
*
|
|
5902
5975
|
* @remarks
|
|
5903
5976
|
* Total — a non-message returns `undefined`, never throws. The input must
|
|
5904
|
-
*
|
|
5977
|
+
* already be `JSON.parse`d: the raw-string parse (which can throw on malformed
|
|
5905
5978
|
* JSON) happens in `MCPServer.handle` inside a try/catch that maps a parse failure
|
|
5906
5979
|
* to a `-32700` response.
|
|
5907
5980
|
*
|
|
5908
|
-
* A defined result is an
|
|
5981
|
+
* A defined result is an owned canonical snapshot, never the input reference: it is
|
|
5909
5982
|
* rebuilt from the canonical text and deeply frozen, so `-0` arrives as `0`. Every record
|
|
5910
|
-
* was
|
|
5983
|
+
* was serialized with its keys sorted, but the rebuilt object enumerates its own keys the
|
|
5911
5984
|
* way JavaScript does, so an integer-like `'9'` still precedes `'10'`: the result's key
|
|
5912
5985
|
* order is neither promised nor generally the canonical one. A caller who needs canonical
|
|
5913
|
-
*
|
|
5986
|
+
* bytes takes them from `serializeJSON`/`snapshotJSON` rather than re-stringifying this
|
|
5914
5987
|
* result. Identity is not preserved and is not promised.
|
|
5915
5988
|
*
|
|
5916
|
-
* The parser's sound partner is the
|
|
5989
|
+
* The parser's sound partner is the composite `isJSONRPCMessage(value) &&
|
|
5917
5990
|
* isBoundedJSON(value, limits)`, and against it both halves of the soundness law
|
|
5918
5991
|
* hold by construction:
|
|
5919
5992
|
*
|
|
@@ -5921,12 +5994,12 @@ export declare function modernResultToLegacy(result: MCPResult | MCPLegacyResult
|
|
|
5921
5994
|
* is applied to the exact frozen reference returned.
|
|
5922
5995
|
* - Every input satisfying the composite is admitted rather than rejected, because
|
|
5923
5996
|
* `isBoundedJSON` is this parser's own admission test — the same canonical
|
|
5924
|
-
* serializer under the same `limits` — so
|
|
5997
|
+
* serializer under the same `limits` — so they cannot disagree about the bound.
|
|
5925
5998
|
*
|
|
5926
|
-
* {@link isJSONRPCMessage}
|
|
5999
|
+
* {@link isJSONRPCMessage} Alone is not that partner. It is clone-backed and so already
|
|
5927
6000
|
* exact about shape, but it carries no size or depth bound — so guard-valid values
|
|
5928
6001
|
* exist that this parser rejects: a message nested deeper than `limits.depth`, and one
|
|
5929
|
-
* whose canonical text exceeds `limits.bytes`. Those are named causes,
|
|
6002
|
+
* whose canonical text exceeds `limits.bytes`. Those are named causes, not a complete
|
|
5930
6003
|
* boundary. Among values `isJSONRPCMessage` already admits, the admitted set is exactly
|
|
5931
6004
|
* what canonical serialization accepts under `limits`, so a caller who needs that line
|
|
5932
6005
|
* tests it with `isBoundedJSON` rather than inferring it from this list.
|
|
@@ -5950,11 +6023,11 @@ export declare function parseJSONRPCMessage(value: unknown, limits?: MCPJSONLimi
|
|
|
5950
6023
|
* @remarks
|
|
5951
6024
|
* This parser does not open the opaque continuation carrier; the configured
|
|
5952
6025
|
* continuation port performs that boundary first. The protected
|
|
5953
|
-
* payload binds the authenticated principal, absolute expiry,
|
|
6026
|
+
* payload binds the authenticated principal, absolute expiry, original request id, version,
|
|
5954
6027
|
* method, the exact round that was issued, tool name, argument digest, and optional
|
|
5955
6028
|
* application state. Every member is required except application state: a payload missing its
|
|
5956
6029
|
* round cannot have the client's answers enforced, so it is refused rather than admitted
|
|
5957
|
-
* unenforced. An
|
|
6030
|
+
* unenforced. An empty round is refused for the same reason — a retry against it would answer
|
|
5958
6031
|
* no question at all. Total over malformed or hostile input.
|
|
5959
6032
|
*
|
|
5960
6033
|
* @param value - The opened canonical continuation value to parse
|
|
@@ -5974,7 +6047,7 @@ export declare function parseMCPInputState(value: unknown): MCPInputState | unde
|
|
|
5974
6047
|
* This is the validity step after {@link isModernRequest}: a defined result can
|
|
5975
6048
|
* only come from a guard-positive request, while a guard-positive request returns
|
|
5976
6049
|
* `undefined` when its required modern metadata is malformed — and also when the
|
|
5977
|
-
* request falls outside the bound this parser
|
|
6050
|
+
* request falls outside the bound this parser inherits by routing through
|
|
5978
6051
|
* {@link parseJSONRPCMessage} under the same `limits`. The version
|
|
5979
6052
|
* must be a string but need not be supported; unsupported strings belong to the
|
|
5980
6053
|
* dedicated protocol-version error path. Client identity is optional, but when
|
|
@@ -5993,7 +6066,7 @@ export declare function parseRequestContext(value: unknown, limits?: MCPJSONLimi
|
|
|
5993
6066
|
* {@link buildCancelledNotification}.
|
|
5994
6067
|
*
|
|
5995
6068
|
* @remarks
|
|
5996
|
-
* `requestId` is the
|
|
6069
|
+
* `requestId` is the wire spelling carried verbatim from the dated schema, and it must be a
|
|
5997
6070
|
* real {@link JSONRPCId}: `null` is not one, and neither is an absent member, so a
|
|
5998
6071
|
* malformed frame reads as "cancels nothing" rather than as an error. Anything that is not a
|
|
5999
6072
|
* `notifications/cancelled` notification — a response, a request that happens to use the
|
|
@@ -6011,15 +6084,15 @@ export declare function readCancelledId(message: JSONRPCMessage): JSONRPCId | un
|
|
|
6011
6084
|
|
|
6012
6085
|
/**
|
|
6013
6086
|
* Decodes a `fetch` Response's Server-Sent-Events body into the JSON-RPC messages it
|
|
6014
|
-
* carried — the
|
|
6087
|
+
* carried — the client-side inverse of a server's Streamable-HTTP SSE response.
|
|
6015
6088
|
*
|
|
6016
6089
|
* @remarks
|
|
6017
6090
|
* Reads the whole `response.body` stream chunk-by-chunk through a `TextDecoder({ stream: true
|
|
6018
6091
|
* })` (handling a multi-byte character split across reads) and `@orkestrel/sse`'s
|
|
6019
6092
|
* {@link SSEParserInterface} (handling a partial line or in-progress event split across
|
|
6020
6093
|
* reads), then narrows each dispatched event's `data` to a {@link JSONRPCMessage} through
|
|
6021
|
-
* {@link decodeEvent} (so a non-message or non-JSON `data:` event is
|
|
6022
|
-
* total). It reuses the
|
|
6094
|
+
* {@link decodeEvent} (so a non-message or non-JSON `data:` event is dropped, never thrown —
|
|
6095
|
+
* total). It reuses the same `SSEParser` a server's `createStream` seam serializes against, so
|
|
6023
6096
|
* the wire round-trips. A `null` body (no stream) yields no messages;
|
|
6024
6097
|
* {@link import('./transports/HTTPClientTransport.js').HTTPClientTransport} reads a
|
|
6025
6098
|
* request/response SSE reply (the server sends one `data:` event then ends), so this drains to
|
|
@@ -6039,11 +6112,11 @@ export declare function readEventStream(response: Response): Promise<readonly JS
|
|
|
6039
6112
|
* Renders one projected argument as the text its `Mcp-Param-*` header carries.
|
|
6040
6113
|
*
|
|
6041
6114
|
* @remarks
|
|
6042
|
-
* The protocol's conversion table, and the
|
|
6115
|
+
* The protocol's conversion table, and the one place it is stated: a string travels as
|
|
6043
6116
|
* itself, an integer in decimal, and a boolean as lowercase `true` or `false`. The value's
|
|
6044
6117
|
* runtime shape must match the leaf's declared type, so a schema that declares `integer` and
|
|
6045
6118
|
* an argument that supplies a string, a fraction, or a magnitude outside the IEEE 754 safe
|
|
6046
|
-
* range carries
|
|
6119
|
+
* range carries nothing — a header that cannot round-trip the body value is worse than an
|
|
6047
6120
|
* absent one, and the tool's own argument validation owns the disagreement.
|
|
6048
6121
|
*
|
|
6049
6122
|
* @param value - The argument value read at the parameter's path
|
|
@@ -6060,14 +6133,14 @@ export declare function renderHeaderValue(value: unknown, primitive: MCPHeaderPr
|
|
|
6060
6133
|
|
|
6061
6134
|
/**
|
|
6062
6135
|
* Pumps a controlled serialized exchange onto a transport — every notification in order, then
|
|
6063
|
-
* the terminating response — and
|
|
6136
|
+
* the terminating response — and end the exchange however the pump leaves.
|
|
6064
6137
|
*
|
|
6065
6138
|
* @remarks
|
|
6066
6139
|
* The generator's `return` value is a message like any other on the wire: it is sent
|
|
6067
|
-
*
|
|
6140
|
+
* last and closes the exchange. Sends are awaited one at a time so the transport
|
|
6068
6141
|
* receives the sequence in the order the method produced it.
|
|
6069
6142
|
*
|
|
6070
|
-
* The first parameter is the
|
|
6143
|
+
* The first parameter is the controlled arm rather than a bare
|
|
6071
6144
|
* {@link import('./types.js').MCPTextStream}, and that is the whole point of it: this pump is
|
|
6072
6145
|
* an owner, and an owner needs a lifecycle member to discharge its obligation with. A bare
|
|
6073
6146
|
* generator has none, so an exit where nothing was cancelled — a `send` that threw two
|
|
@@ -6077,7 +6150,7 @@ export declare function renderHeaderValue(value: unknown, primitive: MCPHeaderPr
|
|
|
6077
6150
|
* is a no-op for an exchange that already ended on its terminal.
|
|
6078
6151
|
*
|
|
6079
6152
|
* The `finally` is spelled explicitly rather than with `await using` because this package's
|
|
6080
|
-
* declared Node floor cannot
|
|
6153
|
+
* declared Node floor cannot parse `await using` — `target: ESNext` emits the declaration
|
|
6081
6154
|
* verbatim, and a floor engine rejects the whole module at load. The obligation discharged is
|
|
6082
6155
|
* identical either way.
|
|
6083
6156
|
*
|
|
@@ -6161,7 +6234,10 @@ export declare function snapshotToolResult(value: unknown, limits: MCPJSONLimitO
|
|
|
6161
6234
|
*/
|
|
6162
6235
|
export declare function stampSubscriptionNotification(notification: JSONRPCNotification, id: JSONRPCId): JSONRPCNotification;
|
|
6163
6236
|
|
|
6164
|
-
/**
|
|
6237
|
+
/**
|
|
6238
|
+
* Lists the protocol revisions accepted by the optional legacy decorator, `2025-11-25` and
|
|
6239
|
+
* `2025-06-18`.
|
|
6240
|
+
*/
|
|
6165
6241
|
export declare const SUPPORTED_LEGACY_PROTOCOL_VERSIONS: readonly MCPLegacyVersion[];
|
|
6166
6242
|
|
|
6167
6243
|
/**
|
|
@@ -6171,7 +6247,7 @@ export declare const SUPPORTED_LEGACY_PROTOCOL_VERSIONS: readonly MCPLegacyVersi
|
|
|
6171
6247
|
export declare const SUPPORTED_MCP_VERSIONS: readonly MCPVersion[];
|
|
6172
6248
|
|
|
6173
6249
|
/**
|
|
6174
|
-
* Lists the modern MCP protocol revisions a bare server accepts and advertises
|
|
6250
|
+
* Lists the modern MCP protocol revisions a bare server accepts and advertises, `2026-07-28`.
|
|
6175
6251
|
*
|
|
6176
6252
|
* @remarks
|
|
6177
6253
|
* Frozen in discovery-advertisement order. Legacy revisions are absent because
|
|
@@ -6204,14 +6280,14 @@ export declare function supportsFormElicitation(value: unknown): boolean;
|
|
|
6204
6280
|
*
|
|
6205
6281
|
* @remarks
|
|
6206
6282
|
* The declaration lives at `extensions['io.modelcontextprotocol/tasks']` and the schema
|
|
6207
|
-
* types its value
|
|
6283
|
+
* types its value exactly empty — `Record<string, never>`, an object with no additional
|
|
6208
6284
|
* properties. So the key's presence is the whole declaration, and the value carries the
|
|
6209
6285
|
* whole of the check: a `true` or a string there is a client speaking a different protocol
|
|
6210
6286
|
* rather than a shorthand, and a member inside the object is a client declaring an option
|
|
6211
6287
|
* this extension does not define. Both are refused, because a server that accepted either
|
|
6212
6288
|
* would be reading a shape no peer can produce from the snapshot's own schema.
|
|
6213
6289
|
*
|
|
6214
|
-
* A client declares this
|
|
6290
|
+
* A client declares this per request. Nothing here consults a session, because the modern
|
|
6215
6291
|
* revision is stateless and a capability declared once at connect time says nothing about
|
|
6216
6292
|
* the request in hand. Total over hostile input.
|
|
6217
6293
|
*
|