@contractspec/bundle.library 3.8.4 → 3.8.5

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 (90) hide show
  1. package/.turbo/turbo-build.log +126 -112
  2. package/CHANGELOG.md +6 -0
  3. package/dist/application/index.js +806 -131
  4. package/dist/application/mcp/cliMcp.js +21 -2
  5. package/dist/application/mcp/common.js +21 -2
  6. package/dist/application/mcp/common.test.d.ts +1 -0
  7. package/dist/application/mcp/contractsMcp.js +21 -2
  8. package/dist/application/mcp/docsMcp.catalog.d.ts +2 -0
  9. package/dist/application/mcp/docsMcp.catalog.js +382 -0
  10. package/dist/application/mcp/docsMcp.d.ts +5 -1
  11. package/dist/application/mcp/docsMcp.data.d.ts +85 -0
  12. package/dist/application/mcp/docsMcp.data.js +148 -0
  13. package/dist/application/mcp/docsMcp.js +776 -101
  14. package/dist/application/mcp/docsMcp.prompts.d.ts +3 -0
  15. package/dist/application/mcp/docsMcp.prompts.js +522 -0
  16. package/dist/application/mcp/docsMcp.reference.d.ts +24 -0
  17. package/dist/application/mcp/docsMcp.reference.js +236 -0
  18. package/dist/application/mcp/docsMcp.resources.d.ts +3 -0
  19. package/dist/application/mcp/docsMcp.resources.js +520 -0
  20. package/dist/application/mcp/docsMcp.test.d.ts +1 -0
  21. package/dist/application/mcp/docsMcp.tools.d.ts +3 -0
  22. package/dist/application/mcp/docsMcp.tools.js +519 -0
  23. package/dist/application/mcp/index.js +806 -131
  24. package/dist/application/mcp/internalMcp.js +21 -2
  25. package/dist/application/mcp/normalizeMcpRequest.d.ts +1 -0
  26. package/dist/application/mcp/normalizeMcpRequest.js +22 -0
  27. package/dist/application/mcp/providerRankingMcp.js +21 -2
  28. package/dist/features/index.js +15 -15
  29. package/dist/index.js +171 -171
  30. package/dist/node/application/index.js +806 -131
  31. package/dist/node/application/mcp/cliMcp.js +21 -2
  32. package/dist/node/application/mcp/common.js +21 -2
  33. package/dist/node/application/mcp/contractsMcp.js +21 -2
  34. package/dist/node/application/mcp/docsMcp.catalog.js +381 -0
  35. package/dist/node/application/mcp/docsMcp.data.js +147 -0
  36. package/dist/node/application/mcp/docsMcp.js +776 -101
  37. package/dist/node/application/mcp/docsMcp.prompts.js +521 -0
  38. package/dist/node/application/mcp/docsMcp.reference.js +235 -0
  39. package/dist/node/application/mcp/docsMcp.resources.js +519 -0
  40. package/dist/node/application/mcp/docsMcp.tools.js +518 -0
  41. package/dist/node/application/mcp/index.js +806 -131
  42. package/dist/node/application/mcp/internalMcp.js +21 -2
  43. package/dist/node/application/mcp/normalizeMcpRequest.js +21 -0
  44. package/dist/node/application/mcp/providerRankingMcp.js +21 -2
  45. package/dist/node/features/index.js +15 -15
  46. package/dist/node/index.js +171 -171
  47. package/dist/node/presentation/features/hooks/index.js +12 -12
  48. package/dist/node/presentation/features/hooks/useContractsRegistry.js +12 -12
  49. package/dist/node/presentation/features/index.js +12 -12
  50. package/dist/node/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  51. package/dist/node/presentation/features/organisms/FeatureEventsList.js +12 -12
  52. package/dist/node/presentation/features/organisms/FeatureFormsList.js +12 -12
  53. package/dist/node/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  54. package/dist/node/presentation/features/organisms/index.js +12 -12
  55. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  56. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  57. package/dist/node/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  58. package/dist/node/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  59. package/dist/node/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  60. package/dist/node/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  61. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  62. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  63. package/dist/presentation/features/hooks/index.js +12 -12
  64. package/dist/presentation/features/hooks/useContractsRegistry.js +12 -12
  65. package/dist/presentation/features/index.js +12 -12
  66. package/dist/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  67. package/dist/presentation/features/organisms/FeatureEventsList.js +12 -12
  68. package/dist/presentation/features/organisms/FeatureFormsList.js +12 -12
  69. package/dist/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  70. package/dist/presentation/features/organisms/index.js +12 -12
  71. package/dist/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  72. package/dist/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  73. package/dist/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  74. package/dist/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  75. package/dist/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  76. package/dist/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  77. package/dist/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  78. package/dist/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  79. package/package.json +85 -1
  80. package/src/application/mcp/common.test.ts +64 -0
  81. package/src/application/mcp/common.ts +5 -2
  82. package/src/application/mcp/docsMcp.catalog.ts +2 -0
  83. package/src/application/mcp/docsMcp.data.ts +196 -0
  84. package/src/application/mcp/docsMcp.prompts.ts +165 -0
  85. package/src/application/mcp/docsMcp.reference.ts +152 -0
  86. package/src/application/mcp/docsMcp.resources.ts +194 -0
  87. package/src/application/mcp/docsMcp.test.ts +148 -0
  88. package/src/application/mcp/docsMcp.tools.ts +183 -0
  89. package/src/application/mcp/docsMcp.ts +13 -177
  90. package/src/application/mcp/normalizeMcpRequest.ts +30 -0
