@contractspec/bundle.library 3.0.0 → 3.1.1

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 (50) hide show
  1. package/.turbo/turbo-build.log +178 -166
  2. package/AGENTS.md +19 -12
  3. package/CHANGELOG.md +46 -0
  4. package/dist/application/context-storage/index.d.ts +18 -0
  5. package/dist/application/context-storage/index.js +29 -0
  6. package/dist/application/index.d.ts +1 -0
  7. package/dist/application/index.js +662 -2
  8. package/dist/application/mcp/cliMcp.js +12 -2
  9. package/dist/application/mcp/common.d.ts +11 -1
  10. package/dist/application/mcp/common.js +12 -2
  11. package/dist/application/mcp/contractsMcp.d.ts +51 -0
  12. package/dist/application/mcp/contractsMcp.js +531 -0
  13. package/dist/application/mcp/contractsMcpResources.d.ts +7 -0
  14. package/dist/application/mcp/contractsMcpResources.js +124 -0
  15. package/dist/application/mcp/contractsMcpTools.d.ts +9 -0
  16. package/dist/application/mcp/contractsMcpTools.js +200 -0
  17. package/dist/application/mcp/contractsMcpTypes.d.ts +50 -0
  18. package/dist/application/mcp/contractsMcpTypes.js +1 -0
  19. package/dist/application/mcp/docsMcp.js +12 -2
  20. package/dist/application/mcp/index.d.ts +2 -0
  21. package/dist/application/mcp/index.js +635 -2
  22. package/dist/application/mcp/internalMcp.js +12 -2
  23. package/dist/application/mcp/providerRankingMcp.d.ts +46 -0
  24. package/dist/application/mcp/providerRankingMcp.js +494 -0
  25. package/dist/node/application/context-storage/index.js +28 -0
  26. package/dist/node/application/index.js +662 -2
  27. package/dist/node/application/mcp/cliMcp.js +12 -2
  28. package/dist/node/application/mcp/common.js +12 -2
  29. package/dist/node/application/mcp/contractsMcp.js +530 -0
  30. package/dist/node/application/mcp/contractsMcpResources.js +123 -0
  31. package/dist/node/application/mcp/contractsMcpTools.js +199 -0
  32. package/dist/node/application/mcp/contractsMcpTypes.js +0 -0
  33. package/dist/node/application/mcp/docsMcp.js +12 -2
  34. package/dist/node/application/mcp/index.js +635 -2
  35. package/dist/node/application/mcp/internalMcp.js +12 -2
  36. package/dist/node/application/mcp/providerRankingMcp.js +493 -0
  37. package/package.json +111 -25
  38. package/src/application/context-storage/index.ts +58 -0
  39. package/src/application/index.ts +1 -0
  40. package/src/application/mcp/common.ts +28 -1
  41. package/src/application/mcp/contractsMcp.ts +34 -0
  42. package/src/application/mcp/contractsMcpResources.ts +142 -0
  43. package/src/application/mcp/contractsMcpTools.ts +246 -0
  44. package/src/application/mcp/contractsMcpTypes.ts +47 -0
  45. package/src/application/mcp/index.ts +2 -0
  46. package/src/application/mcp/providerRankingMcp.ts +380 -0
  47. package/src/components/docs/generated/docs-index._common.json +879 -1
  48. package/src/components/docs/generated/docs-index.manifest.json +5 -5
  49. package/src/components/docs/generated/docs-index.metrics.json +8 -0
  50. package/src/components/docs/generated/docs-index.platform-integrations.json +8 -0
