@orkestrel/mcp 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/browser/index.d.ts +786 -0
- package/dist/src/browser/index.js +636 -4
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +216 -42
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +144 -32
- package/dist/src/core/index.d.ts +144 -32
- package/dist/src/core/index.js +214 -44
- package/dist/src/core/index.js.map +1 -1
- package/package.json +6 -6
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayOf, attempt, cloneJSONRecord, cloneJSONValue, isArray, isBoolean, isFiniteNumber, isInteger, isJSONValue, isNumber, isRecord, isString, isUndefined, parseJSON, sanitizeBudget } from "@orkestrel/contract";
|
|
1
|
+
import { arrayOf, attempt, cloneJSONRecord, cloneJSONValue, isArray, isBoolean, isFiniteNumber, isInteger, isJSONValue, isNumber, isRecord, isString, isUndefined, objectOf, parseJSON, sanitizeBudget } from "@orkestrel/contract";
|
|
2
2
|
import { decodeBase64, decodeUTF8, encodeBase64, encodeHex } from "@orkestrel/codec";
|
|
3
3
|
import { createSSEParser } from "@orkestrel/sse";
|
|
4
4
|
import { Emitter } from "@orkestrel/emitter";
|
|
@@ -274,9 +274,12 @@ var DEFAULT_MCP_SUBSCRIPTION_CAPACITY = 64;
|
|
|
274
274
|
* optional structured context.
|
|
275
275
|
*
|
|
276
276
|
* @remarks
|
|
277
|
-
* {@link MCPClient} throws this error for a remote JSON-RPC `error` response
|
|
278
|
-
*
|
|
279
|
-
*
|
|
277
|
+
* {@link MCPClient} throws this error for a remote JSON-RPC `error` response, for a locally
|
|
278
|
+
* detected protocol incompatibility, and for a session-bound request refused because the
|
|
279
|
+
* client holds no connection — that one carries `-32600`, so a caller separates "reconnect"
|
|
280
|
+
* from "retry" without reading a message. Local lifecycle and transport conditions that
|
|
281
|
+
* settle a request already in flight, such as a disconnect and a request timeout, remain
|
|
282
|
+
* plain `Error`s. For a remote response, `context`
|
|
280
283
|
* carries the optional `error.data` unchanged and is `undefined` when the peer omitted it.
|
|
281
284
|
* This includes the modern reserved paths: `-32020` carries no context, `-32021` may carry
|
|
282
285
|
* `requiredCapabilities`, and `-32022` carries the peer's `supported` revisions and
|
|
@@ -1127,19 +1130,17 @@ function buildCallOutcome(name, result) {
|
|
|
1127
1130
|
* Builds the canonical Tool call for one validated MCP `tools/call` request.
|
|
1128
1131
|
*
|
|
1129
1132
|
* @param request - The original MCP request
|
|
1130
|
-
* @param caller - Optional consumer-asserted caller context
|
|
1131
1133
|
* @param args - Optional once-validated modern arguments; omission retains legacy normalization
|
|
1132
1134
|
* @returns The canonical call, or `undefined` when the name is invalid
|
|
1133
1135
|
*/
|
|
1134
|
-
function buildToolCall(request,
|
|
1136
|
+
function buildToolCall(request, args) {
|
|
1135
1137
|
const name = request.params?.["name"];
|
|
1136
1138
|
if (typeof name !== "string") return void 0;
|
|
1137
1139
|
const rawArguments = request.params?.["arguments"];
|
|
1138
1140
|
return {
|
|
1139
1141
|
id: String(request.id),
|
|
1140
1142
|
name,
|
|
1141
|
-
arguments: args ?? (isRecord(rawArguments) ? rawArguments : {})
|
|
1142
|
-
...caller === void 0 ? {} : { caller }
|
|
1143
|
+
arguments: args ?? (isRecord(rawArguments) ? rawArguments : {})
|
|
1143
1144
|
};
|
|
1144
1145
|
}
|
|
1145
1146
|
/**
|
|
@@ -1230,7 +1231,8 @@ function buildMethodOptions(options, lifetime) {
|
|
|
1230
1231
|
*
|
|
1231
1232
|
* @remarks
|
|
1232
1233
|
* Each {@link import('@orkestrel/tool').ToolDefinition} carries through its
|
|
1233
|
-
* `name` and
|
|
1234
|
+
* `name`, optional `title` and `description`, and mapped annotation hints;
|
|
1235
|
+
* its open JSON-Schema `parameters`
|
|
1234
1236
|
* becomes `inputSchema`, defaulting to an empty object schema (`{ type: 'object' }`)
|
|
1235
1237
|
* when a tool declares none (MCP requires an `inputSchema`).
|
|
1236
1238
|
*
|
|
@@ -1239,14 +1241,50 @@ function buildMethodOptions(options, lifetime) {
|
|
|
1239
1241
|
*/
|
|
1240
1242
|
function buildToolDescriptors(manager) {
|
|
1241
1243
|
return manager.definitions().map((definition) => {
|
|
1242
|
-
const
|
|
1244
|
+
const annotations = definition.annotations === void 0 ? {} : toolAnnotationsToMCP(definition.annotations);
|
|
1245
|
+
return {
|
|
1243
1246
|
name: definition.name,
|
|
1244
|
-
inputSchema: definition.parameters ?? { type: "object" }
|
|
1247
|
+
inputSchema: definition.parameters ?? { type: "object" },
|
|
1248
|
+
...definition.title === void 0 ? {} : { title: definition.title },
|
|
1249
|
+
...definition.description === void 0 ? {} : { description: definition.description },
|
|
1250
|
+
...Object.keys(annotations).length === 0 ? {} : { annotations }
|
|
1245
1251
|
};
|
|
1246
|
-
if (definition.description !== void 0) descriptor.description = definition.description;
|
|
1247
|
-
return descriptor;
|
|
1248
1252
|
});
|
|
1249
1253
|
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Projects domain tool annotations onto MCP wire hints without inventing defaults.
|
|
1256
|
+
*
|
|
1257
|
+
* @param annotations - The authored domain annotations
|
|
1258
|
+
* @returns The mapped hints; `untrusted` has no MCP counterpart
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```ts
|
|
1262
|
+
* toolAnnotationsToMCP({ pure: true, consequential: false }) // { readOnlyHint: true, destructiveHint: false }
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
function toolAnnotationsToMCP(annotations) {
|
|
1266
|
+
return {
|
|
1267
|
+
...annotations.pure === void 0 ? {} : { readOnlyHint: annotations.pure },
|
|
1268
|
+
...annotations.consequential === void 0 ? {} : { destructiveHint: annotations.consequential }
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Projects MCP wire hints onto domain tool annotations without inventing defaults.
|
|
1273
|
+
*
|
|
1274
|
+
* @param annotations - The validated MCP wire annotations
|
|
1275
|
+
* @returns The mapped annotations; unmapped wire hints are omitted
|
|
1276
|
+
*
|
|
1277
|
+
* @example
|
|
1278
|
+
* ```ts
|
|
1279
|
+
* mcpAnnotationsToTool({ readOnlyHint: false, destructiveHint: true }) // { pure: false, consequential: true }
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
1282
|
+
function mcpAnnotationsToTool(annotations) {
|
|
1283
|
+
return {
|
|
1284
|
+
...annotations.readOnlyHint === void 0 ? {} : { pure: annotations.readOnlyHint },
|
|
1285
|
+
...annotations.destructiveHint === void 0 ? {} : { consequential: annotations.destructiveHint }
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1250
1288
|
function buildModernResult(result, identity, ttl, scope) {
|
|
1251
1289
|
const currentMetadata = isRecord(result) ? result["_meta"] : void 0;
|
|
1252
1290
|
if (!isJSONValue(identity)) throw new TypeError("MCP identity must be exact JSON");
|
|
@@ -1451,10 +1489,11 @@ function buildSubscriptionResult(id, identity) {
|
|
|
1451
1489
|
* @remarks
|
|
1452
1490
|
* `capabilities.resources` and `capabilities.prompts` appear only for servers with their
|
|
1453
1491
|
* respective managers and derive notification flags from the configured subscription filter.
|
|
1454
|
-
* `
|
|
1455
|
-
* `capabilities.
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1492
|
+
* `tools.listChanged` is always advertised because the server produces the family from its
|
|
1493
|
+
* own registry. `capabilities.completions` is independent and appears only with a completion
|
|
1494
|
+
* provider. `capabilities.extensions` appears only for a server that configured the
|
|
1495
|
+
* extension it would name. An advertisement is a promise a client is entitled to act on, so
|
|
1496
|
+
* a server with no `task` policy omits the member entirely rather than advertising an empty
|
|
1458
1497
|
* record — and its discovery answer stays byte-for-byte what it was before the extension
|
|
1459
1498
|
* existed.
|
|
1460
1499
|
*
|
|
@@ -1465,7 +1504,7 @@ function buildDiscoverResult(options) {
|
|
|
1465
1504
|
return buildModernResult({
|
|
1466
1505
|
supportedVersions: SUPPORTED_MODERN_PROTOCOL_VERSIONS,
|
|
1467
1506
|
capabilities: {
|
|
1468
|
-
tools: {},
|
|
1507
|
+
tools: { listChanged: true },
|
|
1469
1508
|
...options.resources === void 0 ? {} : { resources: {
|
|
1470
1509
|
...options.subscription?.notifications.resourceSubscriptions === void 0 ? {} : { subscribe: true },
|
|
1471
1510
|
...options.subscription?.notifications.resourcesListChanged === true ? { listChanged: true } : {}
|
|
@@ -2664,6 +2703,28 @@ function isMCPResource(value) {
|
|
|
2664
2703
|
}
|
|
2665
2704
|
}
|
|
2666
2705
|
/**
|
|
2706
|
+
* Checks whether a value carries valid consumed MCP 2026-07-28 tool annotation hints.
|
|
2707
|
+
*
|
|
2708
|
+
* @remarks
|
|
2709
|
+
* Validates only `readOnlyHint` and `destructiveHint`; other wire fields are not consumed, so
|
|
2710
|
+
* the open `objectOf` combinator carries them through unread. Every declared member is
|
|
2711
|
+
* optional, a hostile read answers `false` rather than throwing, and an array is refused.
|
|
2712
|
+
*
|
|
2713
|
+
* @param value - The unknown wire annotations
|
|
2714
|
+
* @returns True if consumed annotation fields are optional booleans; false otherwise
|
|
2715
|
+
*
|
|
2716
|
+
* @example
|
|
2717
|
+
* ```ts
|
|
2718
|
+
* isMCPToolAnnotations({ readOnlyHint: false }) // true
|
|
2719
|
+
* ```
|
|
2720
|
+
*/
|
|
2721
|
+
function isMCPToolAnnotations(value) {
|
|
2722
|
+
return objectOf({
|
|
2723
|
+
readOnlyHint: isBoolean,
|
|
2724
|
+
destructiveHint: isBoolean
|
|
2725
|
+
}, true)(value);
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2667
2728
|
* Determines whether a value is one resource-template descriptor.
|
|
2668
2729
|
*
|
|
2669
2730
|
* @remarks
|
|
@@ -3272,6 +3333,22 @@ function isMCPSubscriptionFilter(value) {
|
|
|
3272
3333
|
return isUndefined(tasks) || arrayOf(isString)(tasks);
|
|
3273
3334
|
}
|
|
3274
3335
|
/**
|
|
3336
|
+
* Checks whether a subscription filter leaves the built-in tools family to the server.
|
|
3337
|
+
*
|
|
3338
|
+
* @param value - The unknown value to inspect
|
|
3339
|
+
* @returns True if the filter is valid and does not claim tools changes; false otherwise
|
|
3340
|
+
*
|
|
3341
|
+
* @example
|
|
3342
|
+
* ```ts
|
|
3343
|
+
* isMCPConsumerFilter({ promptsListChanged: true }) // true
|
|
3344
|
+
* isMCPConsumerFilter({ toolsListChanged: true }) // false
|
|
3345
|
+
* ```
|
|
3346
|
+
*/
|
|
3347
|
+
function isMCPConsumerFilter(value) {
|
|
3348
|
+
const owned = attempt(() => cloneJSONRecord(value));
|
|
3349
|
+
return owned.success && isMCPSubscriptionFilter(owned.value) && owned.value["toolsListChanged"] !== true;
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3275
3352
|
* Determines whether a value is a graceful `subscriptions/listen` result.
|
|
3276
3353
|
*
|
|
3277
3354
|
* @param value - The unknown value to inspect
|
|
@@ -5014,6 +5091,7 @@ var MCPServer = class {
|
|
|
5014
5091
|
#limits;
|
|
5015
5092
|
#subscriptions = 0;
|
|
5016
5093
|
constructor(options) {
|
|
5094
|
+
if (options.subscription !== void 0 && !isMCPConsumerFilter(options.subscription.notifications)) throw new MCPError("The consumer filter must be a valid filter that omits tools changes, because the server produces that family from its registry", JSONRPC_INVALID_PARAMS);
|
|
5017
5095
|
this.#emitter = new Emitter({
|
|
5018
5096
|
...options.on !== void 0 ? { on: options.on } : {},
|
|
5019
5097
|
...options.error !== void 0 ? { error: options.error } : {}
|
|
@@ -5286,14 +5364,14 @@ var MCPServer = class {
|
|
|
5286
5364
|
const args = isRecord(rawArguments) ? rawArguments : EMPTY_MCP_ARGUMENTS;
|
|
5287
5365
|
const input = await this.#input(request, args, options);
|
|
5288
5366
|
if (input !== void 0) return input;
|
|
5289
|
-
const call = buildToolCall(request,
|
|
5367
|
+
const call = buildToolCall(request, args);
|
|
5290
5368
|
if (call === void 0) return buildJSONRPCError(id, JSONRPC_INVALID_PARAMS, "Invalid params: a string `name` is required");
|
|
5291
5369
|
const deferred = await this.#defer(request, call, options);
|
|
5292
5370
|
if (deferred !== void 0) return deferred;
|
|
5293
5371
|
const token = params?.["_meta"];
|
|
5294
5372
|
const progressToken = isRecord(token) ? token["progressToken"] : void 0;
|
|
5295
5373
|
if (this.#options.execution !== void 0 && (isString(progressToken) || typeof progressToken === "number" && Number.isInteger(progressToken))) return this.#progress(request, call, progressToken, options);
|
|
5296
|
-
const result = await this.#execute(request, call, options
|
|
5374
|
+
const result = await this.#execute(request, call, options);
|
|
5297
5375
|
return "jsonrpc" in result ? result : buildJSONRPCResult(id, result);
|
|
5298
5376
|
}
|
|
5299
5377
|
async #defer(request, call, options) {
|
|
@@ -5337,7 +5415,7 @@ var MCPServer = class {
|
|
|
5337
5415
|
keys: this.#limits.keys,
|
|
5338
5416
|
depth: this.#limits.depth
|
|
5339
5417
|
}, signal);
|
|
5340
|
-
const execution = this.#execute(request, call,
|
|
5418
|
+
const execution = this.#execute(request, call, options, reporter);
|
|
5341
5419
|
try {
|
|
5342
5420
|
while (true) {
|
|
5343
5421
|
const outcome = await Promise.race([reporter.take(), execution]);
|
|
@@ -5355,14 +5433,19 @@ var MCPServer = class {
|
|
|
5355
5433
|
reporter.stop();
|
|
5356
5434
|
}
|
|
5357
5435
|
}
|
|
5358
|
-
async #execute(request, call,
|
|
5436
|
+
async #execute(request, call, options, progress) {
|
|
5437
|
+
const { signal, caller } = options;
|
|
5359
5438
|
let result;
|
|
5360
5439
|
try {
|
|
5361
|
-
result = this.#options.execution === void 0 ? await this.#options.tools.execute(call
|
|
5440
|
+
result = this.#options.execution === void 0 ? await this.#options.tools.execute(call, {
|
|
5441
|
+
signal,
|
|
5442
|
+
...caller === void 0 ? {} : { caller }
|
|
5443
|
+
}) : await this.#options.execution({
|
|
5362
5444
|
request,
|
|
5363
5445
|
call,
|
|
5364
5446
|
tools: this.#options.tools,
|
|
5365
5447
|
signal,
|
|
5448
|
+
...caller === void 0 ? {} : { caller },
|
|
5366
5449
|
...progress === void 0 ? {} : { progress }
|
|
5367
5450
|
});
|
|
5368
5451
|
} catch (error) {
|
|
@@ -5550,7 +5633,10 @@ var MCPServer = class {
|
|
|
5550
5633
|
const task = this.#options.task;
|
|
5551
5634
|
const configured = this.#options.subscription;
|
|
5552
5635
|
const tasks = task !== void 0 && configured !== void 0;
|
|
5553
|
-
let notifications = buildSubscriptionFilter(requested,
|
|
5636
|
+
let notifications = buildSubscriptionFilter(requested, {
|
|
5637
|
+
...configured?.notifications,
|
|
5638
|
+
toolsListChanged: true
|
|
5639
|
+
}, tasks);
|
|
5554
5640
|
const requestedTaskIds = notifications.taskIds;
|
|
5555
5641
|
if (requestedTaskIds !== void 0) {
|
|
5556
5642
|
const resolved = [];
|
|
@@ -5563,19 +5649,22 @@ var MCPServer = class {
|
|
|
5563
5649
|
taskIds: resolved
|
|
5564
5650
|
} : rest;
|
|
5565
5651
|
}
|
|
5652
|
+
const state = {
|
|
5653
|
+
frame: void 0,
|
|
5654
|
+
failure: void 0,
|
|
5655
|
+
iterator: void 0
|
|
5656
|
+
};
|
|
5657
|
+
const source = new ReadableStream({
|
|
5658
|
+
start: this.#startSubscription.bind(this, notifications, options, configured, state),
|
|
5659
|
+
pull: this.#pullSubscription.bind(this, notifications, options, state)
|
|
5660
|
+
});
|
|
5566
5661
|
yield buildSubscriptionAcknowledgement(notifications, id);
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
const owned = parseJSONRPCMessage(next.value, {
|
|
5572
|
-
bytes: this.#limits.message,
|
|
5573
|
-
depth: this.#limits.depth
|
|
5574
|
-
});
|
|
5575
|
-
if (owned === void 0 || !isJSONRPCNotification(owned)) continue;
|
|
5576
|
-
if (matchesSubscriptionNotification(owned, notifications)) yield stampSubscriptionNotification(owned, id);
|
|
5577
|
-
}
|
|
5662
|
+
for await (const notification of source) {
|
|
5663
|
+
if (notification === void 0) continue;
|
|
5664
|
+
if (notification === state.frame) state.frame = void 0;
|
|
5665
|
+
yield stampSubscriptionNotification(notification, id);
|
|
5578
5666
|
}
|
|
5667
|
+
if (state.failure !== void 0) throw state.failure.error;
|
|
5579
5668
|
return buildSubscriptionResult(id, this.#options.identity);
|
|
5580
5669
|
} catch (error) {
|
|
5581
5670
|
if (options.signal.aborted) throw error;
|
|
@@ -5584,6 +5673,72 @@ var MCPServer = class {
|
|
|
5584
5673
|
slot.abort();
|
|
5585
5674
|
}
|
|
5586
5675
|
}
|
|
5676
|
+
async #startSubscription(notifications, options, configured, state, controller) {
|
|
5677
|
+
const emitter = this.#options.tools.emitter;
|
|
5678
|
+
const changed = this.#change.bind(this, controller, options.signal, state);
|
|
5679
|
+
if (options.signal.aborted) {
|
|
5680
|
+
controller.error(options.signal.reason);
|
|
5681
|
+
return;
|
|
5682
|
+
}
|
|
5683
|
+
if (notifications.toolsListChanged === true && !emitter.destroyed) {
|
|
5684
|
+
emitter.on("add", changed);
|
|
5685
|
+
emitter.on("remove", changed);
|
|
5686
|
+
emitter.on("clear", changed);
|
|
5687
|
+
}
|
|
5688
|
+
options.signal.addEventListener("abort", () => {
|
|
5689
|
+
emitter.off("add", changed);
|
|
5690
|
+
emitter.off("remove", changed);
|
|
5691
|
+
emitter.off("clear", changed);
|
|
5692
|
+
const iterator = state.iterator;
|
|
5693
|
+
state.iterator = void 0;
|
|
5694
|
+
if (iterator !== void 0) this.#releaseProducer(iterator, options.signal.reason);
|
|
5695
|
+
controller.error(options.signal.reason);
|
|
5696
|
+
}, { once: true });
|
|
5697
|
+
try {
|
|
5698
|
+
if (configured === void 0) return;
|
|
5699
|
+
const iterator = (await configured.producer(notifications, options))[Symbol.asyncIterator]();
|
|
5700
|
+
if (options.signal.aborted) this.#releaseProducer(iterator, options.signal.reason);
|
|
5701
|
+
else state.iterator = iterator;
|
|
5702
|
+
} catch (error) {
|
|
5703
|
+
this.#failSubscription(state, options.signal, controller, error);
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
#change(controller, signal, state) {
|
|
5707
|
+
if (signal.aborted || state.failure !== void 0 || state.frame !== void 0) return;
|
|
5708
|
+
const notification = {
|
|
5709
|
+
jsonrpc: "2.0",
|
|
5710
|
+
method: "notifications/tools/list_changed"
|
|
5711
|
+
};
|
|
5712
|
+
state.frame = notification;
|
|
5713
|
+
controller.enqueue(notification);
|
|
5714
|
+
}
|
|
5715
|
+
async #pullSubscription(notifications, options, state, controller) {
|
|
5716
|
+
try {
|
|
5717
|
+
if (options.signal.aborted) return;
|
|
5718
|
+
const next = await state.iterator?.next();
|
|
5719
|
+
if (options.signal.aborted) return;
|
|
5720
|
+
if (next === void 0 || next.done === true) {
|
|
5721
|
+
state.iterator = void 0;
|
|
5722
|
+
if (notifications.toolsListChanged !== true) controller.close();
|
|
5723
|
+
return;
|
|
5724
|
+
}
|
|
5725
|
+
const owned = parseJSONRPCMessage(next.value, {
|
|
5726
|
+
bytes: this.#limits.message,
|
|
5727
|
+
depth: this.#limits.depth
|
|
5728
|
+
});
|
|
5729
|
+
controller.enqueue(owned !== void 0 && isJSONRPCNotification(owned) && owned.method !== "notifications/tools/list_changed" && matchesSubscriptionNotification(owned, notifications) ? owned : void 0);
|
|
5730
|
+
} catch (error) {
|
|
5731
|
+
this.#failSubscription(state, options.signal, controller, error);
|
|
5732
|
+
}
|
|
5733
|
+
}
|
|
5734
|
+
#failSubscription(state, signal, controller, error) {
|
|
5735
|
+
if (signal.aborted) return;
|
|
5736
|
+
state.failure = { error };
|
|
5737
|
+
controller.close();
|
|
5738
|
+
}
|
|
5739
|
+
#releaseProducer(iterator, reason) {
|
|
5740
|
+
iterator.return?.(reason)?.catch(() => void 0);
|
|
5741
|
+
}
|
|
5587
5742
|
#readTaskId(request) {
|
|
5588
5743
|
const id = request.id;
|
|
5589
5744
|
const context = parseRequestContext(request, {
|
|
@@ -5951,9 +6106,11 @@ var MCPClient = class {
|
|
|
5951
6106
|
async *#openSubscription(notifications, signal, capacity) {
|
|
5952
6107
|
signal.throwIfAborted();
|
|
5953
6108
|
if (!isInteger(capacity) || capacity < 1) throw new MCPError("MCP subscription capacity must be a positive integer", JSONRPC_INVALID_PARAMS);
|
|
6109
|
+
const method = "subscriptions/listen";
|
|
6110
|
+
const opening = this.#refuse(method);
|
|
6111
|
+
if (opening !== void 0) throw opening;
|
|
5954
6112
|
this.#nextId += 1;
|
|
5955
6113
|
const id = this.#nextId;
|
|
5956
|
-
const method = "subscriptions/listen";
|
|
5957
6114
|
const modern = this.#version;
|
|
5958
6115
|
const request = {
|
|
5959
6116
|
jsonrpc: "2.0",
|
|
@@ -6001,7 +6158,16 @@ var MCPClient = class {
|
|
|
6001
6158
|
this.#cancelSubscription(id, /* @__PURE__ */ new Error("MCP subscription closed by its consumer"));
|
|
6002
6159
|
}
|
|
6003
6160
|
}
|
|
6161
|
+
#refuse(method) {
|
|
6162
|
+
if (method === "server/discover") return void 0;
|
|
6163
|
+
if (this.#connected) return void 0;
|
|
6164
|
+
const inflight = this.#connecting;
|
|
6165
|
+
if (inflight !== void 0 && inflight.generation === this.#generation) return void 0;
|
|
6166
|
+
return new MCPError(`MCP client is not connected, so '${method}' was not issued`, JSONRPC_INVALID_REQUEST);
|
|
6167
|
+
}
|
|
6004
6168
|
#request(method, params, deadline, version, options) {
|
|
6169
|
+
const refusal = this.#refuse(method);
|
|
6170
|
+
if (refusal !== void 0) return Promise.reject(refusal);
|
|
6005
6171
|
this.#nextId += 1;
|
|
6006
6172
|
const id = this.#nextId;
|
|
6007
6173
|
const timeout = deadline;
|
|
@@ -6143,16 +6309,20 @@ var MCPClient = class {
|
|
|
6143
6309
|
#tool(name, descriptor) {
|
|
6144
6310
|
const inputSchema = descriptor["inputSchema"];
|
|
6145
6311
|
const description = descriptor["description"];
|
|
6146
|
-
const
|
|
6312
|
+
const title = descriptor["title"];
|
|
6313
|
+
const annotations = descriptor["annotations"];
|
|
6314
|
+
const projected = isMCPToolAnnotations(annotations) ? mcpAnnotationsToTool(annotations) : {};
|
|
6315
|
+
return new Tool({
|
|
6147
6316
|
name,
|
|
6317
|
+
...isString(title) ? { title } : {},
|
|
6318
|
+
...isString(description) ? { description } : {},
|
|
6319
|
+
...isRecord(inputSchema) ? { parameters: inputSchema } : {},
|
|
6320
|
+
...Object.keys(projected).length === 0 ? {} : { annotations: projected },
|
|
6148
6321
|
execute: this.#execute.bind(this, name)
|
|
6149
|
-
};
|
|
6150
|
-
if (isString(description)) options.description = description;
|
|
6151
|
-
if (isRecord(inputSchema)) options.parameters = inputSchema;
|
|
6152
|
-
return new Tool(options);
|
|
6322
|
+
});
|
|
6153
6323
|
}
|
|
6154
|
-
async #execute(name, args) {
|
|
6155
|
-
const outcome = await this.call(name, args);
|
|
6324
|
+
async #execute(name, args, context) {
|
|
6325
|
+
const outcome = await this.call(name, args, { signal: context.signal });
|
|
6156
6326
|
if (outcome.resultType !== "complete") throw new Error(`MCP tool '${name}' answered '${outcome.resultType}' and has no inline value`);
|
|
6157
6327
|
return outcome.value;
|
|
6158
6328
|
}
|
|
@@ -6696,6 +6866,6 @@ function createDuplexClientTransport(transport) {
|
|
|
6696
6866
|
};
|
|
6697
6867
|
}
|
|
6698
6868
|
//#endregion
|
|
6699
|
-
export { DEFAULT_MCP_CACHE_TTL, DEFAULT_MCP_CLIENT_NAME, DEFAULT_MCP_CLIENT_VERSION, DEFAULT_MCP_LIMITS, DEFAULT_MCP_REQUEST_TIMEOUT, DEFAULT_MCP_SUBSCRIPTION_CAPACITY, EMPTY_MCP_ARGUMENTS, HTTPClientTransport, JSONRPC_INTERNAL_ERROR, JSONRPC_INVALID_PARAMS, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_PARSE_ERROR, JSONRPC_SERVER_ERROR, MCPClient, MCPError, MCPLegacy, MCPLegacyClientTransport, MCPMethodManager, MCPProgressReporter, MCPServer, MCPStreamController, MCPTaskClient, MCPTextStreamController, MCP_EXTENSION_TASKS, MCP_FALLBACK_VERSION, MCP_HANDSHAKE_VERSION, MCP_HEADER_ANNOTATION, MCP_HEADER_MISMATCH, MCP_LOOKUP_PAGES, MCP_META_CAPABILITIES, MCP_META_CLIENT, MCP_META_SERVER, MCP_META_SUBSCRIPTION, MCP_META_VERSION, MCP_METHOD_HEADER, MCP_MISSING_CAPABILITY, MCP_MODERN_VERSION, MCP_NAME_HEADER, MCP_PARAM_PREFIX, MCP_PROTOCOL_VERSION_HEADER, MCP_SENTINEL_PREFIX, MCP_SENTINEL_SUFFIX, MCP_SESSION_HEADER, MCP_UNSUPPORTED_VERSION, MCP_WEBSOCKET_SUBPROTOCOL, SUPPORTED_LEGACY_PROTOCOL_VERSIONS, SUPPORTED_MCP_VERSIONS, SUPPORTED_MODERN_PROTOCOL_VERSIONS, bindClient, bindServer, buildCallOutcome, buildCancelledNotification, buildDiscoverResult, buildHeaderParameters, buildHeaderProjection, buildInitializeResult, buildJSONRPCError, buildJSONRPCResult, buildMethodOptions, buildModernResult, buildProgressNotification, buildResponseError, buildSubscriptionAcknowledgement, buildSubscriptionFilter, buildSubscriptionResult, buildToolCall, buildToolDescriptors, computeMissingCapabilities, countHeaderAnnotations, createDuplexClientTransport, createMCPClient, createMCPLegacy, createMCPLegacyClientTransport, createMCPServer, decodeBoundedMessage, decodeEvent, decodeSentinel, deliverMessage, digestJSON, encodeSentinel, extractContentText, extractHeaderAnnotations, extractToolSchema, inferEra, inferRequestEra, inferRequestVersion, inferVersion, isAbsoluteURI, isBoundedJSON, isBoundedString, isElicitContent, isFieldToken, isInitializeRequest, isJSONObject, isJSONRPCError, isJSONRPCErrorResponse, isJSONRPCId, isJSONRPCInvocation, isJSONRPCMessage, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse, isJSONRPCResultResponse, isMCPAnnotations, isMCPBlobResource, isMCPCallResult, isMCPClientCapabilities, isMCPCompletion, isMCPCompletionParams, isMCPCompletionReference, isMCPCompletionResult, isMCPContent, isMCPElicitFieldSchema, isMCPElicitForm, isMCPElicitRequest, isMCPElicitResult, isMCPElicitSchema, isMCPElicitURL, isMCPError, isMCPHeaderPrimitive, isMCPIcon, isMCPIdentity, isMCPInputRequest, isMCPInputRequestMap, isMCPInputResponse, isMCPInputResult, isMCPLegacyResult, isMCPLegacyVersion, isMCPLoggingLevel, isMCPMetaKey, isMCPMetaObject, isMCPModernVersion, isMCPNotificationMetaObject, isMCPPaginationParams, isMCPProgress, isMCPPrompt, isMCPPromptArgument, isMCPPromptGetResult, isMCPPromptMessage, isMCPPromptPage, isMCPResource, isMCPResourceContents, isMCPResourcePage, isMCPResourceTemplate, isMCPResourceTemplatePage, isMCPResult, isMCPResultMetaObject, isMCPRoot, isMCPRootResult, isMCPSampleContent, isMCPSampleResult, isMCPServerCapabilities, isMCPStringArguments, isMCPSubscriptionFilter, isMCPSubscriptionResult, isMCPTaskDetail, isMCPTaskDetailResult, isMCPTaskNotification, isMCPTaskResult, isMCPTaskStatus, isMCPTextResource, isMCPVersion, isModernRequest, isRFC3339Date, isRFC3339DateTime, isStandardBase64, legacyInvocationToModern, legacyResultToModern, matchesResultType, matchesSubscriptionNotification, modernInvocationToLegacy, modernResultToLegacy, parseJSONRPCMessage, parseMCPInputState, parseRequestContext, readCancelledId, readEventStream, renderHeaderValue, sendStream, serializeJSON, snapshotJSON, snapshotToolResult, stampSubscriptionNotification, supportsFormElicitation, supportsTask };
|
|
6869
|
+
export { DEFAULT_MCP_CACHE_TTL, DEFAULT_MCP_CLIENT_NAME, DEFAULT_MCP_CLIENT_VERSION, DEFAULT_MCP_LIMITS, DEFAULT_MCP_REQUEST_TIMEOUT, DEFAULT_MCP_SUBSCRIPTION_CAPACITY, EMPTY_MCP_ARGUMENTS, HTTPClientTransport, JSONRPC_INTERNAL_ERROR, JSONRPC_INVALID_PARAMS, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_PARSE_ERROR, JSONRPC_SERVER_ERROR, MCPClient, MCPError, MCPLegacy, MCPLegacyClientTransport, MCPMethodManager, MCPProgressReporter, MCPServer, MCPStreamController, MCPTaskClient, MCPTextStreamController, MCP_EXTENSION_TASKS, MCP_FALLBACK_VERSION, MCP_HANDSHAKE_VERSION, MCP_HEADER_ANNOTATION, MCP_HEADER_MISMATCH, MCP_LOOKUP_PAGES, MCP_META_CAPABILITIES, MCP_META_CLIENT, MCP_META_SERVER, MCP_META_SUBSCRIPTION, MCP_META_VERSION, MCP_METHOD_HEADER, MCP_MISSING_CAPABILITY, MCP_MODERN_VERSION, MCP_NAME_HEADER, MCP_PARAM_PREFIX, MCP_PROTOCOL_VERSION_HEADER, MCP_SENTINEL_PREFIX, MCP_SENTINEL_SUFFIX, MCP_SESSION_HEADER, MCP_UNSUPPORTED_VERSION, MCP_WEBSOCKET_SUBPROTOCOL, SUPPORTED_LEGACY_PROTOCOL_VERSIONS, SUPPORTED_MCP_VERSIONS, SUPPORTED_MODERN_PROTOCOL_VERSIONS, bindClient, bindServer, buildCallOutcome, buildCancelledNotification, buildDiscoverResult, buildHeaderParameters, buildHeaderProjection, buildInitializeResult, buildJSONRPCError, buildJSONRPCResult, buildMethodOptions, buildModernResult, buildProgressNotification, buildResponseError, buildSubscriptionAcknowledgement, buildSubscriptionFilter, buildSubscriptionResult, buildToolCall, buildToolDescriptors, computeMissingCapabilities, countHeaderAnnotations, createDuplexClientTransport, createMCPClient, createMCPLegacy, createMCPLegacyClientTransport, createMCPServer, decodeBoundedMessage, decodeEvent, decodeSentinel, deliverMessage, digestJSON, encodeSentinel, extractContentText, extractHeaderAnnotations, extractToolSchema, inferEra, inferRequestEra, inferRequestVersion, inferVersion, isAbsoluteURI, isBoundedJSON, isBoundedString, isElicitContent, isFieldToken, isInitializeRequest, isJSONObject, isJSONRPCError, isJSONRPCErrorResponse, isJSONRPCId, isJSONRPCInvocation, isJSONRPCMessage, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse, isJSONRPCResultResponse, isMCPAnnotations, isMCPBlobResource, isMCPCallResult, isMCPClientCapabilities, isMCPCompletion, isMCPCompletionParams, isMCPCompletionReference, isMCPCompletionResult, isMCPConsumerFilter, isMCPContent, isMCPElicitFieldSchema, isMCPElicitForm, isMCPElicitRequest, isMCPElicitResult, isMCPElicitSchema, isMCPElicitURL, isMCPError, isMCPHeaderPrimitive, isMCPIcon, isMCPIdentity, isMCPInputRequest, isMCPInputRequestMap, isMCPInputResponse, isMCPInputResult, isMCPLegacyResult, isMCPLegacyVersion, isMCPLoggingLevel, isMCPMetaKey, isMCPMetaObject, isMCPModernVersion, isMCPNotificationMetaObject, isMCPPaginationParams, isMCPProgress, isMCPPrompt, isMCPPromptArgument, isMCPPromptGetResult, isMCPPromptMessage, isMCPPromptPage, isMCPResource, isMCPResourceContents, isMCPResourcePage, isMCPResourceTemplate, isMCPResourceTemplatePage, isMCPResult, isMCPResultMetaObject, isMCPRoot, isMCPRootResult, isMCPSampleContent, isMCPSampleResult, isMCPServerCapabilities, isMCPStringArguments, isMCPSubscriptionFilter, isMCPSubscriptionResult, isMCPTaskDetail, isMCPTaskDetailResult, isMCPTaskNotification, isMCPTaskResult, isMCPTaskStatus, isMCPTextResource, isMCPToolAnnotations, isMCPVersion, isModernRequest, isRFC3339Date, isRFC3339DateTime, isStandardBase64, legacyInvocationToModern, legacyResultToModern, matchesResultType, matchesSubscriptionNotification, mcpAnnotationsToTool, modernInvocationToLegacy, modernResultToLegacy, parseJSONRPCMessage, parseMCPInputState, parseRequestContext, readCancelledId, readEventStream, renderHeaderValue, sendStream, serializeJSON, snapshotJSON, snapshotToolResult, stampSubscriptionNotification, supportsFormElicitation, supportsTask, toolAnnotationsToMCP };
|
|
6700
6870
|
|
|
6701
6871
|
//# sourceMappingURL=index.js.map
|