@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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +337 -2
  3. package/adapters/pi/HOST-NOTES.md +65 -0
  4. package/adapters/pi/bridge.ts +721 -0
  5. package/adapters/pi/config.ts +364 -0
  6. package/adapters/pi/content-offloaded.ts +53 -0
  7. package/adapters/pi/content.ts +78 -0
  8. package/adapters/pi/diagnostics.ts +26 -0
  9. package/adapters/pi/elicitation.ts +133 -0
  10. package/adapters/pi/index.ts +210 -0
  11. package/adapters/pi/oauth.ts +219 -0
  12. package/adapters/pi/pi-api.ts +133 -0
  13. package/adapters/pi/resources.ts +177 -0
  14. package/adapters/pi/result-files.ts +32 -0
  15. package/adapters/pi/tasks.ts +49 -0
  16. package/dist/auth/client-credentials.d.ts +65 -0
  17. package/dist/auth/client-credentials.js +388 -0
  18. package/dist/auth/discovery.d.ts +28 -0
  19. package/dist/auth/discovery.js +125 -0
  20. package/dist/auth/index.d.ts +9 -0
  21. package/dist/auth/index.js +5 -0
  22. package/dist/auth/node-ports.d.ts +8 -0
  23. package/dist/auth/node-ports.js +67 -0
  24. package/dist/auth/protocol.d.ts +12 -0
  25. package/dist/auth/protocol.js +39 -0
  26. package/dist/auth/provider.d.ts +114 -0
  27. package/dist/auth/provider.js +407 -0
  28. package/dist/auth/safe-fetch.d.ts +14 -0
  29. package/dist/auth/safe-fetch.js +130 -0
  30. package/dist/client/events.d.ts +33 -0
  31. package/dist/client/events.js +84 -0
  32. package/dist/client/index.d.ts +65 -0
  33. package/dist/client/index.js +128 -0
  34. package/dist/core/auth-types.d.ts +36 -0
  35. package/dist/core/auth-types.js +11 -0
  36. package/dist/core/bearer-challenge.d.ts +3 -0
  37. package/dist/core/bearer-challenge.js +63 -0
  38. package/dist/core/cancel.d.ts +70 -0
  39. package/dist/core/cancel.js +177 -0
  40. package/dist/core/extension.d.ts +33 -0
  41. package/dist/core/extension.js +145 -0
  42. package/dist/core/index.d.ts +73 -0
  43. package/dist/core/index.js +129 -0
  44. package/dist/core/jsonrpc.d.ts +49 -0
  45. package/dist/core/jsonrpc.js +80 -0
  46. package/dist/core/lifecycle.d.ts +128 -0
  47. package/dist/core/lifecycle.js +251 -0
  48. package/dist/core/outcome.d.ts +98 -0
  49. package/dist/core/outcome.js +32 -0
  50. package/dist/core/ports.d.ts +144 -0
  51. package/dist/core/ports.js +67 -0
  52. package/dist/core/progress.d.ts +81 -0
  53. package/dist/core/progress.js +205 -0
  54. package/dist/core/request.d.ts +108 -0
  55. package/dist/core/request.js +578 -0
  56. package/dist/core/schema/index.d.ts +1 -0
  57. package/dist/core/schema/index.js +1 -0
  58. package/dist/core/schema/types.d.ts +4154 -0
  59. package/dist/core/schema/types.js +6 -0
  60. package/dist/core/telemetry.d.ts +25 -0
  61. package/dist/core/telemetry.js +37 -0
  62. package/dist/ext-events/index.d.ts +79 -0
  63. package/dist/ext-events/index.js +218 -0
  64. package/dist/ext-events/model.d.ts +10 -0
  65. package/dist/ext-events/model.js +6 -0
  66. package/dist/ext-events/push.d.ts +18 -0
  67. package/dist/ext-events/push.js +101 -0
  68. package/dist/ext-events/stream.d.ts +6 -0
  69. package/dist/ext-events/stream.js +60 -0
  70. package/dist/ext-server-cards/index.d.ts +107 -0
  71. package/dist/ext-server-cards/index.js +249 -0
  72. package/dist/ext-skills/cache.d.ts +20 -0
  73. package/dist/ext-skills/cache.js +101 -0
  74. package/dist/ext-skills/client.d.ts +82 -0
  75. package/dist/ext-skills/client.js +292 -0
  76. package/dist/ext-skills/extension.d.ts +16 -0
  77. package/dist/ext-skills/extension.js +29 -0
  78. package/dist/ext-skills/index.d.ts +4 -0
  79. package/dist/ext-skills/index.js +4 -0
  80. package/dist/ext-skills/verify.d.ts +57 -0
  81. package/dist/ext-skills/verify.js +168 -0
  82. package/dist/index.d.ts +1 -0
  83. package/dist/index.js +1 -0
  84. package/dist/mrtr-cache/cache.d.ts +51 -0
  85. package/dist/mrtr-cache/cache.js +295 -0
  86. package/dist/mrtr-cache/client.d.ts +24 -0
  87. package/dist/mrtr-cache/client.js +44 -0
  88. package/dist/mrtr-cache/common.d.ts +10 -0
  89. package/dist/mrtr-cache/common.js +9 -0
  90. package/dist/mrtr-cache/elicitation.d.ts +42 -0
  91. package/dist/mrtr-cache/elicitation.js +221 -0
  92. package/dist/mrtr-cache/index.d.ts +9 -0
  93. package/dist/mrtr-cache/index.js +8 -0
  94. package/dist/mrtr-cache/mrtr.d.ts +37 -0
  95. package/dist/mrtr-cache/mrtr.js +250 -0
  96. package/dist/mrtr-cache/refresh.d.ts +8 -0
  97. package/dist/mrtr-cache/refresh.js +30 -0
  98. package/dist/mrtr-cache/stream.d.ts +5 -0
  99. package/dist/mrtr-cache/stream.js +18 -0
  100. package/dist/mrtr-cache/subscriptions.d.ts +96 -0
  101. package/dist/mrtr-cache/subscriptions.js +288 -0
  102. package/dist/mrtr-cache/tasks.d.ts +103 -0
  103. package/dist/mrtr-cache/tasks.js +444 -0
  104. package/dist/ops/common.d.ts +18 -0
  105. package/dist/ops/common.js +39 -0
  106. package/dist/ops/completion.d.ts +44 -0
  107. package/dist/ops/completion.js +65 -0
  108. package/dist/ops/content.d.ts +40 -0
  109. package/dist/ops/content.js +117 -0
  110. package/dist/ops/icons.d.ts +29 -0
  111. package/dist/ops/icons.js +82 -0
  112. package/dist/ops/index.d.ts +30 -0
  113. package/dist/ops/index.js +28 -0
  114. package/dist/ops/pagination.d.ts +32 -0
  115. package/dist/ops/pagination.js +65 -0
  116. package/dist/ops/prompts.d.ts +32 -0
  117. package/dist/ops/prompts.js +68 -0
  118. package/dist/ops/resources.d.ts +42 -0
  119. package/dist/ops/resources.js +104 -0
  120. package/dist/ops/schema.d.ts +39 -0
  121. package/dist/ops/schema.js +163 -0
  122. package/dist/ops/tools.d.ts +88 -0
  123. package/dist/ops/tools.js +169 -0
  124. package/dist/ops/uri-template.d.ts +3 -0
  125. package/dist/ops/uri-template.js +101 -0
  126. package/dist/server/index.d.ts +5 -0
  127. package/dist/server/index.js +5 -0
  128. package/dist/server/mrtr.d.ts +38 -0
  129. package/dist/server/mrtr.js +99 -0
  130. package/dist/server/protocol.d.ts +21 -0
  131. package/dist/server/protocol.js +49 -0
  132. package/dist/server/server.d.ts +105 -0
  133. package/dist/server/server.js +383 -0
  134. package/dist/server/skills.d.ts +45 -0
  135. package/dist/server/skills.js +73 -0
  136. package/dist/server/uri.d.ts +2 -0
  137. package/dist/server/uri.js +27 -0
  138. package/dist/server-events/bus.d.ts +40 -0
  139. package/dist/server-events/bus.js +84 -0
  140. package/dist/server-events/events.d.ts +36 -0
  141. package/dist/server-events/events.js +108 -0
  142. package/dist/server-events/index.d.ts +6 -0
  143. package/dist/server-events/index.js +6 -0
  144. package/dist/server-events/notices.d.ts +24 -0
  145. package/dist/server-events/notices.js +31 -0
  146. package/dist/server-events/subscriptions.d.ts +33 -0
  147. package/dist/server-events/subscriptions.js +77 -0
  148. package/dist/server-events/tasks.d.ts +43 -0
  149. package/dist/server-events/tasks.js +101 -0
  150. package/dist/server-events/types.d.ts +25 -0
  151. package/dist/server-events/types.js +34 -0
  152. package/dist/server-transport/auth.d.ts +20 -0
  153. package/dist/server-transport/auth.js +29 -0
  154. package/dist/server-transport/channel.d.ts +17 -0
  155. package/dist/server-transport/channel.js +47 -0
  156. package/dist/server-transport/http.d.ts +19 -0
  157. package/dist/server-transport/http.js +209 -0
  158. package/dist/server-transport/index.d.ts +4 -0
  159. package/dist/server-transport/index.js +4 -0
  160. package/dist/server-transport/stdio.d.ts +16 -0
  161. package/dist/server-transport/stdio.js +83 -0
  162. package/dist/telemetry-otel/index.d.ts +64 -0
  163. package/dist/telemetry-otel/index.js +196 -0
  164. package/dist/testing/index.d.ts +36 -0
  165. package/dist/testing/index.js +140 -0
  166. package/dist/transport-http/headers.d.ts +24 -0
  167. package/dist/transport-http/headers.js +140 -0
  168. package/dist/transport-http/index.d.ts +3 -0
  169. package/dist/transport-http/index.js +3 -0
  170. package/dist/transport-http/sse.d.ts +33 -0
  171. package/dist/transport-http/sse.js +152 -0
  172. package/dist/transport-http/transport.d.ts +66 -0
  173. package/dist/transport-http/transport.js +854 -0
  174. package/dist/transport-stdio/framing.d.ts +50 -0
  175. package/dist/transport-stdio/framing.js +154 -0
  176. package/dist/transport-stdio/index.d.ts +4 -0
  177. package/dist/transport-stdio/index.js +4 -0
  178. package/dist/transport-stdio/stderr-ring.d.ts +27 -0
  179. package/dist/transport-stdio/stderr-ring.js +105 -0
  180. package/dist/transport-stdio/transport.d.ts +142 -0
  181. package/dist/transport-stdio/transport.js +743 -0
  182. package/dist/transport-stdio/write-queue.d.ts +48 -0
  183. package/dist/transport-stdio/write-queue.js +147 -0
  184. package/package.json +134 -4
