@jangmanj/mcp 0.0.0-stage → 0.12.3
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/LICENSE +21 -0
- package/README.md +337 -2
- package/adapters/pi/HOST-NOTES.md +65 -0
- package/adapters/pi/bridge.ts +721 -0
- package/adapters/pi/config.ts +364 -0
- package/adapters/pi/content-offloaded.ts +53 -0
- package/adapters/pi/content.ts +78 -0
- package/adapters/pi/diagnostics.ts +26 -0
- package/adapters/pi/elicitation.ts +133 -0
- package/adapters/pi/index.ts +210 -0
- package/adapters/pi/oauth.ts +219 -0
- package/adapters/pi/pi-api.ts +133 -0
- package/adapters/pi/resources.ts +177 -0
- package/adapters/pi/result-files.ts +32 -0
- package/adapters/pi/tasks.ts +49 -0
- package/dist/auth/client-credentials.d.ts +65 -0
- package/dist/auth/client-credentials.js +388 -0
- package/dist/auth/discovery.d.ts +28 -0
- package/dist/auth/discovery.js +125 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/node-ports.d.ts +8 -0
- package/dist/auth/node-ports.js +67 -0
- package/dist/auth/protocol.d.ts +12 -0
- package/dist/auth/protocol.js +39 -0
- package/dist/auth/provider.d.ts +114 -0
- package/dist/auth/provider.js +407 -0
- package/dist/auth/safe-fetch.d.ts +14 -0
- package/dist/auth/safe-fetch.js +130 -0
- package/dist/client/events.d.ts +33 -0
- package/dist/client/events.js +84 -0
- package/dist/client/index.d.ts +65 -0
- package/dist/client/index.js +128 -0
- package/dist/core/auth-types.d.ts +36 -0
- package/dist/core/auth-types.js +11 -0
- package/dist/core/bearer-challenge.d.ts +3 -0
- package/dist/core/bearer-challenge.js +63 -0
- package/dist/core/cancel.d.ts +70 -0
- package/dist/core/cancel.js +177 -0
- package/dist/core/extension.d.ts +33 -0
- package/dist/core/extension.js +145 -0
- package/dist/core/index.d.ts +73 -0
- package/dist/core/index.js +129 -0
- package/dist/core/jsonrpc.d.ts +49 -0
- package/dist/core/jsonrpc.js +80 -0
- package/dist/core/lifecycle.d.ts +128 -0
- package/dist/core/lifecycle.js +251 -0
- package/dist/core/outcome.d.ts +98 -0
- package/dist/core/outcome.js +32 -0
- package/dist/core/ports.d.ts +144 -0
- package/dist/core/ports.js +67 -0
- package/dist/core/progress.d.ts +81 -0
- package/dist/core/progress.js +205 -0
- package/dist/core/request.d.ts +108 -0
- package/dist/core/request.js +578 -0
- package/dist/core/schema/index.d.ts +1 -0
- package/dist/core/schema/index.js +1 -0
- package/dist/core/schema/types.d.ts +4154 -0
- package/dist/core/schema/types.js +6 -0
- package/dist/core/telemetry.d.ts +25 -0
- package/dist/core/telemetry.js +37 -0
- package/dist/ext-events/index.d.ts +79 -0
- package/dist/ext-events/index.js +218 -0
- package/dist/ext-events/model.d.ts +10 -0
- package/dist/ext-events/model.js +6 -0
- package/dist/ext-events/push.d.ts +18 -0
- package/dist/ext-events/push.js +101 -0
- package/dist/ext-events/stream.d.ts +6 -0
- package/dist/ext-events/stream.js +60 -0
- package/dist/ext-server-cards/index.d.ts +107 -0
- package/dist/ext-server-cards/index.js +249 -0
- package/dist/ext-skills/cache.d.ts +20 -0
- package/dist/ext-skills/cache.js +101 -0
- package/dist/ext-skills/client.d.ts +82 -0
- package/dist/ext-skills/client.js +292 -0
- package/dist/ext-skills/extension.d.ts +16 -0
- package/dist/ext-skills/extension.js +29 -0
- package/dist/ext-skills/index.d.ts +4 -0
- package/dist/ext-skills/index.js +4 -0
- package/dist/ext-skills/verify.d.ts +57 -0
- package/dist/ext-skills/verify.js +168 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mrtr-cache/cache.d.ts +51 -0
- package/dist/mrtr-cache/cache.js +295 -0
- package/dist/mrtr-cache/client.d.ts +24 -0
- package/dist/mrtr-cache/client.js +44 -0
- package/dist/mrtr-cache/common.d.ts +10 -0
- package/dist/mrtr-cache/common.js +9 -0
- package/dist/mrtr-cache/elicitation.d.ts +42 -0
- package/dist/mrtr-cache/elicitation.js +221 -0
- package/dist/mrtr-cache/index.d.ts +9 -0
- package/dist/mrtr-cache/index.js +8 -0
- package/dist/mrtr-cache/mrtr.d.ts +37 -0
- package/dist/mrtr-cache/mrtr.js +250 -0
- package/dist/mrtr-cache/refresh.d.ts +8 -0
- package/dist/mrtr-cache/refresh.js +30 -0
- package/dist/mrtr-cache/stream.d.ts +5 -0
- package/dist/mrtr-cache/stream.js +18 -0
- package/dist/mrtr-cache/subscriptions.d.ts +96 -0
- package/dist/mrtr-cache/subscriptions.js +288 -0
- package/dist/mrtr-cache/tasks.d.ts +103 -0
- package/dist/mrtr-cache/tasks.js +444 -0
- package/dist/ops/common.d.ts +18 -0
- package/dist/ops/common.js +39 -0
- package/dist/ops/completion.d.ts +44 -0
- package/dist/ops/completion.js +65 -0
- package/dist/ops/content.d.ts +40 -0
- package/dist/ops/content.js +117 -0
- package/dist/ops/icons.d.ts +29 -0
- package/dist/ops/icons.js +82 -0
- package/dist/ops/index.d.ts +30 -0
- package/dist/ops/index.js +28 -0
- package/dist/ops/pagination.d.ts +32 -0
- package/dist/ops/pagination.js +65 -0
- package/dist/ops/prompts.d.ts +32 -0
- package/dist/ops/prompts.js +68 -0
- package/dist/ops/resources.d.ts +42 -0
- package/dist/ops/resources.js +104 -0
- package/dist/ops/schema.d.ts +39 -0
- package/dist/ops/schema.js +163 -0
- package/dist/ops/tools.d.ts +88 -0
- package/dist/ops/tools.js +169 -0
- package/dist/ops/uri-template.d.ts +3 -0
- package/dist/ops/uri-template.js +101 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/mrtr.d.ts +38 -0
- package/dist/server/mrtr.js +99 -0
- package/dist/server/protocol.d.ts +21 -0
- package/dist/server/protocol.js +49 -0
- package/dist/server/server.d.ts +105 -0
- package/dist/server/server.js +383 -0
- package/dist/server/skills.d.ts +45 -0
- package/dist/server/skills.js +73 -0
- package/dist/server/uri.d.ts +2 -0
- package/dist/server/uri.js +27 -0
- package/dist/server-events/bus.d.ts +40 -0
- package/dist/server-events/bus.js +84 -0
- package/dist/server-events/events.d.ts +36 -0
- package/dist/server-events/events.js +108 -0
- package/dist/server-events/index.d.ts +6 -0
- package/dist/server-events/index.js +6 -0
- package/dist/server-events/notices.d.ts +24 -0
- package/dist/server-events/notices.js +31 -0
- package/dist/server-events/subscriptions.d.ts +33 -0
- package/dist/server-events/subscriptions.js +77 -0
- package/dist/server-events/tasks.d.ts +43 -0
- package/dist/server-events/tasks.js +101 -0
- package/dist/server-events/types.d.ts +25 -0
- package/dist/server-events/types.js +34 -0
- package/dist/server-transport/auth.d.ts +20 -0
- package/dist/server-transport/auth.js +29 -0
- package/dist/server-transport/channel.d.ts +17 -0
- package/dist/server-transport/channel.js +47 -0
- package/dist/server-transport/http.d.ts +19 -0
- package/dist/server-transport/http.js +209 -0
- package/dist/server-transport/index.d.ts +4 -0
- package/dist/server-transport/index.js +4 -0
- package/dist/server-transport/stdio.d.ts +16 -0
- package/dist/server-transport/stdio.js +83 -0
- package/dist/telemetry-otel/index.d.ts +64 -0
- package/dist/telemetry-otel/index.js +196 -0
- package/dist/testing/index.d.ts +36 -0
- package/dist/testing/index.js +140 -0
- package/dist/transport-http/headers.d.ts +24 -0
- package/dist/transport-http/headers.js +140 -0
- package/dist/transport-http/index.d.ts +3 -0
- package/dist/transport-http/index.js +3 -0
- package/dist/transport-http/sse.d.ts +33 -0
- package/dist/transport-http/sse.js +152 -0
- package/dist/transport-http/transport.d.ts +66 -0
- package/dist/transport-http/transport.js +854 -0
- package/dist/transport-stdio/framing.d.ts +50 -0
- package/dist/transport-stdio/framing.js +154 -0
- package/dist/transport-stdio/index.d.ts +4 -0
- package/dist/transport-stdio/index.js +4 -0
- package/dist/transport-stdio/stderr-ring.d.ts +27 -0
- package/dist/transport-stdio/stderr-ring.js +105 -0
- package/dist/transport-stdio/transport.d.ts +142 -0
- package/dist/transport-stdio/transport.js +743 -0
- package/dist/transport-stdio/write-queue.d.ts +48 -0
- package/dist/transport-stdio/write-queue.js +147 -0
- package/package.json +134 -4
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { isObj, utf8Length } from "./common.js";
|
|
2
|
+
const B64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
3
|
+
const MIME_TOKEN = "[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*";
|
|
4
|
+
const MIME = new RegExp(`^${MIME_TOKEN}/${MIME_TOKEN}(?:\\s*;\\s*[A-Za-z0-9!#$&^_.+-]+=(?:[^\\s;"]+|"[^"]*"))*$`);
|
|
5
|
+
const URI_3986 = /^[A-Za-z][A-Za-z0-9+.-]*:(?:[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=]|%[0-9A-Fa-f]{2})*$/;
|
|
6
|
+
export function isBase64(s) {
|
|
7
|
+
return typeof s === "string" && s.length % 4 === 0 && B64.test(s);
|
|
8
|
+
}
|
|
9
|
+
export function isMimeType(s) {
|
|
10
|
+
return typeof s === "string" && MIME.test(s);
|
|
11
|
+
}
|
|
12
|
+
/** RFC 3986 URI syntax check (OPS-RES-6). */
|
|
13
|
+
export function isRfc3986Uri(s) {
|
|
14
|
+
return typeof s === "string" && URI_3986.test(s);
|
|
15
|
+
}
|
|
16
|
+
export function checkAnnotations(a, issues) {
|
|
17
|
+
if (a === undefined)
|
|
18
|
+
return;
|
|
19
|
+
if (!isObj(a)) {
|
|
20
|
+
issues.push("annotations-not-object");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const p = a["priority"];
|
|
24
|
+
if (p !== undefined && (typeof p !== "number" || !(p >= 0 && p <= 1)))
|
|
25
|
+
issues.push("annotation-priority-out-of-range");
|
|
26
|
+
const aud = a["audience"];
|
|
27
|
+
if (aud !== undefined && !(Array.isArray(aud) && aud.every((x) => x === "user" || x === "assistant"))) {
|
|
28
|
+
issues.push("annotation-audience-invalid");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Check one TextResourceContents / BlobResourceContents. Returns undefined when both or neither of text/blob exist. */
|
|
32
|
+
export function normalizeResourceContents(raw) {
|
|
33
|
+
if (!isObj(raw) || typeof raw["uri"] !== "string")
|
|
34
|
+
return undefined;
|
|
35
|
+
const hasText = "text" in raw;
|
|
36
|
+
const hasBlob = "blob" in raw;
|
|
37
|
+
if (hasText === hasBlob)
|
|
38
|
+
return undefined;
|
|
39
|
+
const issues = [];
|
|
40
|
+
if (!isRfc3986Uri(raw["uri"]))
|
|
41
|
+
issues.push("invalid-uri");
|
|
42
|
+
if (raw["mimeType"] !== undefined && !isMimeType(raw["mimeType"]))
|
|
43
|
+
issues.push("invalid-mimeType");
|
|
44
|
+
if (hasText && typeof raw["text"] !== "string")
|
|
45
|
+
issues.push("invalid-text");
|
|
46
|
+
if (hasBlob && !isBase64(raw["blob"]))
|
|
47
|
+
issues.push("invalid-base64");
|
|
48
|
+
checkAnnotations(raw["annotations"], issues);
|
|
49
|
+
return {
|
|
50
|
+
raw,
|
|
51
|
+
uri: raw["uri"],
|
|
52
|
+
...(typeof raw["mimeType"] === "string" ? { mimeType: raw["mimeType"] } : {}),
|
|
53
|
+
...(typeof raw["text"] === "string" ? { text: raw["text"] } : {}),
|
|
54
|
+
...(typeof raw["blob"] === "string" ? { blob: raw["blob"] } : {}),
|
|
55
|
+
issues,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Normalize one content block (OPS-TOOLS-13/14). Unknown types are preserved and flagged. */
|
|
59
|
+
export function normalizeContentBlock(raw) {
|
|
60
|
+
if (!isObj(raw) || typeof raw["type"] !== "string") {
|
|
61
|
+
return { type: "unknown", raw, issues: ["unknown-type", "not-a-typed-object"] };
|
|
62
|
+
}
|
|
63
|
+
const t = raw["type"];
|
|
64
|
+
const issues = [];
|
|
65
|
+
switch (t) {
|
|
66
|
+
case "text":
|
|
67
|
+
if (typeof raw["text"] !== "string")
|
|
68
|
+
issues.push("invalid-text");
|
|
69
|
+
break;
|
|
70
|
+
case "image":
|
|
71
|
+
case "audio":
|
|
72
|
+
if (!isBase64(raw["data"]))
|
|
73
|
+
issues.push("invalid-base64");
|
|
74
|
+
if (!isMimeType(raw["mimeType"]))
|
|
75
|
+
issues.push("invalid-mimeType");
|
|
76
|
+
break;
|
|
77
|
+
case "resource_link":
|
|
78
|
+
if (typeof raw["uri"] !== "string")
|
|
79
|
+
issues.push("invalid-uri");
|
|
80
|
+
else if (!isRfc3986Uri(raw["uri"]))
|
|
81
|
+
issues.push("invalid-uri");
|
|
82
|
+
break;
|
|
83
|
+
case "resource": {
|
|
84
|
+
const e = normalizeResourceContents(raw["resource"]);
|
|
85
|
+
if (!e)
|
|
86
|
+
issues.push("invalid-embedded-resource");
|
|
87
|
+
else
|
|
88
|
+
issues.push(...e.issues);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
return { type: "unknown", raw, rawType: t, issues: ["unknown-type"] };
|
|
93
|
+
}
|
|
94
|
+
checkAnnotations(raw["annotations"], issues);
|
|
95
|
+
return { type: t, raw, issues };
|
|
96
|
+
}
|
|
97
|
+
export function normalizeContent(blocks) {
|
|
98
|
+
return Array.isArray(blocks) ? blocks.map(normalizeContentBlock) : [];
|
|
99
|
+
}
|
|
100
|
+
/** Blocks whose data is unusable (invalid base64 or mime on image/audio, or blob). */
|
|
101
|
+
export function hasInvalidMedia(b) {
|
|
102
|
+
return b.issues.some((i) => i === "invalid-base64" || i === "invalid-mimeType");
|
|
103
|
+
}
|
|
104
|
+
/** OPS-TOOLS-15: bytes per block only. The library never truncates. */
|
|
105
|
+
export function measure(result) {
|
|
106
|
+
const r = isObj(result) ? result : {};
|
|
107
|
+
const blocks = (Array.isArray(r["content"]) ? r["content"] : []).map((b) => ({
|
|
108
|
+
type: isObj(b) && typeof b["type"] === "string" ? b["type"] : "unknown",
|
|
109
|
+
bytes: utf8Length(b),
|
|
110
|
+
}));
|
|
111
|
+
const structuredContentBytes = "structuredContent" in r ? utf8Length(r["structuredContent"]) : 0;
|
|
112
|
+
return {
|
|
113
|
+
totalBytes: blocks.reduce((n, b) => n + b.bytes, 0) + structuredContentBytes,
|
|
114
|
+
blocks,
|
|
115
|
+
structuredContentBytes,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Icon metadata helpers (SEC-ICON-1..5). The library fetches and renders nothing. */
|
|
2
|
+
export interface Icon {
|
|
3
|
+
readonly src: string;
|
|
4
|
+
readonly mimeType?: string;
|
|
5
|
+
readonly sizes?: readonly string[];
|
|
6
|
+
readonly theme?: string;
|
|
7
|
+
}
|
|
8
|
+
export type ImageKind = "png" | "jpeg" | "webp" | "svg";
|
|
9
|
+
export interface IconPolicy {
|
|
10
|
+
readonly allowWebp?: boolean;
|
|
11
|
+
/** SVG is off by default; sanitization is the renderer's job. */
|
|
12
|
+
readonly allowSvg?: boolean;
|
|
13
|
+
/** Default 256 KiB. */
|
|
14
|
+
readonly maxBytes?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_ICON_MAX_BYTES: number;
|
|
17
|
+
export type IconCheck = {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly kind?: ImageKind;
|
|
20
|
+
} | {
|
|
21
|
+
readonly ok: false;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
};
|
|
24
|
+
/** Detect by magic bytes (SEC-ICON-5). */
|
|
25
|
+
export declare function detectImageKind(b: Uint8Array): ImageKind | undefined;
|
|
26
|
+
/** Check fetched or embedded bytes against the declared MIME type and policy. */
|
|
27
|
+
export declare function checkIconBytes(bytes: Uint8Array, declaredMime: string | undefined, policy?: IconPolicy): IconCheck;
|
|
28
|
+
/** SEC-ICON-1/2/5 for an icon URI. https must be same-origin with the server; data: is checked by magic bytes. */
|
|
29
|
+
export declare function validateIcon(icon: Icon, serverOrigin: string, policy?: IconPolicy): IconCheck;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Icon metadata helpers (SEC-ICON-1..5). The library fetches and renders nothing. */
|
|
2
|
+
export const DEFAULT_ICON_MAX_BYTES = 256 * 1024;
|
|
3
|
+
const MIME_KIND = {
|
|
4
|
+
"image/png": "png",
|
|
5
|
+
"image/jpeg": "jpeg",
|
|
6
|
+
"image/jpg": "jpeg",
|
|
7
|
+
"image/webp": "webp",
|
|
8
|
+
"image/svg+xml": "svg",
|
|
9
|
+
};
|
|
10
|
+
/** Detect by magic bytes (SEC-ICON-5). */
|
|
11
|
+
export function detectImageKind(b) {
|
|
12
|
+
const at = (i, ...v) => v.every((x, j) => b[i + j] === x);
|
|
13
|
+
if (b.length >= 8 && at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a))
|
|
14
|
+
return "png";
|
|
15
|
+
if (b.length >= 3 && at(0, 0xff, 0xd8, 0xff))
|
|
16
|
+
return "jpeg";
|
|
17
|
+
if (b.length >= 12 && at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50))
|
|
18
|
+
return "webp";
|
|
19
|
+
const head = new TextDecoder().decode(b.subarray(0, 256)).trimStart();
|
|
20
|
+
if (/^(<\?xml[^>]*\?>\s*)?(<!--[\s\S]*?-->\s*)?<svg[\s>]/i.test(head))
|
|
21
|
+
return "svg";
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Check fetched or embedded bytes against the declared MIME type and policy. */
|
|
25
|
+
export function checkIconBytes(bytes, declaredMime, policy = {}) {
|
|
26
|
+
if (bytes.length > (policy.maxBytes ?? DEFAULT_ICON_MAX_BYTES))
|
|
27
|
+
return { ok: false, reason: "too-large" };
|
|
28
|
+
const kind = detectImageKind(bytes);
|
|
29
|
+
if (!kind)
|
|
30
|
+
return { ok: false, reason: "unrecognized-image" };
|
|
31
|
+
const allowed = kind === "png" || kind === "jpeg" || (kind === "webp" && policy.allowWebp === true) || (kind === "svg" && policy.allowSvg === true);
|
|
32
|
+
if (!allowed)
|
|
33
|
+
return { ok: false, reason: `type-not-allowed:${kind}` };
|
|
34
|
+
if (declaredMime !== undefined) {
|
|
35
|
+
const declared = MIME_KIND[declaredMime.split(";")[0]?.trim().toLowerCase() ?? ""];
|
|
36
|
+
if (declared !== kind)
|
|
37
|
+
return { ok: false, reason: "mime-mismatch" };
|
|
38
|
+
}
|
|
39
|
+
return { ok: true, kind };
|
|
40
|
+
}
|
|
41
|
+
/** SEC-ICON-1/2/5 for an icon URI. https must be same-origin with the server; data: is checked by magic bytes. */
|
|
42
|
+
export function validateIcon(icon, serverOrigin, policy = {}) {
|
|
43
|
+
let u;
|
|
44
|
+
try {
|
|
45
|
+
u = new URL(icon.src);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return { ok: false, reason: "invalid-uri" };
|
|
49
|
+
}
|
|
50
|
+
if (u.protocol === "https:") {
|
|
51
|
+
let origin;
|
|
52
|
+
try {
|
|
53
|
+
origin = new URL(serverOrigin).origin;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return { ok: false, reason: "invalid-server-origin" };
|
|
57
|
+
}
|
|
58
|
+
if (u.origin !== origin)
|
|
59
|
+
return { ok: false, reason: "cross-origin" };
|
|
60
|
+
if (u.username !== "" || u.password !== "")
|
|
61
|
+
return { ok: false, reason: "credentials-in-uri" };
|
|
62
|
+
return { ok: true };
|
|
63
|
+
}
|
|
64
|
+
if (u.protocol === "data:") {
|
|
65
|
+
const m = /^data:([^,;]*)((?:;[^,;]*)*),(.*)$/s.exec(icon.src);
|
|
66
|
+
if (!m)
|
|
67
|
+
return { ok: false, reason: "invalid-uri" };
|
|
68
|
+
const mime = (m[1] || "").toLowerCase();
|
|
69
|
+
if (!(m[2] ?? "").split(";").includes("base64"))
|
|
70
|
+
return { ok: false, reason: "data-uri-not-base64" };
|
|
71
|
+
let bytes;
|
|
72
|
+
try {
|
|
73
|
+
const bin = atob(decodeURIComponent(m[3] ?? ""));
|
|
74
|
+
bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { ok: false, reason: "invalid-base64" };
|
|
78
|
+
}
|
|
79
|
+
return checkIconBytes(bytes, mime === "" ? icon.mimeType : mime, policy);
|
|
80
|
+
}
|
|
81
|
+
return { ok: false, reason: `unsafe-scheme:${u.protocol}` };
|
|
82
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CompletionApi } from "./completion.js";
|
|
2
|
+
import type { CapabilitySource, OpsClient } from "./common.js";
|
|
3
|
+
import { PromptsApi } from "./prompts.js";
|
|
4
|
+
import { ResourcesApi } from "./resources.js";
|
|
5
|
+
import { ToolsApi, type ToolHooks } from "./tools.js";
|
|
6
|
+
import type { SchemaValidator } from "./schema.js";
|
|
7
|
+
export * from "./common.js";
|
|
8
|
+
export * from "./schema.js";
|
|
9
|
+
export * from "./pagination.js";
|
|
10
|
+
export * from "./content.js";
|
|
11
|
+
export * from "./uri-template.js";
|
|
12
|
+
export * from "./icons.js";
|
|
13
|
+
export * from "./tools.js";
|
|
14
|
+
export * from "./prompts.js";
|
|
15
|
+
export * from "./resources.js";
|
|
16
|
+
export * from "./completion.js";
|
|
17
|
+
export interface OpsOptions {
|
|
18
|
+
/** Server capabilities from server/discover, or a getter. Unknown (undefined) means call and map -32601. */
|
|
19
|
+
readonly capabilities?: CapabilitySource;
|
|
20
|
+
readonly validator?: SchemaValidator;
|
|
21
|
+
readonly serverTrusted?: boolean;
|
|
22
|
+
readonly hooks?: ToolHooks;
|
|
23
|
+
}
|
|
24
|
+
export interface Ops {
|
|
25
|
+
readonly tools: ToolsApi;
|
|
26
|
+
readonly prompts: PromptsApi;
|
|
27
|
+
readonly resources: ResourcesApi;
|
|
28
|
+
readonly completion: CompletionApi;
|
|
29
|
+
}
|
|
30
|
+
export declare function createOps(client: OpsClient, opts?: OpsOptions): Ops;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CompletionApi } from "./completion.js";
|
|
2
|
+
import { PromptsApi } from "./prompts.js";
|
|
3
|
+
import { ResourcesApi } from "./resources.js";
|
|
4
|
+
import { ToolsApi } from "./tools.js";
|
|
5
|
+
export * from "./common.js";
|
|
6
|
+
export * from "./schema.js";
|
|
7
|
+
export * from "./pagination.js";
|
|
8
|
+
export * from "./content.js";
|
|
9
|
+
export * from "./uri-template.js";
|
|
10
|
+
export * from "./icons.js";
|
|
11
|
+
export * from "./tools.js";
|
|
12
|
+
export * from "./prompts.js";
|
|
13
|
+
export * from "./resources.js";
|
|
14
|
+
export * from "./completion.js";
|
|
15
|
+
export function createOps(client, opts = {}) {
|
|
16
|
+
const caps = { ...(opts.capabilities !== undefined ? { capabilities: opts.capabilities } : {}) };
|
|
17
|
+
return {
|
|
18
|
+
tools: new ToolsApi(client, {
|
|
19
|
+
...caps,
|
|
20
|
+
...(opts.validator ? { validator: opts.validator } : {}),
|
|
21
|
+
...(opts.serverTrusted !== undefined ? { serverTrusted: opts.serverTrusted } : {}),
|
|
22
|
+
...(opts.hooks ? { hooks: opts.hooks } : {}),
|
|
23
|
+
}),
|
|
24
|
+
prompts: new PromptsApi(client, caps),
|
|
25
|
+
resources: new ResourcesApi(client, caps),
|
|
26
|
+
completion: new CompletionApi(client, caps),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Outcome, RequestOptions } from "../core/index.js";
|
|
2
|
+
export declare const DEFAULT_MAX_PAGES = 1000;
|
|
3
|
+
export declare const DEFAULT_MAX_ITEMS = 100000;
|
|
4
|
+
export interface ListAllOptions {
|
|
5
|
+
readonly maxPages?: number;
|
|
6
|
+
readonly maxItems?: number;
|
|
7
|
+
/** PAGE-6: restart once from the first page after -32602, only when true. */
|
|
8
|
+
readonly restartOnInvalidCursor?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ListAllResult<T> {
|
|
11
|
+
readonly items: T[];
|
|
12
|
+
readonly pages: number;
|
|
13
|
+
}
|
|
14
|
+
export interface Page<T> {
|
|
15
|
+
readonly items: readonly T[];
|
|
16
|
+
readonly nextCursor?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export type PageFetcher<T> = (cursor: string | undefined) => PromiseLike<Outcome<Page<T>>>;
|
|
19
|
+
/** Read the opaque cursor for a request. An empty string is a real cursor (PAGE-2). */
|
|
20
|
+
export declare function cursorParams(cursor: string | undefined): Record<string, unknown>;
|
|
21
|
+
export declare function nextCursorOf(result: unknown): {
|
|
22
|
+
ok: true;
|
|
23
|
+
cursor: string | undefined;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Follow nextCursor until absent (PAGE-1). Cursors are echoed unchanged and never parsed
|
|
29
|
+
* (PAGE-3). Page size is not assumed (PAGE-4). Loop guard per PAGE-5.
|
|
30
|
+
*/
|
|
31
|
+
export declare function listAll<T>(method: string, fetchPage: PageFetcher<T>, opts?: ListAllOptions): Promise<Outcome<ListAllResult<T>>>;
|
|
32
|
+
export type ListCallOptions = RequestOptions;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { local, mapOutcome, isObj } from "./common.js";
|
|
2
|
+
export const DEFAULT_MAX_PAGES = 1000;
|
|
3
|
+
export const DEFAULT_MAX_ITEMS = 100_000;
|
|
4
|
+
/** Read the opaque cursor for a request. An empty string is a real cursor (PAGE-2). */
|
|
5
|
+
export function cursorParams(cursor) {
|
|
6
|
+
return cursor === undefined ? {} : { cursor };
|
|
7
|
+
}
|
|
8
|
+
export function nextCursorOf(result) {
|
|
9
|
+
if (!isObj(result))
|
|
10
|
+
return { ok: false };
|
|
11
|
+
const c = result["nextCursor"];
|
|
12
|
+
if (c === undefined || c === null)
|
|
13
|
+
return { ok: true, cursor: undefined };
|
|
14
|
+
return typeof c === "string" ? { ok: true, cursor: c } : { ok: false };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Follow nextCursor until absent (PAGE-1). Cursors are echoed unchanged and never parsed
|
|
18
|
+
* (PAGE-3). Page size is not assumed (PAGE-4). Loop guard per PAGE-5.
|
|
19
|
+
*/
|
|
20
|
+
export async function listAll(method, fetchPage, opts = {}) {
|
|
21
|
+
const maxPages = opts.maxPages ?? DEFAULT_MAX_PAGES;
|
|
22
|
+
const maxItems = opts.maxItems ?? DEFAULT_MAX_ITEMS;
|
|
23
|
+
let restarted = false;
|
|
24
|
+
for (;;) {
|
|
25
|
+
const items = [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
let cursor;
|
|
28
|
+
let pages = 0;
|
|
29
|
+
let restart = false;
|
|
30
|
+
for (;;) {
|
|
31
|
+
const o = await fetchPage(cursor);
|
|
32
|
+
if (o.kind !== "ok") {
|
|
33
|
+
if (o.kind === "jsonrpc-error" &&
|
|
34
|
+
o.code === -32602 &&
|
|
35
|
+
cursor !== undefined &&
|
|
36
|
+
opts.restartOnInvalidCursor === true &&
|
|
37
|
+
!restarted) {
|
|
38
|
+
restarted = true;
|
|
39
|
+
restart = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
return mapOutcome(o, () => local("local-error", method, "unreachable"));
|
|
43
|
+
}
|
|
44
|
+
pages += 1;
|
|
45
|
+
items.push(...o.value.items);
|
|
46
|
+
if (items.length > maxItems) {
|
|
47
|
+
return local("limit-exceeded", method, { limit: "maxItems", max: maxItems, observed: items.length });
|
|
48
|
+
}
|
|
49
|
+
const next = o.value.nextCursor;
|
|
50
|
+
if (next === undefined)
|
|
51
|
+
return { kind: "ok", value: { items, pages }, meta: o.meta };
|
|
52
|
+
if (seen.has(next)) {
|
|
53
|
+
return local("protocol-violation", method, { reason: "cursor-loop", pages });
|
|
54
|
+
}
|
|
55
|
+
if (pages >= maxPages) {
|
|
56
|
+
return local("limit-exceeded", method, { limit: "maxPages", max: maxPages, observed: pages });
|
|
57
|
+
}
|
|
58
|
+
seen.add(next);
|
|
59
|
+
cursor = next;
|
|
60
|
+
}
|
|
61
|
+
if (!restart)
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return local("local-error", method, "unreachable");
|
|
65
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Outcome, RequestOptions } from "../core/index.js";
|
|
2
|
+
import { type CapabilitySource, type OpsClient } from "./common.js";
|
|
3
|
+
import { type ContentBlock } from "./content.js";
|
|
4
|
+
import { type ListAllOptions, type ListAllResult } from "./pagination.js";
|
|
5
|
+
export interface PromptsListResult {
|
|
6
|
+
readonly prompts: Record<string, unknown>[];
|
|
7
|
+
readonly nextCursor?: string;
|
|
8
|
+
readonly ttlMs?: unknown;
|
|
9
|
+
readonly cacheScope?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface PromptMessage {
|
|
12
|
+
readonly role: string;
|
|
13
|
+
readonly content: ContentBlock;
|
|
14
|
+
readonly raw: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface PromptGetResult {
|
|
17
|
+
readonly raw: Record<string, unknown>;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly messages: PromptMessage[];
|
|
20
|
+
}
|
|
21
|
+
export declare class PromptsApi {
|
|
22
|
+
private readonly client;
|
|
23
|
+
private readonly opts;
|
|
24
|
+
constructor(client: OpsClient, opts?: {
|
|
25
|
+
readonly capabilities?: CapabilitySource;
|
|
26
|
+
});
|
|
27
|
+
list(opts?: RequestOptions & {
|
|
28
|
+
readonly cursor?: string;
|
|
29
|
+
}): Promise<Outcome<PromptsListResult>>;
|
|
30
|
+
listAll(opts?: RequestOptions & ListAllOptions): Promise<Outcome<ListAllResult<Record<string, unknown>>>>;
|
|
31
|
+
get(name: string, args?: Record<string, string>, opts?: RequestOptions): Promise<Outcome<PromptGetResult>>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { gate, isObj, mapMethodNotFound, mapOutcome } from "./common.js";
|
|
2
|
+
import { hasInvalidMedia, normalizeContentBlock } from "./content.js";
|
|
3
|
+
import { cursorParams, listAll, nextCursorOf } from "./pagination.js";
|
|
4
|
+
export class PromptsApi {
|
|
5
|
+
client;
|
|
6
|
+
opts;
|
|
7
|
+
constructor(client, opts = {}) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.opts = opts;
|
|
10
|
+
}
|
|
11
|
+
async list(opts) {
|
|
12
|
+
const blocked = gate(this.opts.capabilities, "prompts", "prompts/list");
|
|
13
|
+
if (blocked)
|
|
14
|
+
return blocked;
|
|
15
|
+
const { cursor, ...ro } = opts ?? {};
|
|
16
|
+
const o = await this.client.request("prompts/list", cursorParams(cursor), { ...ro, idempotent: true });
|
|
17
|
+
return mapOutcome(mapMethodNotFound(o, "prompts"), (v, meta) => {
|
|
18
|
+
const next = nextCursorOf(v);
|
|
19
|
+
if (!Array.isArray(v["prompts"]) || !next.ok)
|
|
20
|
+
return { kind: "protocol-violation", detail: { reason: "bad-prompts-list" }, meta };
|
|
21
|
+
return {
|
|
22
|
+
kind: "ok",
|
|
23
|
+
value: {
|
|
24
|
+
prompts: v["prompts"],
|
|
25
|
+
...(next.cursor !== undefined ? { nextCursor: next.cursor } : {}),
|
|
26
|
+
...("ttlMs" in v ? { ttlMs: v["ttlMs"] } : {}),
|
|
27
|
+
...("cacheScope" in v ? { cacheScope: v["cacheScope"] } : {}),
|
|
28
|
+
},
|
|
29
|
+
meta,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
listAll(opts) {
|
|
34
|
+
const { maxPages, maxItems, restartOnInvalidCursor, ...ro } = opts ?? {};
|
|
35
|
+
return listAll("prompts/list", async (cursor) => mapOutcome(await this.list({ ...ro, ...(cursor !== undefined ? { cursor } : {}) }), (v, meta) => ({
|
|
36
|
+
kind: "ok",
|
|
37
|
+
value: { items: v.prompts, ...(v.nextCursor !== undefined ? { nextCursor: v.nextCursor } : {}) },
|
|
38
|
+
meta,
|
|
39
|
+
})), {
|
|
40
|
+
...(maxPages !== undefined ? { maxPages } : {}),
|
|
41
|
+
...(maxItems !== undefined ? { maxItems } : {}),
|
|
42
|
+
...(restartOnInvalidCursor !== undefined ? { restartOnInvalidCursor } : {}),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async get(name, args, opts) {
|
|
46
|
+
const blocked = gate(this.opts.capabilities, "prompts", "prompts/get");
|
|
47
|
+
if (blocked)
|
|
48
|
+
return blocked;
|
|
49
|
+
const o = await this.client.request("prompts/get", { name, ...(args !== undefined ? { arguments: args } : {}) }, opts);
|
|
50
|
+
return mapOutcome(mapMethodNotFound(o, "prompts"), (v, meta) => {
|
|
51
|
+
if (!Array.isArray(v["messages"]))
|
|
52
|
+
return { kind: "protocol-violation", detail: { reason: "messages-not-array" }, meta };
|
|
53
|
+
const messages = [];
|
|
54
|
+
for (const m of v["messages"]) {
|
|
55
|
+
const content = normalizeContentBlock(isObj(m) ? m["content"] : undefined);
|
|
56
|
+
if (hasInvalidMedia(content)) {
|
|
57
|
+
return { kind: "protocol-violation", detail: { reason: "invalid-media", issues: content.issues }, meta };
|
|
58
|
+
}
|
|
59
|
+
messages.push({ role: isObj(m) && typeof m["role"] === "string" ? m["role"] : "", content, raw: m });
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
kind: "ok",
|
|
63
|
+
value: { raw: v, ...(typeof v["description"] === "string" ? { description: v["description"] } : {}), messages },
|
|
64
|
+
meta,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Outcome, RequestOptions } from "../core/index.js";
|
|
2
|
+
import { type CapabilitySource, type OpsClient } from "./common.js";
|
|
3
|
+
import { type ResourceEntry } from "./content.js";
|
|
4
|
+
import { type ListAllOptions, type ListAllResult } from "./pagination.js";
|
|
5
|
+
import { type TemplateValue } from "./uri-template.js";
|
|
6
|
+
export interface FlaggedItem {
|
|
7
|
+
readonly raw: Record<string, unknown>;
|
|
8
|
+
readonly issues: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export interface ResourcesListResult {
|
|
11
|
+
readonly items: FlaggedItem[];
|
|
12
|
+
readonly nextCursor?: string;
|
|
13
|
+
readonly ttlMs?: unknown;
|
|
14
|
+
readonly cacheScope?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface ResourceReadResult {
|
|
17
|
+
readonly raw: Record<string, unknown>;
|
|
18
|
+
readonly contents: ResourceEntry[];
|
|
19
|
+
/** OPS-RES-4: true for any empty contents. Not-found is never inferred. */
|
|
20
|
+
readonly empty: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class ResourcesApi {
|
|
23
|
+
private readonly client;
|
|
24
|
+
private readonly opts;
|
|
25
|
+
constructor(client: OpsClient, opts?: {
|
|
26
|
+
readonly capabilities?: CapabilitySource;
|
|
27
|
+
});
|
|
28
|
+
private page;
|
|
29
|
+
list(opts?: RequestOptions & {
|
|
30
|
+
readonly cursor?: string;
|
|
31
|
+
}): Promise<Outcome<ResourcesListResult>>;
|
|
32
|
+
listTemplates(opts?: RequestOptions & {
|
|
33
|
+
readonly cursor?: string;
|
|
34
|
+
}): Promise<Outcome<ResourcesListResult>>;
|
|
35
|
+
private all;
|
|
36
|
+
listAll(opts?: RequestOptions & ListAllOptions): Promise<Outcome<ListAllResult<FlaggedItem>>>;
|
|
37
|
+
listAllTemplates(opts?: RequestOptions & ListAllOptions): Promise<Outcome<ListAllResult<FlaggedItem>>>;
|
|
38
|
+
/** RFC 6570 level 1-4 expansion, local only. */
|
|
39
|
+
expandTemplate(template: string, vars: Readonly<Record<string, TemplateValue>>): string;
|
|
40
|
+
/** resources/read. Never fetches the URI itself (OPS-RES-5). */
|
|
41
|
+
read(uri: string, opts?: RequestOptions): Promise<Outcome<ResourceReadResult>>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { gate, isObj, mapMethodNotFound, mapOutcome } from "./common.js";
|
|
2
|
+
import { checkAnnotations, isRfc3986Uri, normalizeResourceContents } from "./content.js";
|
|
3
|
+
import { cursorParams, listAll, nextCursorOf } from "./pagination.js";
|
|
4
|
+
import { expandUriTemplate } from "./uri-template.js";
|
|
5
|
+
function flag(raw, uriKey) {
|
|
6
|
+
if (!isObj(raw))
|
|
7
|
+
return undefined;
|
|
8
|
+
const issues = [];
|
|
9
|
+
const u = raw[uriKey];
|
|
10
|
+
if (typeof u !== "string")
|
|
11
|
+
issues.push(`missing-${uriKey}`);
|
|
12
|
+
else if (uriKey === "uri" && !isRfc3986Uri(u))
|
|
13
|
+
issues.push("invalid-uri");
|
|
14
|
+
checkAnnotations(raw["annotations"], issues);
|
|
15
|
+
return { raw, issues };
|
|
16
|
+
}
|
|
17
|
+
export class ResourcesApi {
|
|
18
|
+
client;
|
|
19
|
+
opts;
|
|
20
|
+
constructor(client, opts = {}) {
|
|
21
|
+
this.client = client;
|
|
22
|
+
this.opts = opts;
|
|
23
|
+
}
|
|
24
|
+
async page(method, key, opts) {
|
|
25
|
+
const blocked = gate(this.opts.capabilities, "resources", method);
|
|
26
|
+
if (blocked)
|
|
27
|
+
return blocked;
|
|
28
|
+
const { cursor, ...ro } = opts ?? {};
|
|
29
|
+
const o = await this.client.request(method, cursorParams(cursor), { ...ro, idempotent: true });
|
|
30
|
+
return mapOutcome(mapMethodNotFound(o, "resources"), (v, meta) => {
|
|
31
|
+
const next = nextCursorOf(v);
|
|
32
|
+
const arr = v[key];
|
|
33
|
+
if (!Array.isArray(arr) || !next.ok)
|
|
34
|
+
return { kind: "protocol-violation", detail: { reason: `bad-${method}` }, meta };
|
|
35
|
+
const items = [];
|
|
36
|
+
for (const x of arr) {
|
|
37
|
+
const f = flag(x, key === "resources" ? "uri" : "uriTemplate");
|
|
38
|
+
if (f)
|
|
39
|
+
items.push(f);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
kind: "ok",
|
|
43
|
+
value: {
|
|
44
|
+
items,
|
|
45
|
+
...(next.cursor !== undefined ? { nextCursor: next.cursor } : {}),
|
|
46
|
+
...("ttlMs" in v ? { ttlMs: v["ttlMs"] } : {}),
|
|
47
|
+
...("cacheScope" in v ? { cacheScope: v["cacheScope"] } : {}),
|
|
48
|
+
},
|
|
49
|
+
meta,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
list(opts) {
|
|
54
|
+
return this.page("resources/list", "resources", opts);
|
|
55
|
+
}
|
|
56
|
+
listTemplates(opts) {
|
|
57
|
+
return this.page("resources/templates/list", "resourceTemplates", opts);
|
|
58
|
+
}
|
|
59
|
+
all(method, opts) {
|
|
60
|
+
const { maxPages, maxItems, restartOnInvalidCursor, ...ro } = opts ?? {};
|
|
61
|
+
return listAll(method, async (cursor) => mapOutcome(await (method === "resources/list" ? this.list : this.listTemplates).call(this, { ...ro, ...(cursor !== undefined ? { cursor } : {}) }), (v, meta) => ({
|
|
62
|
+
kind: "ok",
|
|
63
|
+
value: { items: v.items, ...(v.nextCursor !== undefined ? { nextCursor: v.nextCursor } : {}) },
|
|
64
|
+
meta,
|
|
65
|
+
})), {
|
|
66
|
+
...(maxPages !== undefined ? { maxPages } : {}),
|
|
67
|
+
...(maxItems !== undefined ? { maxItems } : {}),
|
|
68
|
+
...(restartOnInvalidCursor !== undefined ? { restartOnInvalidCursor } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
listAll(opts) {
|
|
72
|
+
return this.all("resources/list", opts);
|
|
73
|
+
}
|
|
74
|
+
listAllTemplates(opts) {
|
|
75
|
+
return this.all("resources/templates/list", opts);
|
|
76
|
+
}
|
|
77
|
+
/** RFC 6570 level 1-4 expansion, local only. */
|
|
78
|
+
expandTemplate(template, vars) {
|
|
79
|
+
return expandUriTemplate(template, vars);
|
|
80
|
+
}
|
|
81
|
+
/** resources/read. Never fetches the URI itself (OPS-RES-5). */
|
|
82
|
+
async read(uri, opts) {
|
|
83
|
+
const blocked = gate(this.opts.capabilities, "resources", "resources/read");
|
|
84
|
+
if (blocked)
|
|
85
|
+
return blocked;
|
|
86
|
+
const o = await this.client.request("resources/read", { uri }, { ...opts, idempotent: true });
|
|
87
|
+
const m = mapMethodNotFound(o, "resources");
|
|
88
|
+
if (m.kind === "jsonrpc-error" && (m.code === -32602 || m.code === -32002)) {
|
|
89
|
+
return { ...m, refined: "resource-not-found" };
|
|
90
|
+
}
|
|
91
|
+
return mapOutcome(m, (v, meta) => {
|
|
92
|
+
if (!Array.isArray(v["contents"]))
|
|
93
|
+
return { kind: "protocol-violation", detail: { reason: "contents-not-array" }, meta };
|
|
94
|
+
const contents = [];
|
|
95
|
+
for (const c of v["contents"]) {
|
|
96
|
+
const e = normalizeResourceContents(c);
|
|
97
|
+
if (!e)
|
|
98
|
+
return { kind: "protocol-violation", detail: { reason: "contents-entry-needs-text-xor-blob" }, meta };
|
|
99
|
+
contents.push(e);
|
|
100
|
+
}
|
|
101
|
+
return { kind: "ok", value: { raw: v, contents, empty: contents.length === 0 }, meta };
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|