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