@@ -0,0 +1,292 @@
1
+ import { SKILLS_EXTENSION_ID, SKILLS_REVISION } from "./extension.js";
2
+ import { isSkillMdUri, manifestFingerprint, validateSkillEntry, verifyFileBytes, verifySkillMd, } from "./verify.js";
3
+ function syntheticMeta(method) {
4
+ return { requestId: 0, method, binding: "local", attempts: 0 };
5
+ }
6
+ function isObj(v) {
7
+ return Boolean(v) && typeof v === "object" && !Array.isArray(v);
8
+ }
9
+ export class SkillsClient {
10
+ client;
11
+ serverKey;
12
+ caps;
13
+ approval;
14
+ cache;
15
+ allowDynamic;
16
+ entries = new Map();
17
+ approvedFingerprints = new Map();
18
+ constructor(opts) {
19
+ this.client = opts.client;
20
+ this.serverKey = opts.serverKey ?? opts.client.server.key;
21
+ this.caps = opts.capabilities;
22
+ this.approval = opts.approval;
23
+ this.cache = opts.cache;
24
+ this.allowDynamic = opts.allowDynamic === true;
25
+ }
26
+ entryKey(skillUri) {
27
+ return `${this.serverKey}\0${skillUri}`;
28
+ }
29
+ checkCapabilities() {
30
+ if (!this.caps)
31
+ return { ok: false, reason: "server capabilities missing" };
32
+ if (!isObj(this.caps["resources"]))
33
+ return { ok: false, reason: "server resources capability absent" };
34
+ const exts = this.caps["extensions"];
35
+ if (!isObj(exts))
36
+ return { ok: false, reason: "server extensions capability absent" };
37
+ const ext = exts[SKILLS_EXTENSION_ID];
38
+ if (!isObj(ext))
39
+ return { ok: false, reason: "server skills extension capability absent" };
40
+ if (ext["revision"] !== undefined && ext["revision"] !== SKILLS_REVISION) {
41
+ return { ok: false, reason: `unknown skills revision: ${String(ext["revision"])}` };
42
+ }
43
+ return { ok: true, directoryRead: ext["directoryRead"] === true };
44
+ }
45
+ isKnownSkill(skillUri) {
46
+ return this.entries.has(this.entryKey(skillUri));
47
+ }
48
+ getRetainedSkill(skillUri) {
49
+ return this.entries.get(this.entryKey(skillUri));
50
+ }
51
+ listRetainedSkills() {
52
+ return Array.from(this.entries.values());
53
+ }
54
+ retainEntry(entry) {
55
+ const key = this.entryKey(entry.uri);
56
+ const prev = this.entries.get(key);
57
+ if (prev && manifestFingerprint(prev.files) !== manifestFingerprint(entry.files)) {
58
+ this.approvedFingerprints.delete(key);
59
+ }
60
+ this.entries.set(key, entry);
61
+ }
62
+ async list(cursor) {
63
+ const cap = this.checkCapabilities();
64
+ if (!cap.ok) {
65
+ return { kind: "capability-absent", detail: cap.reason, meta: syntheticMeta("skills/list") };
66
+ }
67
+ const out = await this.client.request("skills/list", cursor ? { cursor } : {});
68
+ if (out.kind !== "ok")
69
+ return out;
70
+ const res = out.value;
71
+ if (!Array.isArray(res["skills"])) {
72
+ return { kind: "protocol-violation", detail: "skills/list missing skills array", meta: out.meta };
73
+ }
74
+ const skills = [];
75
+ for (const raw of res["skills"]) {
76
+ const v = validateSkillEntry(raw, { allowDynamic: this.allowDynamic });
77
+ if (!v.ok) {
78
+ return { kind: v.kind === "limit-exceeded" ? "limit-exceeded" : "protocol-violation", detail: v.reason, meta: out.meta };
79
+ }
80
+ this.retainEntry(v.entry);
81
+ skills.push(v.entry);
82
+ }
83
+ return {
84
+ kind: "ok",
85
+ value: {
86
+ skills,
87
+ ...(typeof res["nextCursor"] === "string" ? { nextCursor: res["nextCursor"] } : {}),
88
+ resultType: "complete",
89
+ ...(typeof res["ttlMs"] === "number" ? { ttlMs: res["ttlMs"] } : {}),
90
+ ...(typeof res["cacheScope"] === "string" ? { cacheScope: res["cacheScope"] } : {}),
91
+ },
92
+ meta: out.meta,
93
+ };
94
+ }
95
+ async listAll() {
96
+ const all = [];
97
+ let cursor;
98
+ let lastMeta = syntheticMeta("skills/list");
99
+ let ttlMs;
100
+ let cacheScope;
101
+ do {
102
+ const page = await this.list(cursor);
103
+ if (page.kind !== "ok")
104
+ return page;
105
+ lastMeta = page.meta;
106
+ ttlMs = page.value.ttlMs;
107
+ cacheScope = page.value.cacheScope;
108
+ all.push(...page.value.skills);
109
+ cursor = page.value.nextCursor;
110
+ } while (cursor);
111
+ return {
112
+ kind: "ok",
113
+ value: {
114
+ skills: all,
115
+ resultType: "complete",
116
+ ...(ttlMs !== undefined ? { ttlMs } : {}),
117
+ ...(cacheScope !== undefined ? { cacheScope } : {}),
118
+ },
119
+ meta: lastMeta,
120
+ };
121
+ }
122
+ async get(uri) {
123
+ const cap = this.checkCapabilities();
124
+ if (!cap.ok) {
125
+ return { kind: "capability-absent", detail: cap.reason, meta: syntheticMeta("skills/get") };
126
+ }
127
+ const out = await this.client.request("skills/get", { uri });
128
+ if (out.kind !== "ok")
129
+ return out;
130
+ const res = out.value;
131
+ const rawSkill = res["skill"] ?? res;
132
+ const v = validateSkillEntry(rawSkill, { allowDynamic: this.allowDynamic });
133
+ if (!v.ok) {
134
+ return { kind: v.kind === "limit-exceeded" ? "limit-exceeded" : "protocol-violation", detail: v.reason, meta: out.meta };
135
+ }
136
+ this.retainEntry(v.entry);
137
+ return {
138
+ kind: "ok",
139
+ value: {
140
+ skill: v.entry,
141
+ resultType: "complete",
142
+ ...(typeof res["ttlMs"] === "number" ? { ttlMs: res["ttlMs"] } : {}),
143
+ ...(typeof res["cacheScope"] === "string" ? { cacheScope: res["cacheScope"] } : {}),
144
+ },
145
+ meta: out.meta,
146
+ };
147
+ }
148
+ async approve(skillUri) {
149
+ const entry = this.entries.get(this.entryKey(skillUri));
150
+ if (!entry || !this.approval)
151
+ return false;
152
+ const fp = manifestFingerprint(entry.files);
153
+ const ok = await this.approval.approveLoad({
154
+ serverKey: this.serverKey,
155
+ skillUri,
156
+ manifestFingerprint: fp,
157
+ files: entry.files,
158
+ });
159
+ if (!ok)
160
+ return false;
161
+ if (entry.allowedTools && entry.allowedTools.length > 0) {
162
+ if (!this.approval.approveTools)
163
+ return false;
164
+ const toolsOk = await this.approval.approveTools({
165
+ serverKey: this.serverKey,
166
+ skillUri,
167
+ allowedTools: entry.allowedTools,
168
+ });
169
+ if (!toolsOk)
170
+ return false;
171
+ }
172
+ this.approvedFingerprints.set(this.entryKey(skillUri), fp);
173
+ return true;
174
+ }
175
+ async activateNestedSkill(parentSkillUri, nestedSkillUri) {
176
+ const entry = this.entries.get(this.entryKey(parentSkillUri));
177
+ if (!entry || !this.approval?.approveTools)
178
+ return false;
179
+ return this.approval.approveTools({
180
+ serverKey: this.serverKey,
181
+ skillUri: parentSkillUri,
182
+ allowedTools: entry.allowedTools ?? [],
183
+ nestedSkillUri,
184
+ });
185
+ }
186
+ async readFile(skillUri, fileUri, opts) {
187
+ const meta = syntheticMeta("resources/read");
188
+ const entry = this.entries.get(this.entryKey(skillUri));
189
+ if (!entry) {
190
+ return { kind: "protocol-violation", detail: `unknown skill uri: ${skillUri}`, meta };
191
+ }
192
+ const fileEntry = entry.files.find((f) => f.uri === fileUri);
193
+ if (!fileEntry) {
194
+ return { kind: "protocol-violation", detail: `file uri not in retained manifest: ${fileUri}`, meta };
195
+ }
196
+ if (this.approval) {
197
+ const approvedFp = this.approvedFingerprints.get(this.entryKey(skillUri));
198
+ if (!approvedFp || approvedFp !== manifestFingerprint(entry.files)) {
199
+ this.approvedFingerprints.delete(this.entryKey(skillUri));
200
+ return { kind: "protocol-violation", detail: `skill not approved for current manifest: ${skillUri}`, meta };
201
+ }
202
+ }
203
+ if (opts?.resourceServer && opts.resourceServer !== this.serverKey) {
204
+ if (!this.approval?.approveCrossServerRead) {
205
+ return { kind: "protocol-violation", detail: "cross-server read requires approval port", meta };
206
+ }
207
+ const allowed = await this.approval.approveCrossServerRead({
208
+ skillServer: this.serverKey,
209
+ resourceServer: opts.resourceServer,
210
+ skillUri,
211
+ resourceUri: fileUri,
212
+ });
213
+ if (!allowed) {
214
+ return { kind: "protocol-violation", detail: "cross-server read denied", meta };
215
+ }
216
+ }
217
+ const cached = this.cache?.get(this.serverKey, skillUri, fileUri, fileEntry.size, fileEntry.sha256);
218
+ if (cached) {
219
+ const text = Buffer.from(cached.bytes).toString("utf8");
220
+ if (isSkillMdUri(fileUri)) {
221
+ const mdCheck = verifySkillMd(fileUri, text, entry);
222
+ if (!mdCheck.ok) {
223
+ await this.get(skillUri);
224
+ return { kind: "protocol-violation", detail: mdCheck.reason, meta };
225
+ }
226
+ }
227
+ return { kind: "ok", value: { file: fileEntry, bytes: cached.bytes, text, fromCache: true }, meta };
228
+ }
229
+ const reader = opts?.resourceClient ?? this.client;
230
+ const out = await reader.request("resources/read", { uri: fileUri });
231
+ if (out.kind !== "ok")
232
+ return out;
233
+ const contents = out.value["contents"];
234
+ if (!Array.isArray(contents) || contents.length === 0 || !isObj(contents[0])) {
235
+ await this.get(skillUri);
236
+ return { kind: "protocol-violation", detail: "resources/read missing contents", meta: out.meta };
237
+ }
238
+ const item = contents[0];
239
+ const bytes = typeof item["blob"] === "string"
240
+ ? new Uint8Array(Buffer.from(item["blob"], "base64"))
241
+ : typeof item["text"] === "string"
242
+ ? new Uint8Array(Buffer.from(item["text"], "utf8"))
243
+ : undefined;
244
+ if (!bytes) {
245
+ await this.get(skillUri);
246
+ return { kind: "protocol-violation", detail: "resources/read missing text or blob", meta: out.meta };
247
+ }
248
+ const byteCheck = verifyFileBytes(bytes, fileEntry);
249
+ if (!byteCheck.ok) {
250
+ await this.get(skillUri);
251
+ return { kind: "protocol-violation", detail: byteCheck.reason, meta: out.meta };
252
+ }
253
+ const text = Buffer.from(bytes).toString("utf8");
254
+ if (isSkillMdUri(fileUri)) {
255
+ const mdCheck = verifySkillMd(fileUri, text, entry);
256
+ if (!mdCheck.ok) {
257
+ await this.get(skillUri);
258
+ return { kind: "protocol-violation", detail: mdCheck.reason, meta: out.meta };
259
+ }
260
+ }
261
+ this.cache?.set({
262
+ origin: { kind: "mcp", serverKey: this.serverKey, skillUri },
263
+ uri: fileUri,
264
+ size: fileEntry.size,
265
+ sha256: fileEntry.sha256,
266
+ bytes,
267
+ });
268
+ return { kind: "ok", value: { file: fileEntry, bytes, text, fromCache: false }, meta: out.meta };
269
+ }
270
+ async readDirectory(skillUri, dirUri) {
271
+ const cap = this.checkCapabilities();
272
+ if (!cap.ok || !cap.directoryRead) {
273
+ return { kind: "capability-absent", detail: "directoryRead capability absent", meta: syntheticMeta("resources/directory/read") };
274
+ }
275
+ const entry = this.entries.get(this.entryKey(skillUri));
276
+ if (!entry) {
277
+ return { kind: "protocol-violation", detail: `unknown skill uri: ${skillUri}`, meta: syntheticMeta("resources/directory/read") };
278
+ }
279
+ const out = await this.client.request("resources/directory/read", { uri: dirUri });
280
+ if (out.kind !== "ok")
281
+ return out;
282
+ const rawUris = Array.isArray(out.value["uris"])
283
+ ? out.value["uris"].filter((u) => typeof u === "string")
284
+ : Array.isArray(out.value["entries"])
285
+ ? out.value["entries"]
286
+ .map((e) => (isObj(e) && typeof e["uri"] === "string" ? e["uri"] : undefined))
287
+ .filter((u) => Boolean(u))
288
+ : [];
289
+ const manifestUris = new Set(entry.files.map((f) => f.uri));
290
+ return { kind: "ok", value: { uris: rawUris.filter((u) => manifestUris.has(u)) }, meta: out.meta };
291
+ }
292
+ }
@@ -0,0 +1,16 @@
1
+ import type { Extension, ExtensionCapabilities } from "../core/index.js";
2
+ export declare const SKILLS_EXTENSION_ID = "io.modelcontextprotocol/skills";
3
+ export declare const SKILLS_REVISION = "2026-10-30";
4
+ export interface SkillsExtensionOptions {
5
+ readonly healthy?: boolean;
6
+ }
7
+ export declare class SkillsExtension implements Extension {
8
+ readonly id = "io.modelcontextprotocol/skills";
9
+ readonly version = "2026-10-30";
10
+ private readonly healthy;
11
+ constructor(opts?: SkillsExtensionOptions);
12
+ health(): "working" | "unhealthy";
13
+ settings(): Record<string, unknown> | undefined;
14
+ capabilities(isWorking?: boolean): ExtensionCapabilities;
15
+ }
16
+ export declare function createSkillsExtension(opts?: SkillsExtensionOptions): SkillsExtension;
@@ -0,0 +1,29 @@
1
+ export const SKILLS_EXTENSION_ID = "io.modelcontextprotocol/skills";
2
+ export const SKILLS_REVISION = "2026-10-30";
3
+ export class SkillsExtension {
4
+ id = SKILLS_EXTENSION_ID;
5
+ version = SKILLS_REVISION;
6
+ healthy;
7
+ constructor(opts = {}) {
8
+ this.healthy = opts.healthy !== false;
9
+ }
10
+ health() {
11
+ return this.healthy ? "working" : "unhealthy";
12
+ }
13
+ settings() {
14
+ return this.health() === "working" ? {} : undefined;
15
+ }
16
+ capabilities(isWorking = true) {
17
+ if (!isWorking || this.health() !== "working") {
18
+ return {};
19
+ }
20
+ return {
21
+ extensions: {
22
+ [SKILLS_EXTENSION_ID]: {},
23
+ },
24
+ };
25
+ }
26
+ }
27
+ export function createSkillsExtension(opts) {
28
+ return new SkillsExtension(opts);
29
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./verify.js";
2
+ export * from "./cache.js";
3
+ export * from "./extension.js";
4
+ export * from "./client.js";
@@ -0,0 +1,4 @@
1
+ export * from "./verify.js";
2
+ export * from "./cache.js";
3
+ export * from "./extension.js";
4
+ export * from "./client.js";
@@ -0,0 +1,57 @@
1
+ export declare const MAX_SKILL_FILES = 512;
2
+ export declare const MAX_SKILL_BYTES: number;
3
+ export declare const SKILL_CACHE_EXCLUDE_MARKER = ".mcp-skill-cache-exclude";
4
+ export interface SkillFileEntry {
5
+ readonly uri: string;
6
+ readonly size: number;
7
+ readonly sha256: string;
8
+ readonly mimeType?: string;
9
+ }
10
+ export interface SkillEntry {
11
+ readonly uri: string;
12
+ readonly name: string;
13
+ readonly description: string;
14
+ readonly files: readonly SkillFileEntry[];
15
+ readonly resources?: "static" | "dynamic";
16
+ readonly allowedTools?: readonly string[];
17
+ readonly metadata?: Record<string, unknown>;
18
+ }
19
+ export interface SkillOrigin {
20
+ readonly kind: "mcp";
21
+ readonly serverKey: string;
22
+ readonly skillUri: string;
23
+ }
24
+ export interface SkillCacheEntry {
25
+ readonly origin: SkillOrigin;
26
+ readonly uri: string;
27
+ readonly size: number;
28
+ readonly sha256: string;
29
+ readonly bytes: Uint8Array;
30
+ }
31
+ export declare function sha256Hex(bytes: Uint8Array): string;
32
+ export declare function manifestFingerprint(files: readonly SkillFileEntry[]): string;
33
+ export type EntryValidation = {
34
+ readonly ok: true;
35
+ readonly entry: SkillEntry;
36
+ } | {
37
+ readonly ok: false;
38
+ readonly kind: "protocol-violation" | "limit-exceeded" | "dynamic-declined";
39
+ readonly reason: string;
40
+ };
41
+ export declare function validateSkillEntry(raw: unknown, opts?: {
42
+ readonly allowDynamic?: boolean;
43
+ }): EntryValidation;
44
+ export declare function verifyFileBytes(bytes: Uint8Array, expected: SkillFileEntry): {
45
+ readonly ok: true;
46
+ } | {
47
+ readonly ok: false;
48
+ readonly reason: string;
49
+ };
50
+ export declare function parseYamlFrontmatter(text: string): Record<string, unknown> | undefined;
51
+ export declare function isSkillMdUri(uri: string): boolean;
52
+ export declare function verifySkillMd(uri: string, text: string, entry: SkillEntry): {
53
+ readonly ok: true;
54
+ } | {
55
+ readonly ok: false;
56
+ readonly reason: string;
57
+ };
@@ -0,0 +1,168 @@
1
+ import { createHash } from "node:crypto";
2
+ export const MAX_SKILL_FILES = 512;
3
+ export const MAX_SKILL_BYTES = 16 * 1024 * 1024;
4
+ export const SKILL_CACHE_EXCLUDE_MARKER = ".mcp-skill-cache-exclude";
5
+ export function sha256Hex(bytes) {
6
+ return createHash("sha256").update(bytes).digest("hex");
7
+ }
8
+ export function manifestFingerprint(files) {
9
+ const sorted = [...files]
10
+ .map((f) => ({ uri: f.uri, size: f.size, sha256: f.sha256 }))
11
+ .sort((a, b) => (a.uri < b.uri ? -1 : a.uri > b.uri ? 1 : 0));
12
+ return sha256Hex(Buffer.from(JSON.stringify(sorted), "utf8"));
13
+ }
14
+ const SHA256_RE = /^[0-9a-f]{64}$/;
15
+ export function validateSkillEntry(raw, opts) {
16
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
17
+ return { ok: false, kind: "protocol-violation", reason: "skill entry must be an object" };
18
+ }
19
+ const r = raw;
20
+ if (typeof r["uri"] !== "string" || !r["uri"]) {
21
+ return { ok: false, kind: "protocol-violation", reason: "skill entry missing uri" };
22
+ }
23
+ if (typeof r["name"] !== "string" || !r["name"]) {
24
+ return { ok: false, kind: "protocol-violation", reason: "skill entry missing name" };
25
+ }
26
+ if (typeof r["description"] !== "string") {
27
+ return { ok: false, kind: "protocol-violation", reason: "skill entry missing description" };
28
+ }
29
+ if (!Array.isArray(r["files"])) {
30
+ return { ok: false, kind: "protocol-violation", reason: "skill entry missing complete files manifest" };
31
+ }
32
+ const resources = r["resources"];
33
+ if (resources !== undefined && resources !== "static" && resources !== "dynamic") {
34
+ return { ok: false, kind: "protocol-violation", reason: "invalid resources mode" };
35
+ }
36
+ if (resources === "dynamic" && !opts?.allowDynamic) {
37
+ return { ok: false, kind: "dynamic-declined", reason: "dynamic resources declined by default" };
38
+ }
39
+ if (r["files"].length > MAX_SKILL_FILES) {
40
+ return { ok: false, kind: "limit-exceeded", reason: `file count ${r["files"].length} exceeds ${MAX_SKILL_FILES}` };
41
+ }
42
+ let totalBytes = 0;
43
+ const files = [];
44
+ for (const item of r["files"]) {
45
+ if (!item || typeof item !== "object" || Array.isArray(item)) {
46
+ return { ok: false, kind: "protocol-violation", reason: "manifest file entry must be an object" };
47
+ }
48
+ const f = item;
49
+ if (typeof f["uri"] !== "string" || !f["uri"]) {
50
+ return { ok: false, kind: "protocol-violation", reason: "manifest file missing uri" };
51
+ }
52
+ if (typeof f["size"] !== "number" || !Number.isInteger(f["size"]) || f["size"] < 0) {
53
+ return { ok: false, kind: "protocol-violation", reason: `invalid size for ${f["uri"]}` };
54
+ }
55
+ if (typeof f["sha256"] !== "string" || !SHA256_RE.test(f["sha256"])) {
56
+ return { ok: false, kind: "protocol-violation", reason: `invalid sha256 for ${f["uri"]}` };
57
+ }
58
+ totalBytes += f["size"];
59
+ if (totalBytes > MAX_SKILL_BYTES) {
60
+ return { ok: false, kind: "limit-exceeded", reason: `total bytes ${totalBytes} exceeds ${MAX_SKILL_BYTES}` };
61
+ }
62
+ files.push({
63
+ uri: f["uri"],
64
+ size: f["size"],
65
+ sha256: f["sha256"],
66
+ ...(typeof f["mimeType"] === "string" ? { mimeType: f["mimeType"] } : {}),
67
+ });
68
+ }
69
+ const rawTools = r["allowed-tools"] ?? r["allowedTools"];
70
+ const allowedTools = Array.isArray(rawTools) && rawTools.every((t) => typeof t === "string") ? rawTools : undefined;
71
+ return {
72
+ ok: true,
73
+ entry: {
74
+ uri: r["uri"],
75
+ name: r["name"],
76
+ description: r["description"],
77
+ files,
78
+ ...(resources !== undefined ? { resources } : {}),
79
+ ...(allowedTools !== undefined ? { allowedTools } : {}),
80
+ ...(r["metadata"] && typeof r["metadata"] === "object" && !Array.isArray(r["metadata"])
81
+ ? { metadata: r["metadata"] }
82
+ : {}),
83
+ },
84
+ };
85
+ }
86
+ export function verifyFileBytes(bytes, expected) {
87
+ if (bytes.byteLength !== expected.size) {
88
+ return { ok: false, reason: `size mismatch for ${expected.uri}: expected ${expected.size}, got ${bytes.byteLength}` };
89
+ }
90
+ const actual = sha256Hex(bytes);
91
+ if (actual !== expected.sha256) {
92
+ return { ok: false, reason: `sha256 mismatch for ${expected.uri}: expected ${expected.sha256}, got ${actual}` };
93
+ }
94
+ return { ok: true };
95
+ }
96
+ export function parseYamlFrontmatter(text) {
97
+ const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
98
+ if (!m)
99
+ return undefined;
100
+ const lines = (m[1] ?? "").split(/\r?\n/);
101
+ const out = {};
102
+ let currentKey;
103
+ for (const rawLine of lines) {
104
+ const line = rawLine.trimEnd();
105
+ if (!line || line.trimStart().startsWith("#"))
106
+ continue;
107
+ const listMatch = line.match(/^\s+-\s+(.*)$/);
108
+ if (listMatch && currentKey) {
109
+ const arr = Array.isArray(out[currentKey]) ? out[currentKey] : [];
110
+ arr.push(unquote(listMatch[1].trim()));
111
+ out[currentKey] = arr;
112
+ continue;
113
+ }
114
+ const kv = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
115
+ if (!kv)
116
+ continue;
117
+ currentKey = kv[1];
118
+ const val = kv[2].trim();
119
+ if (val === "") {
120
+ out[currentKey] = [];
121
+ }
122
+ else if (val.startsWith("[") && val.endsWith("]")) {
123
+ const inner = val.slice(1, -1).trim();
124
+ out[currentKey] = inner ? inner.split(",").map((s) => unquote(s.trim())) : [];
125
+ }
126
+ else {
127
+ out[currentKey] = unquote(val);
128
+ }
129
+ }
130
+ return out;
131
+ }
132
+ function unquote(s) {
133
+ if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
134
+ return s.slice(1, -1);
135
+ }
136
+ return s;
137
+ }
138
+ export function isSkillMdUri(uri) {
139
+ const clean = uri.split(/[?#]/)[0] ?? uri;
140
+ return clean.endsWith("/SKILL.md") || clean === "SKILL.md";
141
+ }
142
+ export function verifySkillMd(uri, text, entry) {
143
+ const clean = uri.split(/[?#]/)[0] ?? uri;
144
+ const parts = clean.split("/").filter(Boolean);
145
+ const parent = parts.length >= 2 ? parts[parts.length - 2] : undefined;
146
+ if (parent !== entry.name) {
147
+ return { ok: false, reason: `SKILL.md parent dir "${parent ?? ""}" does not match skill name "${entry.name}"` };
148
+ }
149
+ const fm = parseYamlFrontmatter(text);
150
+ if (!fm) {
151
+ return { ok: false, reason: "SKILL.md missing YAML frontmatter" };
152
+ }
153
+ if (fm["name"] !== entry.name) {
154
+ return { ok: false, reason: `frontmatter name mismatch: expected "${entry.name}", got "${String(fm["name"])}"` };
155
+ }
156
+ if (fm["description"] !== entry.description) {
157
+ return { ok: false, reason: `frontmatter description mismatch` };
158
+ }
159
+ const fmTools = fm["allowed-tools"] ?? fm["allowedTools"];
160
+ if (entry.allowedTools !== undefined || fmTools !== undefined) {
161
+ const a = JSON.stringify(entry.allowedTools ?? []);
162
+ const b = JSON.stringify(Array.isArray(fmTools) ? fmTools : typeof fmTools === "string" ? fmTools.split(/\s+/).filter(Boolean) : []);
163
+ if (a !== b) {
164
+ return { ok: false, reason: `frontmatter allowed-tools mismatch` };
165
+ }
166
+ }
167
+ return { ok: true };
168
+ }
@@ -0,0 +1 @@
1
+ export * from "./core/index.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./core/index.js";
@@ -0,0 +1,51 @@
1
+ import type { Outcome, RequestOptions } from "../core/index.js";
2
+ import { type Diagnostic, type Obj, type RequestFn } from "./common.js";
3
+ export interface CacheContext {
4
+ serverRef: string;
5
+ authContextId: string;
6
+ }
7
+ export interface CacheEntry extends CacheContext {
8
+ method: string;
9
+ uri: unknown;
10
+ key: string;
11
+ shared: boolean;
12
+ scope: "public" | "private";
13
+ mixed: boolean;
14
+ expires: number;
15
+ size: number;
16
+ outcome: Extract<Outcome<unknown>, {
17
+ kind: "ok";
18
+ }>;
19
+ }
20
+ /** Insertion-ordered LRU store. Durable implementations must use the host clock domain for expires. */
21
+ export interface ResultCacheStore extends Iterable<[string, CacheEntry]> {
22
+ readonly perPrincipalIsolation?: boolean;
23
+ get(key: string): CacheEntry | undefined;
24
+ set(key: string, value: CacheEntry): unknown;
25
+ delete(key: string): unknown;
26
+ readonly size: number;
27
+ }
28
+ export interface CacheOptions {
29
+ now?: () => number;
30
+ maxEntries?: number;
31
+ maxBytes?: number;
32
+ maxEntryBytes?: number;
33
+ maxTtlMs?: number;
34
+ sharePublic?: boolean;
35
+ staleIfError?: boolean;
36
+ store?: ResultCacheStore;
37
+ diagnostic?: Diagnostic;
38
+ }
39
+ export declare class ResultCache {
40
+ private readonly options;
41
+ private readonly memory;
42
+ private readonly stores;
43
+ private readonly flights;
44
+ private readonly now;
45
+ constructor(options?: CacheOptions);
46
+ private purge;
47
+ invalidate(serverRef: string, method: string, uri?: string): void;
48
+ notification(serverRef: string, method: string, params?: Obj): void;
49
+ private insert;
50
+ run(ctx: CacheContext, method: string, params: Obj, opts: RequestOptions, request: RequestFn): Promise<Outcome<unknown>>;
51
+ }