@@ -0,0 +1,124 @@
1
+ // @bun
2
+ // src/application/mcp/contractsMcpResources.ts
3
+ import {
4
+ definePrompt,
5
+ defineResourceTemplate,
6
+ PromptRegistry,
7
+ ResourceRegistry
8
+ } from "@contractspec/lib.contracts-spec";
9
+ import z from "zod";
10
+ var OWNERS = ["@contractspec"];
11
+ var TAGS = ["contracts", "mcp"];
12
+ function buildContractsResources(services) {
13
+ const resources = new ResourceRegistry;
14
+ resources.register(defineResourceTemplate({
15
+ meta: {
16
+ uriTemplate: "contracts://list",
17
+ title: "Contract specs list",
18
+ description: "JSON list of all contract specs in the workspace.",
19
+ mimeType: "application/json",
20
+ tags: TAGS
21
+ },
22
+ input: z.object({}),
23
+ resolve: async () => {
24
+ const specs = await services.listSpecs();
25
+ return {
26
+ uri: "contracts://list",
27
+ mimeType: "application/json",
28
+ data: JSON.stringify(specs, null, 2)
29
+ };
30
+ }
31
+ }));
32
+ resources.register(defineResourceTemplate({
33
+ meta: {
34
+ uriTemplate: "contracts://spec/{path}",
35
+ title: "Contract spec content",
36
+ description: "Read a single contract spec file by path.",
37
+ mimeType: "text/plain",
38
+ tags: TAGS
39
+ },
40
+ input: z.object({ path: z.string() }),
41
+ resolve: async ({ path }) => {
42
+ const result = await services.getSpec(path);
43
+ if (!result) {
44
+ return {
45
+ uri: `contracts://spec/${encodeURIComponent(path)}`,
46
+ mimeType: "text/plain",
47
+ data: `Spec not found: ${path}`
48
+ };
49
+ }
50
+ return {
51
+ uri: `contracts://spec/${encodeURIComponent(path)}`,
52
+ mimeType: "text/plain",
53
+ data: result.content
54
+ };
55
+ }
56
+ }));
57
+ resources.register(defineResourceTemplate({
58
+ meta: {
59
+ uriTemplate: "contracts://registry/manifest",
60
+ title: "Remote registry manifest",
61
+ description: "Contract registry manifest from the remote server.",
62
+ mimeType: "application/json",
63
+ tags: TAGS
64
+ },
65
+ input: z.object({}),
66
+ resolve: async () => {
67
+ const manifest = await services.fetchRegistryManifest();
68
+ return {
69
+ uri: "contracts://registry/manifest",
70
+ mimeType: "application/json",
71
+ data: JSON.stringify(manifest, null, 2)
72
+ };
73
+ }
74
+ }));
75
+ return resources;
76
+ }
77
+ function buildContractsPrompts() {
78
+ const prompts = new PromptRegistry;
79
+ prompts.register(definePrompt({
80
+ meta: {
81
+ key: "contracts.editor",
82
+ version: "1.0.0",
83
+ title: "Contract editing guide",
84
+ description: "Guide AI agents through reading, editing, and validating contracts.",
85
+ tags: TAGS,
86
+ stability: "beta",
87
+ owners: OWNERS
88
+ },
89
+ args: [
90
+ {
91
+ name: "goal",
92
+ description: "What the agent wants to achieve with the contract.",
93
+ required: false,
94
+ schema: z.string().optional()
95
+ }
96
+ ],
97
+ input: z.object({ goal: z.string().optional() }),
98
+ render: async ({ goal }) => [
99
+ {
100
+ type: "text",
101
+ text: [
102
+ "Contract editing workflow:",
103
+ "1. Use contracts.list to discover specs",
104
+ "2. Use contracts.get to read a spec",
105
+ "3. Edit content and call contracts.update",
106
+ "4. Run contracts.validate to verify changes",
107
+ "5. Run contracts.build to regenerate artifacts",
108
+ goal ? `Agent goal: ${goal}` : ""
109
+ ].filter(Boolean).join(`
110
+ `)
111
+ },
112
+ {
113
+ type: "resource",
114
+ uri: "contracts://list",
115
+ title: "Available contracts"
116
+ }
117
+ ]
118
+ }));
119
+ return prompts;
120
+ }
121
+ export {
122
+ buildContractsResources,
123
+ buildContractsPrompts
124
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Contract management MCP tool definitions.
3
+ *
4
+ * Each tool delegates to an injected service so the bundle stays
5
+ * decoupled from bundle.workspace (apps layer does the wiring).
6
+ */
7
+ import { OperationSpecRegistry } from '@contractspec/lib.contracts-spec';
8
+ import type { ContractsMcpServices } from './contractsMcpTypes';
9
+ export declare function buildContractsOps(services: ContractsMcpServices): OperationSpecRegistry;
@@ -0,0 +1,200 @@
1
+ // @bun
2
+ // src/application/mcp/contractsMcpTools.ts
3
+ import {
4
+ defineCommand,
5
+ installOp,
6
+ OperationSpecRegistry
7
+ } from "@contractspec/lib.contracts-spec";
8
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
9
+ var OWNERS = ["@contractspec"];
10
+ var TAGS = ["contracts", "mcp"];
11
+ function buildContractsOps(services) {
12
+ const registry = new OperationSpecRegistry;
13
+ const ListInput = defineSchemaModel({
14
+ name: "ContractsListInput",
15
+ fields: {
16
+ pattern: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
17
+ type: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
18
+ }
19
+ });
20
+ const ListOutput = defineSchemaModel({
21
+ name: "ContractsListOutput",
22
+ fields: {
23
+ specs: { type: ScalarTypeEnum.JSON(), isOptional: false },
24
+ total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
25
+ }
26
+ });
27
+ installOp(registry, defineCommand({
28
+ meta: {
29
+ key: "contracts.list",
30
+ version: "1.0.0",
31
+ stability: "beta",
32
+ owners: OWNERS,
33
+ tags: TAGS,
34
+ description: "List contract specs in the workspace.",
35
+ goal: "Discover available contracts by type, pattern, or owner.",
36
+ context: "Contracts MCP server."
37
+ },
38
+ io: { input: ListInput, output: ListOutput },
39
+ policy: { auth: "anonymous" }
40
+ }), async ({ pattern, type }) => {
41
+ const specs = await services.listSpecs({ pattern, type });
42
+ return { specs, total: specs.length };
43
+ });
44
+ const GetInput = defineSchemaModel({
45
+ name: "ContractsGetInput",
46
+ fields: {
47
+ path: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
48
+ }
49
+ });
50
+ const GetOutput = defineSchemaModel({
51
+ name: "ContractsGetOutput",
52
+ fields: {
53
+ content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
54
+ info: { type: ScalarTypeEnum.JSON(), isOptional: false }
55
+ }
56
+ });
57
+ installOp(registry, defineCommand({
58
+ meta: {
59
+ key: "contracts.get",
60
+ version: "1.0.0",
61
+ stability: "beta",
62
+ owners: OWNERS,
63
+ tags: TAGS,
64
+ description: "Read a single contract spec file.",
65
+ goal: "Fetch spec content and parsed metadata.",
66
+ context: "Contracts MCP server."
67
+ },
68
+ io: { input: GetInput, output: GetOutput },
69
+ policy: { auth: "anonymous" }
70
+ }), async ({ path }) => {
71
+ const result = await services.getSpec(path);
72
+ if (!result)
73
+ throw new Error(`Spec not found: ${path}`);
74
+ return result;
75
+ });
76
+ const ValidateInput = defineSchemaModel({
77
+ name: "ContractsValidateInput",
78
+ fields: {
79
+ path: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
80
+ }
81
+ });
82
+ const ValidateOutput = defineSchemaModel({
83
+ name: "ContractsValidateOutput",
84
+ fields: {
85
+ valid: { type: ScalarTypeEnum.Boolean(), isOptional: false },
86
+ errors: { type: ScalarTypeEnum.JSON(), isOptional: false },
87
+ warnings: { type: ScalarTypeEnum.JSON(), isOptional: false }
88
+ }
89
+ });
90
+ installOp(registry, defineCommand({
91
+ meta: {
92
+ key: "contracts.validate",
93
+ version: "1.0.0",
94
+ stability: "beta",
95
+ owners: OWNERS,
96
+ tags: TAGS,
97
+ description: "Validate a contract spec structure.",
98
+ goal: "Check spec for structural or policy issues.",
99
+ context: "Contracts MCP server."
100
+ },
101
+ io: { input: ValidateInput, output: ValidateOutput },
102
+ policy: { auth: "anonymous" }
103
+ }), async ({ path }) => services.validateSpec(path));
104
+ const BuildInput = defineSchemaModel({
105
+ name: "ContractsBuildInput",
106
+ fields: {
107
+ path: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
108
+ dryRun: { type: ScalarTypeEnum.Boolean(), isOptional: true }
109
+ }
110
+ });
111
+ const BuildOutput = defineSchemaModel({
112
+ name: "ContractsBuildOutput",
113
+ fields: {
114
+ results: { type: ScalarTypeEnum.JSON(), isOptional: false }
115
+ }
116
+ });
117
+ installOp(registry, defineCommand({
118
+ meta: {
119
+ key: "contracts.build",
120
+ version: "1.0.0",
121
+ stability: "beta",
122
+ owners: OWNERS,
123
+ tags: TAGS,
124
+ description: "Generate implementation code from a contract spec.",
125
+ goal: "Produce handler, component, or test skeletons.",
126
+ context: "Contracts MCP server."
127
+ },
128
+ io: { input: BuildInput, output: BuildOutput },
129
+ policy: { auth: "user" }
130
+ }), async ({ path, dryRun }) => services.buildSpec(path, { dryRun }));
131
+ registerMutationTools(registry, services);
132
+ return registry;
133
+ }
134
+ function registerMutationTools(registry, services) {
135
+ const UpdateInput = defineSchemaModel({
136
+ name: "ContractsUpdateInput",
137
+ fields: {
138
+ path: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
139
+ content: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
140
+ fields: { type: ScalarTypeEnum.JSON(), isOptional: true }
141
+ }
142
+ });
143
+ const UpdateOutput = defineSchemaModel({
144
+ name: "ContractsUpdateOutput",
145
+ fields: {
146
+ updated: { type: ScalarTypeEnum.Boolean(), isOptional: false },
147
+ errors: { type: ScalarTypeEnum.JSON(), isOptional: false },
148
+ warnings: { type: ScalarTypeEnum.JSON(), isOptional: false }
149
+ }
150
+ });
151
+ installOp(registry, defineCommand({
152
+ meta: {
153
+ key: "contracts.update",
154
+ version: "1.0.0",
155
+ stability: "beta",
156
+ owners: OWNERS,
157
+ tags: TAGS,
158
+ description: "Update an existing contract spec.",
159
+ goal: "Modify spec content or individual fields with validation.",
160
+ context: "Contracts MCP server."
161
+ },
162
+ io: { input: UpdateInput, output: UpdateOutput },
163
+ policy: { auth: "user" }
164
+ }), async ({ path, content, fields }) => services.updateSpec(path, {
165
+ content,
166
+ fields: Array.isArray(fields) ? fields : undefined
167
+ }));
168
+ const DeleteInput = defineSchemaModel({
169
+ name: "ContractsDeleteInput",
170
+ fields: {
171
+ path: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
172
+ clean: { type: ScalarTypeEnum.Boolean(), isOptional: true }
173
+ }
174
+ });
175
+ const DeleteOutput = defineSchemaModel({
176
+ name: "ContractsDeleteOutput",
177
+ fields: {
178
+ deleted: { type: ScalarTypeEnum.Boolean(), isOptional: false },
179
+ cleanedFiles: { type: ScalarTypeEnum.JSON(), isOptional: false },
180
+ errors: { type: ScalarTypeEnum.JSON(), isOptional: false }
181
+ }
182
+ });
183
+ installOp(registry, defineCommand({
184
+ meta: {
185
+ key: "contracts.delete",
186
+ version: "1.0.0",
187
+ stability: "beta",
188
+ owners: OWNERS,
189
+ tags: TAGS,
190
+ description: "Delete a contract spec and optionally its artifacts.",
191
+ goal: "Remove a spec file and clean generated handlers/tests.",
192
+ context: "Contracts MCP server."
193
+ },
194
+ io: { input: DeleteInput, output: DeleteOutput },
195
+ policy: { auth: "user" }
196
+ }), async ({ path, clean }) => services.deleteSpec(path, { clean }));
197
+ }
198
+ export {
199
+ buildContractsOps
200
+ };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Contracts MCP service interface.
3
+ *
4
+ * Defines the dependency-injection boundary so `bundle.library` stays
5
+ * decoupled from `bundle.workspace`. The app layer wires real impls.
6
+ */
7
+ export interface ContractInfo {
8
+ specType: string;
9
+ filePath: string;
10
+ key?: string;
11
+ version?: string;
12
+ kind?: string;
13
+ description?: string;
14
+ }
15
+ export interface ContractsMcpServices {
16
+ listSpecs(options?: {
17
+ pattern?: string;
18
+ type?: string;
19
+ }): Promise<ContractInfo[]>;
20
+ getSpec(path: string): Promise<{
21
+ content: string;
22
+ info: ContractInfo;
23
+ } | null>;
24
+ validateSpec(path: string): Promise<{
25
+ valid: boolean;
26
+ errors: string[];
27
+ warnings: string[];
28
+ }>;
29
+ buildSpec(path: string, options?: {
30
+ dryRun?: boolean;
31
+ }): Promise<{
32
+ results: unknown[];
33
+ }>;
34
+ updateSpec(path: string, options: {
35
+ content?: string;
36
+ fields?: unknown[];
37
+ }): Promise<{
38
+ updated: boolean;
39
+ errors: string[];
40
+ warnings: string[];
41
+ }>;
42
+ deleteSpec(path: string, options?: {
43
+ clean?: boolean;
44
+ }): Promise<{
45
+ deleted: boolean;
46
+ cleanedFiles: string[];
47
+ errors: string[];
48
+ }>;
49
+ fetchRegistryManifest(): Promise<unknown>;
50
+ }
@@ -0,0 +1 @@
1
+ // @bun
@@ -73,9 +73,13 @@ function createMcpElysiaHandler({
73
73
  ops,
74
74
  resources,
75
75
  prompts,
76
- presentations
76
+ presentations,
77
+ validateAuth,
78
+ requiredAuthMethods
77
79
  }) {
78
- logger.info("Setting up MCP handler...");
80
+ logger.info("Setting up MCP handler...", {
81
+ requiredAuthMethods: requiredAuthMethods ?? []
82
+ });
79
83
  const isStateful = process.env.CONTRACTSPEC_MCP_STATEFUL === "1";
80
84
  const sessions = new Map;
81
85
  async function handleStateless(request) {
@@ -146,6 +150,12 @@ function createMcpElysiaHandler({
146
150
  }
147
151
  return new Elysia({ name: `mcp-${serverName}` }).all(path, async ({ request }) => {
148
152
  try {
153
+ if (validateAuth) {
154
+ const authResult = await validateAuth(request);
155
+ if (!authResult.valid) {
156
+ return createJsonRpcErrorResponse(401, -32002, "Authentication failed", authResult.reason);
157
+ }
158
+ }
149
159
  if (isStateful) {
150
160
  return await handleStateful(request);
151
161
  }
@@ -1,3 +1,5 @@
1
1
  export * from './docsMcp';
2
2
  export * from './cliMcp';
3
3
  export * from './internalMcp';
4
+ export * from './providerRankingMcp';
5
+ export * from './contractsMcp';