@orkestrel/mcp 0.0.31 → 0.0.33
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/core/index.cjs +55 -60
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.js +56 -61
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +1 -1
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +2 -2
- package/dist/src/server/index.js.map +1 -1
- package/package.json +24 -23
package/dist/src/core/index.cjs
CHANGED
|
@@ -326,11 +326,7 @@ var MCPError = class extends Error {
|
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
328
|
function isMCPError(value) {
|
|
329
|
-
|
|
330
|
-
return value instanceof MCPError;
|
|
331
|
-
} catch {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
329
|
+
return (0, _orkestrel_contract.isInstance)(value, MCPError);
|
|
334
330
|
}
|
|
335
331
|
//#endregion
|
|
336
332
|
//#region src/core/cloners.ts
|
|
@@ -581,7 +577,7 @@ function parseMCPInputState(value) {
|
|
|
581
577
|
const name = parsed["name"];
|
|
582
578
|
const digest = parsed["digest"];
|
|
583
579
|
const state = parsed["state"];
|
|
584
|
-
if (!(0, _orkestrel_contract.isString)(principal) || principal.length === 0 || !(0, _orkestrel_contract.
|
|
580
|
+
if (!(0, _orkestrel_contract.isString)(principal) || principal.length === 0 || !(0, _orkestrel_contract.isFiniteNumber)(expiry)) return;
|
|
585
581
|
if (!isJSONRPCId(id)) return void 0;
|
|
586
582
|
if (!(0, _orkestrel_contract.isString)(version) || !(0, _orkestrel_contract.isString)(method) || !(0, _orkestrel_contract.isString)(name)) return void 0;
|
|
587
583
|
if (!(0, _orkestrel_contract.isString)(digest) || !(0, _orkestrel_contract.isUndefined)(state) && !(0, _orkestrel_contract.isJSONValue)(state)) return void 0;
|
|
@@ -744,9 +740,9 @@ function serializeJSON(value, limits) {
|
|
|
744
740
|
const limit = limits.bytes;
|
|
745
741
|
const depth = limits.depth;
|
|
746
742
|
const breadth = limits.keys;
|
|
747
|
-
if (!
|
|
748
|
-
if (!
|
|
749
|
-
if (breadth !== void 0 && (!
|
|
743
|
+
if (!(0, _orkestrel_contract.isInteger)(limit) || limit < 0) return void 0;
|
|
744
|
+
if (!(0, _orkestrel_contract.isInteger)(depth) || depth < 0) return void 0;
|
|
745
|
+
if (breadth !== void 0 && (!(0, _orkestrel_contract.isInteger)(breadth) || breadth < 0)) return void 0;
|
|
750
746
|
let bytes = 0;
|
|
751
747
|
let keys = 0;
|
|
752
748
|
const chunks = [];
|
|
@@ -860,7 +856,7 @@ function serializeJSON(value, limits) {
|
|
|
860
856
|
continue;
|
|
861
857
|
}
|
|
862
858
|
if ((0, _orkestrel_contract.isNumber)(entry)) {
|
|
863
|
-
if (!
|
|
859
|
+
if (!(0, _orkestrel_contract.isFiniteNumber)(entry)) return void 0;
|
|
864
860
|
const text = JSON.stringify(entry);
|
|
865
861
|
if (!(0, _orkestrel_contract.isString)(text)) return void 0;
|
|
866
862
|
bytes += text.length;
|
|
@@ -876,10 +872,10 @@ function serializeJSON(value, limits) {
|
|
|
876
872
|
});
|
|
877
873
|
continue;
|
|
878
874
|
}
|
|
879
|
-
if (
|
|
880
|
-
if (
|
|
875
|
+
if (!(0, _orkestrel_contract.isObject)(entry) || ancestors.has(entry)) return void 0;
|
|
876
|
+
if ((0, _orkestrel_contract.isArray)(entry)) {
|
|
881
877
|
const lengthDescriptor = Reflect.getOwnPropertyDescriptor(entry, "length");
|
|
882
|
-
if (lengthDescriptor === void 0 || !Object.hasOwn(lengthDescriptor, "value") || !(0, _orkestrel_contract.isNumber)(lengthDescriptor.value) || !
|
|
878
|
+
if (lengthDescriptor === void 0 || !Object.hasOwn(lengthDescriptor, "value") || !(0, _orkestrel_contract.isNumber)(lengthDescriptor.value) || !(0, _orkestrel_contract.isInteger)(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable === true || lengthDescriptor.configurable === true) return void 0;
|
|
883
879
|
const length = lengthDescriptor.value;
|
|
884
880
|
keys += length;
|
|
885
881
|
bytes += 2 + (length === 0 ? 0 : length - 1);
|
|
@@ -896,7 +892,7 @@ function serializeJSON(value, limits) {
|
|
|
896
892
|
continue;
|
|
897
893
|
}
|
|
898
894
|
const index = Number(name);
|
|
899
|
-
if (!
|
|
895
|
+
if (!(0, _orkestrel_contract.isInteger)(index) || index < 0 || index >= length || String(index) !== name) return void 0;
|
|
900
896
|
}
|
|
901
897
|
if (!foundLength) return void 0;
|
|
902
898
|
const values = [];
|
|
@@ -1117,10 +1113,9 @@ function buildCallOutcome(name, result) {
|
|
|
1117
1113
|
if ((0, _orkestrel_contract.isRecord)(result) && result["isError"] === true) throw new Error(text.length > 0 ? text : `MCP tool '${name}' failed`);
|
|
1118
1114
|
let value;
|
|
1119
1115
|
if ((0, _orkestrel_contract.isRecord)(result) && Object.hasOwn(result, "structuredContent")) value = result["structuredContent"];
|
|
1120
|
-
else if (text.length > 0)
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
value = text;
|
|
1116
|
+
else if (text.length > 0) {
|
|
1117
|
+
const parsed = (0, _orkestrel_contract.parseJSON)(text);
|
|
1118
|
+
value = parsed === void 0 ? text : parsed;
|
|
1124
1119
|
}
|
|
1125
1120
|
return Object.freeze({
|
|
1126
1121
|
resultType: "complete",
|
|
@@ -1136,7 +1131,7 @@ function buildCallOutcome(name, result) {
|
|
|
1136
1131
|
*/
|
|
1137
1132
|
function buildToolCall(request, args) {
|
|
1138
1133
|
const name = request.params?.["name"];
|
|
1139
|
-
if (
|
|
1134
|
+
if (!(0, _orkestrel_contract.isString)(name)) return void 0;
|
|
1140
1135
|
const rawArguments = request.params?.["arguments"];
|
|
1141
1136
|
return {
|
|
1142
1137
|
id: String(request.id),
|
|
@@ -1321,7 +1316,7 @@ function modernResultToLegacy(result) {
|
|
|
1321
1316
|
const projected = {};
|
|
1322
1317
|
for (const [key, value] of Object.entries(result)) {
|
|
1323
1318
|
if (key === "resultType" || key === "ttlMs" || key === "cacheScope") continue;
|
|
1324
|
-
if (key === "content" &&
|
|
1319
|
+
if (key === "content" && (0, _orkestrel_contract.isArray)(value)) {
|
|
1325
1320
|
projected[key] = value.map((entry) => (0, _orkestrel_contract.isRecord)(entry) && entry["type"] === "text" && (0, _orkestrel_contract.isString)(entry["text"]) ? {
|
|
1326
1321
|
type: "text",
|
|
1327
1322
|
text: entry["text"]
|
|
@@ -1434,7 +1429,7 @@ function matchesSubscriptionNotification(notification, filter) {
|
|
|
1434
1429
|
if (notification.method === "notifications/resources/list_changed") return filter.resourcesListChanged === true;
|
|
1435
1430
|
if (notification.method === "notifications/resources/updated") {
|
|
1436
1431
|
const uri = notification.params?.["uri"];
|
|
1437
|
-
return
|
|
1432
|
+
return (0, _orkestrel_contract.isString)(uri) && filter.resourceSubscriptions?.includes(uri) === true;
|
|
1438
1433
|
}
|
|
1439
1434
|
if (notification.method === "notifications/tasks") return isMCPTaskNotification(notification) && filter.taskIds?.includes(notification.params.taskId) === true;
|
|
1440
1435
|
return false;
|
|
@@ -2148,7 +2143,7 @@ function bindServer(server, transport) {
|
|
|
2148
2143
|
try {
|
|
2149
2144
|
const answer = await server.handle(message, { signal: request.signal });
|
|
2150
2145
|
if (answer === void 0) return;
|
|
2151
|
-
if (
|
|
2146
|
+
if ((0, _orkestrel_contract.isString)(answer)) {
|
|
2152
2147
|
if (!request.signal.aborted) await transport.send(answer);
|
|
2153
2148
|
} else if (request.signal.aborted) await answer[Symbol.asyncDispose]();
|
|
2154
2149
|
else await sendStream(answer, transport);
|
|
@@ -2549,7 +2544,7 @@ function isMCPAnnotations(value) {
|
|
|
2549
2544
|
const audience = annotations["audience"];
|
|
2550
2545
|
const priority = annotations["priority"];
|
|
2551
2546
|
const lastModified = annotations["lastModified"];
|
|
2552
|
-
if (!(0, _orkestrel_contract.isUndefined)(audience) && (!
|
|
2547
|
+
if (!(0, _orkestrel_contract.isUndefined)(audience) && (!(0, _orkestrel_contract.isArray)(audience) || !audience.every((role) => role === "user" || role === "assistant"))) return false;
|
|
2553
2548
|
if (!(0, _orkestrel_contract.isUndefined)(priority) && (!(0, _orkestrel_contract.isFiniteNumber)(priority) || priority < 0 || priority > 1)) return false;
|
|
2554
2549
|
return (0, _orkestrel_contract.isUndefined)(lastModified) || (0, _orkestrel_contract.isString)(lastModified);
|
|
2555
2550
|
} catch {
|
|
@@ -2571,7 +2566,7 @@ function isMCPIcon(value) {
|
|
|
2571
2566
|
const mimeType = icon["mimeType"];
|
|
2572
2567
|
const sizes = icon["sizes"];
|
|
2573
2568
|
const theme = icon["theme"];
|
|
2574
|
-
return ((0, _orkestrel_contract.isUndefined)(mimeType) || (0, _orkestrel_contract.isString)(mimeType)) && ((0, _orkestrel_contract.isUndefined)(sizes) ||
|
|
2569
|
+
return ((0, _orkestrel_contract.isUndefined)(mimeType) || (0, _orkestrel_contract.isString)(mimeType)) && ((0, _orkestrel_contract.isUndefined)(sizes) || (0, _orkestrel_contract.isArray)(sizes) && sizes.every((size) => (0, _orkestrel_contract.isString)(size))) && ((0, _orkestrel_contract.isUndefined)(theme) || theme === "light" || theme === "dark");
|
|
2575
2570
|
} catch {
|
|
2576
2571
|
return false;
|
|
2577
2572
|
}
|
|
@@ -2587,7 +2582,7 @@ function isMCPIdentity(value) {
|
|
|
2587
2582
|
const description = identity["description"];
|
|
2588
2583
|
const website = identity["websiteUrl"];
|
|
2589
2584
|
const icons = identity["icons"];
|
|
2590
|
-
return ((0, _orkestrel_contract.isUndefined)(title) || (0, _orkestrel_contract.isString)(title)) && ((0, _orkestrel_contract.isUndefined)(description) || (0, _orkestrel_contract.isString)(description)) && ((0, _orkestrel_contract.isUndefined)(website) || isAbsoluteURI(website)) && ((0, _orkestrel_contract.isUndefined)(icons) ||
|
|
2585
|
+
return ((0, _orkestrel_contract.isUndefined)(title) || (0, _orkestrel_contract.isString)(title)) && ((0, _orkestrel_contract.isUndefined)(description) || (0, _orkestrel_contract.isString)(description)) && ((0, _orkestrel_contract.isUndefined)(website) || isAbsoluteURI(website)) && ((0, _orkestrel_contract.isUndefined)(icons) || (0, _orkestrel_contract.isArray)(icons) && icons.every((icon) => isMCPIcon(icon)));
|
|
2591
2586
|
} catch {
|
|
2592
2587
|
return false;
|
|
2593
2588
|
}
|
|
@@ -2698,7 +2693,7 @@ function isMCPResource(value) {
|
|
|
2698
2693
|
const resource = owned.value;
|
|
2699
2694
|
const icons = resource["icons"];
|
|
2700
2695
|
const size = resource["size"];
|
|
2701
|
-
return isAbsoluteURI(resource["uri"]) && (0, _orkestrel_contract.isString)(resource["name"]) && ((0, _orkestrel_contract.isUndefined)(resource["title"]) || (0, _orkestrel_contract.isString)(resource["title"])) && ((0, _orkestrel_contract.isUndefined)(resource["description"]) || (0, _orkestrel_contract.isString)(resource["description"])) && ((0, _orkestrel_contract.isUndefined)(resource["mimeType"]) || (0, _orkestrel_contract.isString)(resource["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(resource["annotations"]) || isMCPAnnotations(resource["annotations"])) && ((0, _orkestrel_contract.isUndefined)(size) || (0, _orkestrel_contract.isInteger)(size) && size >= 0) && ((0, _orkestrel_contract.isUndefined)(icons) ||
|
|
2696
|
+
return isAbsoluteURI(resource["uri"]) && (0, _orkestrel_contract.isString)(resource["name"]) && ((0, _orkestrel_contract.isUndefined)(resource["title"]) || (0, _orkestrel_contract.isString)(resource["title"])) && ((0, _orkestrel_contract.isUndefined)(resource["description"]) || (0, _orkestrel_contract.isString)(resource["description"])) && ((0, _orkestrel_contract.isUndefined)(resource["mimeType"]) || (0, _orkestrel_contract.isString)(resource["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(resource["annotations"]) || isMCPAnnotations(resource["annotations"])) && ((0, _orkestrel_contract.isUndefined)(size) || (0, _orkestrel_contract.isInteger)(size) && size >= 0) && ((0, _orkestrel_contract.isUndefined)(icons) || (0, _orkestrel_contract.isArray)(icons) && icons.every((icon) => isMCPIcon(icon))) && ((0, _orkestrel_contract.isUndefined)(resource["_meta"]) || isMCPMetaObject(resource["_meta"]));
|
|
2702
2697
|
} catch {
|
|
2703
2698
|
return false;
|
|
2704
2699
|
}
|
|
@@ -2741,7 +2736,7 @@ function isMCPResourceTemplate(value) {
|
|
|
2741
2736
|
try {
|
|
2742
2737
|
const template = owned.value;
|
|
2743
2738
|
const icons = template["icons"];
|
|
2744
|
-
return (0, _orkestrel_contract.isString)(template["uriTemplate"]) && template["uriTemplate"].length > 0 && (0, _orkestrel_contract.isString)(template["name"]) && ((0, _orkestrel_contract.isUndefined)(template["title"]) || (0, _orkestrel_contract.isString)(template["title"])) && ((0, _orkestrel_contract.isUndefined)(template["description"]) || (0, _orkestrel_contract.isString)(template["description"])) && ((0, _orkestrel_contract.isUndefined)(template["mimeType"]) || (0, _orkestrel_contract.isString)(template["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(template["annotations"]) || isMCPAnnotations(template["annotations"])) && ((0, _orkestrel_contract.isUndefined)(icons) ||
|
|
2739
|
+
return (0, _orkestrel_contract.isString)(template["uriTemplate"]) && template["uriTemplate"].length > 0 && (0, _orkestrel_contract.isString)(template["name"]) && ((0, _orkestrel_contract.isUndefined)(template["title"]) || (0, _orkestrel_contract.isString)(template["title"])) && ((0, _orkestrel_contract.isUndefined)(template["description"]) || (0, _orkestrel_contract.isString)(template["description"])) && ((0, _orkestrel_contract.isUndefined)(template["mimeType"]) || (0, _orkestrel_contract.isString)(template["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(template["annotations"]) || isMCPAnnotations(template["annotations"])) && ((0, _orkestrel_contract.isUndefined)(icons) || (0, _orkestrel_contract.isArray)(icons) && icons.every((icon) => isMCPIcon(icon))) && ((0, _orkestrel_contract.isUndefined)(template["_meta"]) || isMCPMetaObject(template["_meta"]));
|
|
2745
2740
|
} catch {
|
|
2746
2741
|
return false;
|
|
2747
2742
|
}
|
|
@@ -2781,7 +2776,7 @@ function isMCPResourcePage(value) {
|
|
|
2781
2776
|
if (!owned.success) return false;
|
|
2782
2777
|
const resources = owned.value["resources"];
|
|
2783
2778
|
const cursor = owned.value["nextCursor"];
|
|
2784
|
-
return
|
|
2779
|
+
return (0, _orkestrel_contract.isArray)(resources) && resources.every((resource) => isMCPResource(resource)) && ((0, _orkestrel_contract.isUndefined)(cursor) || (0, _orkestrel_contract.isString)(cursor));
|
|
2785
2780
|
}
|
|
2786
2781
|
/**
|
|
2787
2782
|
* Determines whether a value is one consumer-owned resource-template page.
|
|
@@ -2794,7 +2789,7 @@ function isMCPResourceTemplatePage(value) {
|
|
|
2794
2789
|
if (!owned.success) return false;
|
|
2795
2790
|
const templates = owned.value["resourceTemplates"];
|
|
2796
2791
|
const cursor = owned.value["nextCursor"];
|
|
2797
|
-
return
|
|
2792
|
+
return (0, _orkestrel_contract.isArray)(templates) && templates.every((template) => isMCPResourceTemplate(template)) && ((0, _orkestrel_contract.isUndefined)(cursor) || (0, _orkestrel_contract.isString)(cursor));
|
|
2798
2793
|
}
|
|
2799
2794
|
/**
|
|
2800
2795
|
* Determines whether a value is a string-valued MCP argument record.
|
|
@@ -2830,7 +2825,7 @@ function isMCPPrompt(value) {
|
|
|
2830
2825
|
const prompt = owned.value;
|
|
2831
2826
|
const argumentsValue = prompt["arguments"];
|
|
2832
2827
|
const icons = prompt["icons"];
|
|
2833
|
-
return (0, _orkestrel_contract.isString)(prompt["name"]) && ((0, _orkestrel_contract.isUndefined)(prompt["title"]) || (0, _orkestrel_contract.isString)(prompt["title"])) && ((0, _orkestrel_contract.isUndefined)(prompt["description"]) || (0, _orkestrel_contract.isString)(prompt["description"])) && ((0, _orkestrel_contract.isUndefined)(argumentsValue) ||
|
|
2828
|
+
return (0, _orkestrel_contract.isString)(prompt["name"]) && ((0, _orkestrel_contract.isUndefined)(prompt["title"]) || (0, _orkestrel_contract.isString)(prompt["title"])) && ((0, _orkestrel_contract.isUndefined)(prompt["description"]) || (0, _orkestrel_contract.isString)(prompt["description"])) && ((0, _orkestrel_contract.isUndefined)(argumentsValue) || (0, _orkestrel_contract.isArray)(argumentsValue) && argumentsValue.every((argument) => isMCPPromptArgument(argument))) && ((0, _orkestrel_contract.isUndefined)(icons) || (0, _orkestrel_contract.isArray)(icons) && icons.every((icon) => isMCPIcon(icon))) && ((0, _orkestrel_contract.isUndefined)(prompt["_meta"]) || isMCPMetaObject(prompt["_meta"]));
|
|
2834
2829
|
}
|
|
2835
2830
|
/**
|
|
2836
2831
|
* Determines whether a value is one prompt message with existing rich content.
|
|
@@ -2853,7 +2848,7 @@ function isMCPPromptPage(value) {
|
|
|
2853
2848
|
if (!owned.success) return false;
|
|
2854
2849
|
const prompts = owned.value["prompts"];
|
|
2855
2850
|
const cursor = owned.value["nextCursor"];
|
|
2856
|
-
return
|
|
2851
|
+
return (0, _orkestrel_contract.isArray)(prompts) && prompts.every((prompt) => isMCPPrompt(prompt)) && ((0, _orkestrel_contract.isUndefined)(cursor) || (0, _orkestrel_contract.isString)(cursor));
|
|
2857
2852
|
}
|
|
2858
2853
|
/**
|
|
2859
2854
|
* Determines whether a value is one complete `prompts/get` result.
|
|
@@ -2866,7 +2861,7 @@ function isMCPPromptGetResult(value) {
|
|
|
2866
2861
|
if (!owned.success) return false;
|
|
2867
2862
|
const result = owned.value;
|
|
2868
2863
|
const messages = result["messages"];
|
|
2869
|
-
return result["resultType"] === "complete" && ((0, _orkestrel_contract.isUndefined)(result["description"]) || (0, _orkestrel_contract.isString)(result["description"])) &&
|
|
2864
|
+
return result["resultType"] === "complete" && ((0, _orkestrel_contract.isUndefined)(result["description"]) || (0, _orkestrel_contract.isString)(result["description"])) && (0, _orkestrel_contract.isArray)(messages) && messages.every((message) => isMCPPromptMessage(message)) && ((0, _orkestrel_contract.isUndefined)(result["_meta"]) || isMCPResultMetaObject(result["_meta"]));
|
|
2870
2865
|
}
|
|
2871
2866
|
/**
|
|
2872
2867
|
* Determines whether a value is a prompt or resource-template completion reference.
|
|
@@ -2911,7 +2906,7 @@ function isMCPCompletion(value) {
|
|
|
2911
2906
|
const completion = owned.value;
|
|
2912
2907
|
const values = completion["values"];
|
|
2913
2908
|
const total = completion["total"];
|
|
2914
|
-
return
|
|
2909
|
+
return (0, _orkestrel_contract.isArray)(values) && values.every((candidate) => (0, _orkestrel_contract.isString)(candidate)) && ((0, _orkestrel_contract.isUndefined)(total) || (0, _orkestrel_contract.isInteger)(total) && total >= 0) && ((0, _orkestrel_contract.isUndefined)(completion["hasMore"]) || (0, _orkestrel_contract.isBoolean)(completion["hasMore"]));
|
|
2915
2910
|
}
|
|
2916
2911
|
/**
|
|
2917
2912
|
* Determines whether a value is one complete, capped `completion/complete` result.
|
|
@@ -2949,7 +2944,7 @@ function isMCPContent(value) {
|
|
|
2949
2944
|
case "resource_link": {
|
|
2950
2945
|
const icons = content["icons"];
|
|
2951
2946
|
const size = content["size"];
|
|
2952
|
-
return (0, _orkestrel_contract.isString)(content["name"]) && isAbsoluteURI(content["uri"]) && ((0, _orkestrel_contract.isUndefined)(content["title"]) || (0, _orkestrel_contract.isString)(content["title"])) && ((0, _orkestrel_contract.isUndefined)(content["description"]) || (0, _orkestrel_contract.isString)(content["description"])) && ((0, _orkestrel_contract.isUndefined)(content["mimeType"]) || (0, _orkestrel_contract.isString)(content["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(icons) ||
|
|
2947
|
+
return (0, _orkestrel_contract.isString)(content["name"]) && isAbsoluteURI(content["uri"]) && ((0, _orkestrel_contract.isUndefined)(content["title"]) || (0, _orkestrel_contract.isString)(content["title"])) && ((0, _orkestrel_contract.isUndefined)(content["description"]) || (0, _orkestrel_contract.isString)(content["description"])) && ((0, _orkestrel_contract.isUndefined)(content["mimeType"]) || (0, _orkestrel_contract.isString)(content["mimeType"])) && ((0, _orkestrel_contract.isUndefined)(icons) || (0, _orkestrel_contract.isArray)(icons) && icons.every((icon) => isMCPIcon(icon))) && ((0, _orkestrel_contract.isUndefined)(size) || (0, _orkestrel_contract.isInteger)(size) && size >= 0);
|
|
2953
2948
|
}
|
|
2954
2949
|
default: return false;
|
|
2955
2950
|
}
|
|
@@ -3023,7 +3018,7 @@ function isMCPCallResult(value) {
|
|
|
3023
3018
|
const content = result["content"];
|
|
3024
3019
|
const error = result["isError"];
|
|
3025
3020
|
const metadata = result["_meta"];
|
|
3026
|
-
return
|
|
3021
|
+
return (0, _orkestrel_contract.isArray)(content) && content.every((entry) => isMCPContent(entry)) && ((0, _orkestrel_contract.isUndefined)(error) || (0, _orkestrel_contract.isBoolean)(error)) && ((0, _orkestrel_contract.isUndefined)(metadata) || isMCPResultMetaObject(metadata));
|
|
3027
3022
|
} catch {
|
|
3028
3023
|
return false;
|
|
3029
3024
|
}
|
|
@@ -3212,7 +3207,7 @@ function isMCPTaskNotification(value) {
|
|
|
3212
3207
|
* ```
|
|
3213
3208
|
*/
|
|
3214
3209
|
function isBoundedString(value, bytes) {
|
|
3215
|
-
if (!(0, _orkestrel_contract.isString)(value) || !
|
|
3210
|
+
if (!(0, _orkestrel_contract.isString)(value) || !(0, _orkestrel_contract.isInteger)(bytes) || bytes < 0) return false;
|
|
3216
3211
|
let measured = 0;
|
|
3217
3212
|
for (let index = 0; index < value.length; index += 1) {
|
|
3218
3213
|
const code = value.charCodeAt(index);
|
|
@@ -3397,21 +3392,21 @@ function isMCPElicitFieldSchema(value) {
|
|
|
3397
3392
|
const names = schema["enumNames"];
|
|
3398
3393
|
const titled = schema["oneOf"];
|
|
3399
3394
|
if (!(0, _orkestrel_contract.isUndefined)(minimum) && (!(0, _orkestrel_contract.isInteger)(minimum) || minimum < 0) || !(0, _orkestrel_contract.isUndefined)(maximum) && (!(0, _orkestrel_contract.isInteger)(maximum) || maximum < 0) || !(0, _orkestrel_contract.isUndefined)(fallback) && !(0, _orkestrel_contract.isString)(fallback) || !(0, _orkestrel_contract.isUndefined)(format) && format !== "uri" && format !== "email" && format !== "date" && format !== "date-time") return false;
|
|
3400
|
-
if (!(0, _orkestrel_contract.isUndefined)(choices) && (!
|
|
3401
|
-
if (!(0, _orkestrel_contract.isUndefined)(names) && ((0, _orkestrel_contract.isUndefined)(choices) || !
|
|
3402
|
-
return !(!(0, _orkestrel_contract.isUndefined)(titled) && (!
|
|
3395
|
+
if (!(0, _orkestrel_contract.isUndefined)(choices) && (!(0, _orkestrel_contract.isArray)(choices) || !choices.every(_orkestrel_contract.isString))) return false;
|
|
3396
|
+
if (!(0, _orkestrel_contract.isUndefined)(names) && ((0, _orkestrel_contract.isUndefined)(choices) || !(0, _orkestrel_contract.isArray)(names) || !names.every(_orkestrel_contract.isString))) return false;
|
|
3397
|
+
return !(!(0, _orkestrel_contract.isUndefined)(titled) && (!(0, _orkestrel_contract.isArray)(titled) || !titled.every((choice) => isJSONObject(choice) && (0, _orkestrel_contract.isString)(choice["const"]) && (0, _orkestrel_contract.isString)(choice["title"]))));
|
|
3403
3398
|
}
|
|
3404
3399
|
if (schema["type"] !== "array") return false;
|
|
3405
3400
|
const minimum = schema["minItems"];
|
|
3406
3401
|
const maximum = schema["maxItems"];
|
|
3407
3402
|
const items = schema["items"];
|
|
3408
|
-
if (!(0, _orkestrel_contract.isUndefined)(minimum) && (!(0, _orkestrel_contract.isInteger)(minimum) || minimum < 0) || !(0, _orkestrel_contract.isUndefined)(maximum) && (!(0, _orkestrel_contract.isInteger)(maximum) || maximum < 0) || !(0, _orkestrel_contract.isUndefined)(fallback) && (!
|
|
3403
|
+
if (!(0, _orkestrel_contract.isUndefined)(minimum) && (!(0, _orkestrel_contract.isInteger)(minimum) || minimum < 0) || !(0, _orkestrel_contract.isUndefined)(maximum) && (!(0, _orkestrel_contract.isInteger)(maximum) || maximum < 0) || !(0, _orkestrel_contract.isUndefined)(fallback) && (!(0, _orkestrel_contract.isArray)(fallback) || !fallback.every((item) => (0, _orkestrel_contract.isString)(item))) || !isJSONObject(items)) return false;
|
|
3409
3404
|
const itemType = items["type"];
|
|
3410
3405
|
const choices = items["enum"];
|
|
3411
3406
|
const titled = items["anyOf"];
|
|
3412
3407
|
if (!(0, _orkestrel_contract.isUndefined)(itemType) && itemType !== "string") return false;
|
|
3413
|
-
if (!(0, _orkestrel_contract.isUndefined)(choices) && (!
|
|
3414
|
-
if (!(0, _orkestrel_contract.isUndefined)(titled) && (!
|
|
3408
|
+
if (!(0, _orkestrel_contract.isUndefined)(choices) && (!(0, _orkestrel_contract.isArray)(choices) || !choices.every(_orkestrel_contract.isString))) return false;
|
|
3409
|
+
if (!(0, _orkestrel_contract.isUndefined)(titled) && (!(0, _orkestrel_contract.isArray)(titled) || !titled.every((choice) => isJSONObject(choice) && (0, _orkestrel_contract.isString)(choice["const"]) && (0, _orkestrel_contract.isString)(choice["title"])))) return false;
|
|
3415
3410
|
return itemType === "string" && !(0, _orkestrel_contract.isUndefined)(choices) || !(0, _orkestrel_contract.isUndefined)(titled);
|
|
3416
3411
|
} catch {
|
|
3417
3412
|
return false;
|
|
@@ -3446,7 +3441,7 @@ function isMCPElicitSchema(value) {
|
|
|
3446
3441
|
const dialect = schema["$schema"];
|
|
3447
3442
|
if (!(0, _orkestrel_contract.isUndefined)(dialect) && !(0, _orkestrel_contract.isString)(dialect)) return false;
|
|
3448
3443
|
const required = schema["required"];
|
|
3449
|
-
return ((0, _orkestrel_contract.isUndefined)(required) ||
|
|
3444
|
+
return ((0, _orkestrel_contract.isUndefined)(required) || (0, _orkestrel_contract.isArray)(required) && required.every((name) => (0, _orkestrel_contract.isString)(name))) && Object.values(properties).every((property) => isMCPElicitFieldSchema(property));
|
|
3450
3445
|
} catch {
|
|
3451
3446
|
return false;
|
|
3452
3447
|
}
|
|
@@ -3589,7 +3584,7 @@ function isMCPElicitResult(value) {
|
|
|
3589
3584
|
if (action !== "accept") return (0, _orkestrel_contract.isUndefined)(content);
|
|
3590
3585
|
if ((0, _orkestrel_contract.isUndefined)(content)) return true;
|
|
3591
3586
|
if (!isJSONObject(content)) return false;
|
|
3592
|
-
return Object.values(content).every((item) => (0, _orkestrel_contract.isString)(item) || (0, _orkestrel_contract.isFiniteNumber)(item) || (0, _orkestrel_contract.isBoolean)(item) ||
|
|
3587
|
+
return Object.values(content).every((item) => (0, _orkestrel_contract.isString)(item) || (0, _orkestrel_contract.isFiniteNumber)(item) || (0, _orkestrel_contract.isBoolean)(item) || (0, _orkestrel_contract.isArray)(item) && item.every((entry) => (0, _orkestrel_contract.isString)(entry)));
|
|
3593
3588
|
} catch {
|
|
3594
3589
|
return false;
|
|
3595
3590
|
}
|
|
@@ -3644,11 +3639,11 @@ function isElicitContent(value, schema) {
|
|
|
3644
3639
|
const properties = declared.value["properties"];
|
|
3645
3640
|
const required = declared.value["required"];
|
|
3646
3641
|
if (!isJSONObject(properties)) return false;
|
|
3647
|
-
if (
|
|
3642
|
+
if ((0, _orkestrel_contract.isArray)(required)) {
|
|
3648
3643
|
for (const name of required) if (!(0, _orkestrel_contract.isString)(name) || !Object.hasOwn(content, name)) return false;
|
|
3649
3644
|
}
|
|
3650
3645
|
for (const [name, item] of Object.entries(content)) {
|
|
3651
|
-
if (!(0, _orkestrel_contract.isString)(item) && !(0, _orkestrel_contract.isFiniteNumber)(item) && !(0, _orkestrel_contract.isBoolean)(item) && !(
|
|
3646
|
+
if (!(0, _orkestrel_contract.isString)(item) && !(0, _orkestrel_contract.isFiniteNumber)(item) && !(0, _orkestrel_contract.isBoolean)(item) && !((0, _orkestrel_contract.isArray)(item) && item.every((entry) => (0, _orkestrel_contract.isString)(entry)))) return false;
|
|
3652
3647
|
if (!Object.hasOwn(properties, name)) continue;
|
|
3653
3648
|
const field = properties[name];
|
|
3654
3649
|
if (!isJSONObject(field)) return false;
|
|
@@ -3661,7 +3656,7 @@ function isElicitContent(value, schema) {
|
|
|
3661
3656
|
const minimum = field["minimum"];
|
|
3662
3657
|
const maximum = field["maximum"];
|
|
3663
3658
|
if (!(0, _orkestrel_contract.isFiniteNumber)(item)) return false;
|
|
3664
|
-
if (declaredType === "integer" && !
|
|
3659
|
+
if (declaredType === "integer" && !(0, _orkestrel_contract.isInteger)(item)) return false;
|
|
3665
3660
|
if ((0, _orkestrel_contract.isFiniteNumber)(minimum) && item < minimum) return false;
|
|
3666
3661
|
if ((0, _orkestrel_contract.isFiniteNumber)(maximum) && item > maximum) return false;
|
|
3667
3662
|
continue;
|
|
@@ -3673,8 +3668,8 @@ function isElicitContent(value, schema) {
|
|
|
3673
3668
|
const maximum = field["maxLength"];
|
|
3674
3669
|
const format = field["format"];
|
|
3675
3670
|
if (!(0, _orkestrel_contract.isString)(item)) return false;
|
|
3676
|
-
if (
|
|
3677
|
-
if (
|
|
3671
|
+
if ((0, _orkestrel_contract.isArray)(choices) && !choices.includes(item)) return false;
|
|
3672
|
+
if ((0, _orkestrel_contract.isArray)(titled) && !titled.some((choice) => isJSONObject(choice) && choice["const"] === item)) return false;
|
|
3678
3673
|
const length = Array.from(item).length;
|
|
3679
3674
|
if ((0, _orkestrel_contract.isInteger)(minimum) && length < minimum) return false;
|
|
3680
3675
|
if ((0, _orkestrel_contract.isInteger)(maximum) && length > maximum) return false;
|
|
@@ -3687,14 +3682,14 @@ function isElicitContent(value, schema) {
|
|
|
3687
3682
|
const items = field["items"];
|
|
3688
3683
|
const minimum = field["minItems"];
|
|
3689
3684
|
const maximum = field["maxItems"];
|
|
3690
|
-
if (!
|
|
3685
|
+
if (!(0, _orkestrel_contract.isArray)(item) || !item.every((entry) => (0, _orkestrel_contract.isString)(entry))) return false;
|
|
3691
3686
|
if ((0, _orkestrel_contract.isInteger)(minimum) && item.length < minimum) return false;
|
|
3692
3687
|
if ((0, _orkestrel_contract.isInteger)(maximum) && item.length > maximum) return false;
|
|
3693
3688
|
if (!isJSONObject(items)) return false;
|
|
3694
3689
|
const choices = items["enum"];
|
|
3695
3690
|
const titled = items["anyOf"];
|
|
3696
|
-
if (
|
|
3697
|
-
if (
|
|
3691
|
+
if ((0, _orkestrel_contract.isArray)(choices) && !item.every((entry) => choices.includes(entry))) return false;
|
|
3692
|
+
if ((0, _orkestrel_contract.isArray)(titled) && !item.every((entry) => titled.some((choice) => isJSONObject(choice) && choice["const"] === entry))) return false;
|
|
3698
3693
|
}
|
|
3699
3694
|
return true;
|
|
3700
3695
|
} catch {
|
|
@@ -3755,7 +3750,7 @@ function isMCPRootResult(value) {
|
|
|
3755
3750
|
const result = owned.value;
|
|
3756
3751
|
const roots = result["roots"];
|
|
3757
3752
|
const metadata = result["_meta"];
|
|
3758
|
-
if (!
|
|
3753
|
+
if (!(0, _orkestrel_contract.isArray)(roots) || !roots.every((root) => isMCPRoot(root))) return false;
|
|
3759
3754
|
return (0, _orkestrel_contract.isUndefined)(metadata) || isMCPMetaObject(metadata);
|
|
3760
3755
|
} catch {
|
|
3761
3756
|
return false;
|
|
@@ -3793,7 +3788,7 @@ function isMCPSampleContent(value) {
|
|
|
3793
3788
|
if (block["type"] === "tool_result") {
|
|
3794
3789
|
const carried = block["content"];
|
|
3795
3790
|
const failed = block["isError"];
|
|
3796
|
-
if (!
|
|
3791
|
+
if (!(0, _orkestrel_contract.isArray)(carried) || !carried.every((entry) => isMCPContent(entry))) return false;
|
|
3797
3792
|
if (!(0, _orkestrel_contract.isUndefined)(failed) && !(0, _orkestrel_contract.isBoolean)(failed)) return false;
|
|
3798
3793
|
return (0, _orkestrel_contract.isString)(block["toolUseId"]);
|
|
3799
3794
|
}
|
|
@@ -3842,7 +3837,7 @@ function isMCPSampleResult(value) {
|
|
|
3842
3837
|
const metadata = result["_meta"];
|
|
3843
3838
|
if (role !== "user" && role !== "assistant") return false;
|
|
3844
3839
|
if (!(0, _orkestrel_contract.isString)(result["model"])) return false;
|
|
3845
|
-
if (!(
|
|
3840
|
+
if (!((0, _orkestrel_contract.isArray)(content) ? content : [content]).every((block) => isMCPSampleContent(block))) return false;
|
|
3846
3841
|
if (!(0, _orkestrel_contract.isUndefined)(reason) && !(0, _orkestrel_contract.isString)(reason)) return false;
|
|
3847
3842
|
return (0, _orkestrel_contract.isUndefined)(metadata) || isMCPMetaObject(metadata);
|
|
3848
3843
|
} catch {
|
|
@@ -5255,7 +5250,7 @@ var MCPServer = class {
|
|
|
5255
5250
|
const input = captured[0];
|
|
5256
5251
|
return this.#forward(input, request);
|
|
5257
5252
|
}
|
|
5258
|
-
if (!
|
|
5253
|
+
if (!(0, _orkestrel_contract.isArray)(captured[0]) || !captured[0].every((entry) => isMCPResourceContents(entry))) return buildJSONRPCError(request.id, JSONRPC_INTERNAL_ERROR, "Server resource manager returned invalid or oversized contents");
|
|
5259
5254
|
const result = buildModernResult({ contents: captured[0] }, this.#options.identity, this.#options.cache?.ttl ?? 6e4, this.#options.cache?.scope);
|
|
5260
5255
|
return buildJSONRPCResult(request.id, result);
|
|
5261
5256
|
}
|
|
@@ -5338,7 +5333,7 @@ var MCPServer = class {
|
|
|
5338
5333
|
const generated = await manager.complete(params, options);
|
|
5339
5334
|
if (generated === void 0) return buildJSONRPCError(request.id, JSONRPC_INVALID_PARAMS, "Completion reference not found");
|
|
5340
5335
|
const candidate = generated;
|
|
5341
|
-
if (!(0, _orkestrel_contract.isRecord)(candidate) || !
|
|
5336
|
+
if (!(0, _orkestrel_contract.isRecord)(candidate) || !(0, _orkestrel_contract.isArray)(candidate["values"])) return buildJSONRPCError(request.id, JSONRPC_INTERNAL_ERROR, "Server completion manager returned invalid or oversized candidates");
|
|
5342
5337
|
const values = candidate["values"];
|
|
5343
5338
|
const truncated = values.length > 100;
|
|
5344
5339
|
const captured = snapshotJSON({
|
|
@@ -5371,7 +5366,7 @@ var MCPServer = class {
|
|
|
5371
5366
|
if (deferred !== void 0) return deferred;
|
|
5372
5367
|
const token = params?.["_meta"];
|
|
5373
5368
|
const progressToken = (0, _orkestrel_contract.isRecord)(token) ? token["progressToken"] : void 0;
|
|
5374
|
-
if (this.#options.execution !== void 0 && ((0, _orkestrel_contract.isString)(progressToken) ||
|
|
5369
|
+
if (this.#options.execution !== void 0 && ((0, _orkestrel_contract.isString)(progressToken) || (0, _orkestrel_contract.isInteger)(progressToken))) return this.#progress(request, call, progressToken, options);
|
|
5375
5370
|
const result = await this.#execute(request, call, options);
|
|
5376
5371
|
return "jsonrpc" in result ? result : buildJSONRPCResult(id, result);
|
|
5377
5372
|
}
|
|
@@ -5584,7 +5579,7 @@ var MCPServer = class {
|
|
|
5584
5579
|
bytes: this.#limits.message,
|
|
5585
5580
|
depth: this.#limits.depth
|
|
5586
5581
|
});
|
|
5587
|
-
if (configured === void 0 || context === void 0 || !(0, _orkestrel_contract.isString)(principal) || principal.length === 0 || !
|
|
5582
|
+
if (configured === void 0 || context === void 0 || !(0, _orkestrel_contract.isString)(principal) || principal.length === 0 || !(0, _orkestrel_contract.isFiniteNumber)(configured.ttl) || configured.ttl <= 0) return buildJSONRPCError(id, JSONRPC_INVALID_PARAMS, "Invalid params: input policy returned an invalid round or continuation context");
|
|
5588
5583
|
if (previous !== void 0 && previous <= Date.now()) return buildJSONRPCError(id, JSONRPC_INVALID_PARAMS, "Invalid params: request state could not be verified for this retry");
|
|
5589
5584
|
const expiry = Date.now() + configured.ttl;
|
|
5590
5585
|
const protectedState = {
|
|
@@ -6222,7 +6217,7 @@ var MCPClient = class {
|
|
|
6222
6217
|
...report === void 0 ? {} : { progress: report }
|
|
6223
6218
|
});
|
|
6224
6219
|
this.#transport.send(request).catch((error) => {
|
|
6225
|
-
this.#settle(id, error
|
|
6220
|
+
this.#settle(id, (0, _orkestrel_contract.isError)(error) ? error : new Error(String(error)), true);
|
|
6226
6221
|
});
|
|
6227
6222
|
});
|
|
6228
6223
|
}
|