@@ -0,0 +1,519 @@
1
+ // src/application/mcp/docsMcp.data.ts
2
+ import { defaultDocRegistry } from "@contractspec/lib.contracts-spec/docs";
3
+ var DEFAULT_LIMIT = 20;
4
+ var MAX_LIMIT = 100;
5
+ function normalizeText(value) {
6
+ return value?.trim().toLowerCase() ?? "";
7
+ }
8
+ function normalizeRoute(route) {
9
+ const decoded = decodeURIComponent(route).trim();
10
+ if (!decoded)
11
+ return "/";
12
+ return decoded.startsWith("/") ? decoded : `/${decoded}`;
13
+ }
14
+ function normalizeTags(value) {
15
+ const tags = Array.isArray(value) ? value : value ? [value] : [];
16
+ return tags.map((tag) => normalizeText(tag)).filter(Boolean);
17
+ }
18
+ function clampLimit(limit) {
19
+ if (!limit || Number.isNaN(limit))
20
+ return DEFAULT_LIMIT;
21
+ return Math.min(Math.max(limit, 1), MAX_LIMIT);
22
+ }
23
+ function clampOffset(offset) {
24
+ if (!offset || Number.isNaN(offset))
25
+ return 0;
26
+ return Math.max(offset, 0);
27
+ }
28
+ function toDocSummary({ block, route }) {
29
+ return {
30
+ id: block.id,
31
+ title: block.title,
32
+ summary: block.summary ?? "",
33
+ route,
34
+ visibility: block.visibility ?? "public",
35
+ kind: block.kind ?? "reference",
36
+ version: block.version ?? "1.0.0",
37
+ tags: block.tags ?? []
38
+ };
39
+ }
40
+ function scoreDoc(route, query) {
41
+ if (!query)
42
+ return 1;
43
+ const tokens = query.split(/\s+/).filter(Boolean);
44
+ const title = normalizeText(route.block.title);
45
+ const id = normalizeText(route.block.id);
46
+ const summary = normalizeText(route.block.summary);
47
+ const body = normalizeText(route.block.body);
48
+ const path = normalizeText(route.route);
49
+ const tags = (route.block.tags ?? []).map((tag) => normalizeText(tag));
50
+ const haystack = [title, id, summary, body, path, ...tags].join(" ");
51
+ if (tokens.some((token) => !haystack.includes(token)))
52
+ return 0;
53
+ let score = 0;
54
+ for (const token of tokens) {
55
+ if (id.includes(token))
56
+ score += 8;
57
+ if (title.includes(token))
58
+ score += 7;
59
+ if (tags.some((tag) => tag.includes(token)))
60
+ score += 5;
61
+ if (summary.includes(token))
62
+ score += 4;
63
+ if (path.includes(token))
64
+ score += 3;
65
+ if (body.includes(token))
66
+ score += 2;
67
+ }
68
+ return score;
69
+ }
70
+ function searchDocs(routes, args) {
71
+ const query = normalizeText(typeof args.query === "string" ? args.query : undefined);
72
+ const tags = normalizeTags(args.tag);
73
+ const visibility = normalizeText(typeof args.visibility === "string" ? args.visibility : undefined);
74
+ const kind = normalizeText(typeof args.kind === "string" ? args.kind : undefined);
75
+ const limit = clampLimit(typeof args.limit === "number" ? args.limit : undefined);
76
+ const offset = clampOffset(typeof args.offset === "number" ? args.offset : undefined);
77
+ const ranked = routes.map((route) => ({
78
+ doc: toDocSummary(route),
79
+ score: scoreDoc(route, query)
80
+ })).filter(({ doc, score }) => {
81
+ const matchesQuery = query ? score > 0 : true;
82
+ const matchesTags = tags.length ? tags.every((tag) => doc.tags.some((docTag) => normalizeText(docTag).includes(tag))) : true;
83
+ const matchesVisibility = visibility ? normalizeText(doc.visibility) === visibility : true;
84
+ const matchesKind = kind ? normalizeText(doc.kind) === kind : true;
85
+ return matchesQuery && matchesTags && matchesVisibility && matchesKind;
86
+ }).sort((left, right) => {
87
+ if (right.score !== left.score)
88
+ return right.score - left.score;
89
+ return left.doc.title.localeCompare(right.doc.title);
90
+ });
91
+ const docs = ranked.slice(offset, offset + limit).map(({ doc }) => doc);
92
+ const nextOffset = offset + docs.length < ranked.length ? offset + docs.length : undefined;
93
+ return {
94
+ docs,
95
+ items: docs,
96
+ total: ranked.length,
97
+ ...nextOffset != null ? { nextOffset } : {}
98
+ };
99
+ }
100
+ function getDocById(id) {
101
+ const normalizedId = decodeURIComponent(id);
102
+ const found = defaultDocRegistry.get(normalizedId);
103
+ if (!found)
104
+ return;
105
+ return {
106
+ doc: toDocSummary(found),
107
+ content: String(found.block.body ?? "")
108
+ };
109
+ }
110
+ function getDocByRoute(routes, routePath) {
111
+ const normalizedPath = normalizeRoute(routePath);
112
+ const found = routes.find((route) => normalizeRoute(route.route) === normalizedPath);
113
+ if (!found)
114
+ return;
115
+ return {
116
+ doc: toDocSummary(found),
117
+ content: String(found.block.body ?? "")
118
+ };
119
+ }
120
+ function listDocFacets(routes) {
121
+ const tags = new Map;
122
+ const kinds = new Map;
123
+ const visibilities = new Map;
124
+ for (const route of routes) {
125
+ const kind = route.block.kind ?? "reference";
126
+ const visibility = route.block.visibility ?? "public";
127
+ kinds.set(kind, (kinds.get(kind) ?? 0) + 1);
128
+ visibilities.set(visibility, (visibilities.get(visibility) ?? 0) + 1);
129
+ for (const tag of route.block.tags ?? []) {
130
+ tags.set(tag, (tags.get(tag) ?? 0) + 1);
131
+ }
132
+ }
133
+ const toEntries = (values, key) => [...values.entries()].sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])).map(([value, count]) => ({ [key]: value, count }));
134
+ return {
135
+ totalDocs: routes.length,
136
+ tags: toEntries(tags, "tag"),
137
+ kinds: toEntries(kinds, "kind"),
138
+ visibilities: toEntries(visibilities, "visibility")
139
+ };
140
+ }
141
+
142
+ // src/features/contracts-registry.ts
143
+ import {
144
+ EventRegistry,
145
+ OperationSpecRegistry
146
+ } from "@contractspec/lib.contracts-spec";
147
+ import {
148
+ DataViewRegistry
149
+ } from "@contractspec/lib.contracts-spec/data-views";
150
+ import {
151
+ ContractReferenceDataView,
152
+ ContractReferenceQuery,
153
+ DocsGenerateCommand,
154
+ DocsGeneratedEvent,
155
+ DocsIndexDataView,
156
+ DocsIndexQuery,
157
+ DocsLayoutPresentation,
158
+ DocsPublishCommand,
159
+ DocsPublishedEvent,
160
+ DocsReferencePagePresentation,
161
+ DocsSearchForm,
162
+ ExampleCatalogDataView
163
+ } from "@contractspec/lib.contracts-spec/docs";
164
+ import { FormRegistry } from "@contractspec/lib.contracts-spec/forms";
165
+ import {
166
+ PresentationRegistry
167
+ } from "@contractspec/lib.contracts-spec/presentations";
168
+ import {
169
+ serializeDataViewSpec,
170
+ serializeEventSpec,
171
+ serializeFormSpec,
172
+ serializeOperationSpec,
173
+ serializePresentationSpec
174
+ } from "@contractspec/lib.contracts-spec/serialization";
175
+ var operationRegistry = null;
176
+ function createContractSpecOperationRegistry() {
177
+ const registry = new OperationSpecRegistry;
178
+ registry.register(DocsIndexQuery).register(ContractReferenceQuery).register(DocsGenerateCommand).register(DocsPublishCommand);
179
+ return registry;
180
+ }
181
+ function getContractSpecOperationRegistry() {
182
+ if (!operationRegistry) {
183
+ operationRegistry = createContractSpecOperationRegistry();
184
+ }
185
+ return operationRegistry;
186
+ }
187
+ function resolveOperationSpec(key, version) {
188
+ return getContractSpecOperationRegistry().get(key, version);
189
+ }
190
+ var eventRegistry = null;
191
+ function createContractSpecEventRegistry() {
192
+ const registry = new EventRegistry;
193
+ registry.register(DocsGeneratedEvent).register(DocsPublishedEvent);
194
+ return registry;
195
+ }
196
+ function getContractSpecEventRegistry() {
197
+ if (!eventRegistry) {
198
+ eventRegistry = createContractSpecEventRegistry();
199
+ }
200
+ return eventRegistry;
201
+ }
202
+ function resolveEventSpec(key, version) {
203
+ return getContractSpecEventRegistry().get(key, version);
204
+ }
205
+ var presentationRegistry = null;
206
+ function createContractSpecPresentationRegistry() {
207
+ const registry = new PresentationRegistry;
208
+ registry.register(DocsLayoutPresentation).register(DocsReferencePagePresentation);
209
+ return registry;
210
+ }
211
+ function getContractSpecPresentationRegistry() {
212
+ if (!presentationRegistry) {
213
+ presentationRegistry = createContractSpecPresentationRegistry();
214
+ }
215
+ return presentationRegistry;
216
+ }
217
+ function resolvePresentationSpec(key, version) {
218
+ return getContractSpecPresentationRegistry().get(key, version);
219
+ }
220
+ var dataViewRegistry = null;
221
+ function createContractSpecDataViewRegistry() {
222
+ const registry = new DataViewRegistry;
223
+ registry.register(DocsIndexDataView).register(ContractReferenceDataView).register(ExampleCatalogDataView);
224
+ return registry;
225
+ }
226
+ function getContractSpecDataViewRegistry() {
227
+ if (!dataViewRegistry) {
228
+ dataViewRegistry = createContractSpecDataViewRegistry();
229
+ }
230
+ return dataViewRegistry;
231
+ }
232
+ function resolveDataViewSpec(key, version) {
233
+ return getContractSpecDataViewRegistry().get(key, version);
234
+ }
235
+ var formRegistry = null;
236
+ function createContractSpecFormRegistry() {
237
+ const registry = new FormRegistry;
238
+ registry.register(DocsSearchForm);
239
+ return registry;
240
+ }
241
+ function getContractSpecFormRegistry() {
242
+ if (!formRegistry) {
243
+ formRegistry = createContractSpecFormRegistry();
244
+ }
245
+ return formRegistry;
246
+ }
247
+ function resolveFormSpec(key, _version) {
248
+ return getContractSpecFormRegistry().get(key);
249
+ }
250
+ function resolveSerializedOperationSpec(key, version) {
251
+ const spec = resolveOperationSpec(key, version);
252
+ return serializeOperationSpec(spec) ?? undefined;
253
+ }
254
+ function resolveSerializedEventSpec(key, version) {
255
+ const spec = resolveEventSpec(key, version);
256
+ return serializeEventSpec(spec) ?? undefined;
257
+ }
258
+ function resolveSerializedPresentationSpec(key, version) {
259
+ const spec = resolvePresentationSpec(key, version);
260
+ return serializePresentationSpec(spec) ?? undefined;
261
+ }
262
+ function resolveSerializedDataViewSpec(key, version) {
263
+ const spec = resolveDataViewSpec(key, version);
264
+ return serializeDataViewSpec(spec) ?? undefined;
265
+ }
266
+ function resolveSerializedFormSpec(key, version) {
267
+ const spec = resolveFormSpec(key, version);
268
+ return serializeFormSpec(spec) ?? undefined;
269
+ }
270
+ function resetContractSpecOperationRegistry() {
271
+ operationRegistry = null;
272
+ }
273
+ function resetContractSpecEventRegistry() {
274
+ eventRegistry = null;
275
+ }
276
+ function resetContractSpecPresentationRegistry() {
277
+ presentationRegistry = null;
278
+ }
279
+ function resetContractSpecDataViewRegistry() {
280
+ dataViewRegistry = null;
281
+ }
282
+ function resetContractSpecFormRegistry() {
283
+ formRegistry = null;
284
+ }
285
+ function resetAllContractSpecRegistries() {
286
+ resetContractSpecOperationRegistry();
287
+ resetContractSpecEventRegistry();
288
+ resetContractSpecPresentationRegistry();
289
+ resetContractSpecDataViewRegistry();
290
+ resetContractSpecFormRegistry();
291
+ }
292
+
293
+ // src/application/mcp/docsMcp.reference.ts
294
+ import { defaultDocRegistry as defaultDocRegistry2 } from "@contractspec/lib.contracts-spec/docs";
295
+ function normalizeText2(value) {
296
+ return value?.trim().toLowerCase() ?? "";
297
+ }
298
+ function routeFromDocIds(docIds) {
299
+ for (const docId of docIds ?? []) {
300
+ const doc = defaultDocRegistry2.get(docId);
301
+ if (doc)
302
+ return doc.route;
303
+ }
304
+ return;
305
+ }
306
+ function toReference(spec, type, schema, policy) {
307
+ const title = spec.meta.title ?? spec.meta.key;
308
+ const route = routeFromDocIds(spec.meta.docId);
309
+ const description = spec.meta.description;
310
+ return {
311
+ key: spec.meta.key,
312
+ version: spec.meta.version,
313
+ type,
314
+ title,
315
+ description,
316
+ markdown: [
317
+ `# ${title}`,
318
+ `- Key: ${spec.meta.key}`,
319
+ `- Type: ${type}`,
320
+ `- Version: ${spec.meta.version}`,
321
+ route ? `- Docs route: ${route}` : "",
322
+ description ? `
323
+ ${description}` : ""
324
+ ].filter(Boolean).join(`
325
+ `),
326
+ ...route ? { route } : {},
327
+ ...schema ? { schema } : {},
328
+ ...policy ? { policy } : {},
329
+ tags: spec.meta.tags ?? [],
330
+ owners: spec.meta.owners ?? [],
331
+ stability: spec.meta.stability
332
+ };
333
+ }
334
+ function resolveContractReference(args) {
335
+ const includeSchema = args.includeSchema ?? false;
336
+ const requestedType = normalizeText2(args.type);
337
+ const operation = resolveOperationSpec(args.key, args.version);
338
+ if (operation && (!requestedType || requestedType === "operation" || requestedType === operation.meta.kind)) {
339
+ return {
340
+ reference: toReference(operation, operation.meta.kind, includeSchema ? resolveSerializedOperationSpec(args.key, args.version) : undefined, operation.policy)
341
+ };
342
+ }
343
+ const resolvers = [
344
+ {
345
+ type: "data-view",
346
+ spec: resolveDataViewSpec(args.key, args.version),
347
+ schema: includeSchema ? resolveSerializedDataViewSpec(args.key, args.version) : undefined
348
+ },
349
+ {
350
+ type: "form",
351
+ spec: resolveFormSpec(args.key, args.version),
352
+ schema: includeSchema ? resolveSerializedFormSpec(args.key, args.version) : undefined
353
+ },
354
+ {
355
+ type: "presentation",
356
+ spec: resolvePresentationSpec(args.key, args.version),
357
+ schema: includeSchema ? resolveSerializedPresentationSpec(args.key, args.version) : undefined
358
+ },
359
+ {
360
+ type: "event",
361
+ spec: resolveEventSpec(args.key, args.version),
362
+ schema: includeSchema ? resolveSerializedEventSpec(args.key, args.version) : undefined
363
+ }
364
+ ];
365
+ for (const candidate of resolvers) {
366
+ if (candidate.spec && (!requestedType || requestedType === candidate.type)) {
367
+ return {
368
+ reference: toReference(candidate.spec, candidate.type, candidate.schema)
369
+ };
370
+ }
371
+ }
372
+ throw new Error(`Contract reference not found: ${args.key}`);
373
+ }
374
+
375
+ // src/application/mcp/docsMcp.resources.ts
376
+ import {
377
+ defineResourceTemplate,
378
+ ResourceRegistry
379
+ } from "@contractspec/lib.contracts-spec";
380
+ import z from "zod";
381
+ var DOC_TAGS = ["docs", "mcp"];
382
+ function buildDocResources(routes) {
383
+ const resources = new ResourceRegistry;
384
+ const readDocIndex = (input) => searchDocs(routes, input);
385
+ resources.register(defineResourceTemplate({
386
+ meta: {
387
+ uriTemplate: "docs://index",
388
+ title: "DocBlocks index",
389
+ description: "Default ContractSpec docs index resource.",
390
+ mimeType: "application/json",
391
+ tags: DOC_TAGS
392
+ },
393
+ input: z.object({}),
394
+ resolve: async () => ({
395
+ uri: "docs://index",
396
+ mimeType: "application/json",
397
+ data: JSON.stringify(readDocIndex({}), null, 2)
398
+ })
399
+ }));
400
+ resources.register(defineResourceTemplate({
401
+ meta: {
402
+ uriTemplate: "docs://index{?query,tag,kind,visibility,limit,offset}",
403
+ title: "DocBlocks index",
404
+ description: "Search and paginate ContractSpec docs by query, tag, kind, or visibility.",
405
+ mimeType: "application/json",
406
+ tags: DOC_TAGS
407
+ },
408
+ input: z.object({
409
+ query: z.string().optional(),
410
+ tag: z.string().optional(),
411
+ kind: z.string().optional(),
412
+ visibility: z.string().optional(),
413
+ limit: z.coerce.number().optional(),
414
+ offset: z.coerce.number().optional()
415
+ }),
416
+ resolve: async (input) => ({
417
+ uri: "docs://index",
418
+ mimeType: "application/json",
419
+ data: JSON.stringify(readDocIndex(input), null, 2)
420
+ })
421
+ }));
422
+ resources.register(defineResourceTemplate({
423
+ meta: {
424
+ uriTemplate: "docs://list",
425
+ title: "DocBlocks index (legacy alias)",
426
+ description: "Compatibility alias for the docs index resource.",
427
+ mimeType: "application/json",
428
+ tags: DOC_TAGS
429
+ },
430
+ input: z.object({}),
431
+ resolve: async () => ({
432
+ uri: "docs://list",
433
+ mimeType: "application/json",
434
+ data: JSON.stringify(readDocIndex({}), null, 2)
435
+ })
436
+ }));
437
+ resources.register(defineResourceTemplate({
438
+ meta: {
439
+ uriTemplate: "docs://doc/{id}",
440
+ title: "Doc markdown",
441
+ description: "Fetch a single DocBlock body by id as markdown.",
442
+ mimeType: "text/markdown",
443
+ tags: DOC_TAGS
444
+ },
445
+ input: z.object({ id: z.string() }),
446
+ resolve: async ({ id }) => {
447
+ const found = getDocById(id);
448
+ if (!found) {
449
+ return {
450
+ uri: `docs://doc/${encodeURIComponent(id)}`,
451
+ mimeType: "text/plain",
452
+ data: `DocBlock not found: ${id}`
453
+ };
454
+ }
455
+ return {
456
+ uri: `docs://doc/${encodeURIComponent(id)}`,
457
+ mimeType: "text/markdown",
458
+ data: found.content
459
+ };
460
+ }
461
+ }));
462
+ resources.register(defineResourceTemplate({
463
+ meta: {
464
+ uriTemplate: "docs://route/{routePath}",
465
+ title: "Doc by route",
466
+ description: "Resolve a docs route to the matching DocBlock summary and body.",
467
+ mimeType: "application/json",
468
+ tags: DOC_TAGS
469
+ },
470
+ input: z.object({ routePath: z.string() }),
471
+ resolve: async ({ routePath }) => ({
472
+ uri: `docs://route/${encodeURIComponent(routePath)}`,
473
+ mimeType: "application/json",
474
+ data: JSON.stringify(getDocByRoute(routes, routePath) ?? {
475
+ error: "not_found",
476
+ route: routePath
477
+ }, null, 2)
478
+ })
479
+ }));
480
+ resources.register(defineResourceTemplate({
481
+ meta: {
482
+ uriTemplate: "docs://facets",
483
+ title: "Docs facets",
484
+ description: "Counts of available tags, kinds, and visibilities across docs.",
485
+ mimeType: "application/json",
486
+ tags: DOC_TAGS
487
+ },
488
+ input: z.object({}),
489
+ resolve: async () => ({
490
+ uri: "docs://facets",
491
+ mimeType: "application/json",
492
+ data: JSON.stringify(listDocFacets(routes), null, 2)
493
+ })
494
+ }));
495
+ resources.register(defineResourceTemplate({
496
+ meta: {
497
+ uriTemplate: "docs://contract-reference/{key}{?version,type,includeSchema}",
498
+ title: "Contract reference",
499
+ description: "Resolve a ContractSpec surface into a docs-ready reference payload.",
500
+ mimeType: "application/json",
501
+ tags: DOC_TAGS
502
+ },
503
+ input: z.object({
504
+ key: z.string(),
505
+ version: z.string().optional(),
506
+ type: z.string().optional(),
507
+ includeSchema: z.coerce.boolean().optional()
508
+ }),
509
+ resolve: async ({ key, version, type, includeSchema }) => ({
510
+ uri: `docs://contract-reference/${encodeURIComponent(key)}`,
511
+ mimeType: "application/json",
512
+ data: JSON.stringify(resolveContractReference({ key, version, type, includeSchema }), null, 2)
513
+ })
514
+ }));
515
+ return resources;
516
+ }
517
+ export {
518
+ buildDocResources
519
+ };