@mcp-web/core 0.1.0

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 (102) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +253 -0
  3. package/dist/addTool.typetest.d.ts +11 -0
  4. package/dist/addTool.typetest.d.ts.map +1 -0
  5. package/dist/addTool.typetest.js +248 -0
  6. package/dist/create-state-tools.d.ts +77 -0
  7. package/dist/create-state-tools.d.ts.map +1 -0
  8. package/dist/create-state-tools.js +181 -0
  9. package/dist/create-tool.d.ts +90 -0
  10. package/dist/create-tool.d.ts.map +1 -0
  11. package/dist/create-tool.js +82 -0
  12. package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts +8 -0
  13. package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts.map +1 -0
  14. package/dist/expanded-schema-tools/generate-fixed-shape-tools.js +53 -0
  15. package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts +2 -0
  16. package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts.map +1 -0
  17. package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.js +331 -0
  18. package/dist/expanded-schema-tools/index.d.ts +4 -0
  19. package/dist/expanded-schema-tools/index.d.ts.map +1 -0
  20. package/dist/expanded-schema-tools/index.js +2 -0
  21. package/dist/expanded-schema-tools/integration.test.d.ts +2 -0
  22. package/dist/expanded-schema-tools/integration.test.d.ts.map +1 -0
  23. package/dist/expanded-schema-tools/integration.test.js +599 -0
  24. package/dist/expanded-schema-tools/schema-analysis.d.ts +18 -0
  25. package/dist/expanded-schema-tools/schema-analysis.d.ts.map +1 -0
  26. package/dist/expanded-schema-tools/schema-analysis.js +142 -0
  27. package/dist/expanded-schema-tools/schema-analysis.test.d.ts +2 -0
  28. package/dist/expanded-schema-tools/schema-analysis.test.d.ts.map +1 -0
  29. package/dist/expanded-schema-tools/schema-analysis.test.js +314 -0
  30. package/dist/expanded-schema-tools/schema-helpers.d.ts +69 -0
  31. package/dist/expanded-schema-tools/schema-helpers.d.ts.map +1 -0
  32. package/dist/expanded-schema-tools/schema-helpers.js +139 -0
  33. package/dist/expanded-schema-tools/schema-helpers.test.d.ts +2 -0
  34. package/dist/expanded-schema-tools/schema-helpers.test.d.ts.map +1 -0
  35. package/dist/expanded-schema-tools/schema-helpers.test.js +223 -0
  36. package/dist/expanded-schema-tools/tool-generator.d.ts +10 -0
  37. package/dist/expanded-schema-tools/tool-generator.d.ts.map +1 -0
  38. package/dist/expanded-schema-tools/tool-generator.js +430 -0
  39. package/dist/expanded-schema-tools/tool-generator.test.d.ts +2 -0
  40. package/dist/expanded-schema-tools/tool-generator.test.d.ts.map +1 -0
  41. package/dist/expanded-schema-tools/tool-generator.test.js +689 -0
  42. package/dist/expanded-schema-tools/types.d.ts +26 -0
  43. package/dist/expanded-schema-tools/types.d.ts.map +1 -0
  44. package/dist/expanded-schema-tools/types.js +1 -0
  45. package/dist/expanded-schema-tools/utils.d.ts +16 -0
  46. package/dist/expanded-schema-tools/utils.d.ts.map +1 -0
  47. package/dist/expanded-schema-tools/utils.js +35 -0
  48. package/dist/expanded-schema-tools/utils.test.d.ts +2 -0
  49. package/dist/expanded-schema-tools/utils.test.d.ts.map +1 -0
  50. package/dist/expanded-schema-tools/utils.test.js +169 -0
  51. package/dist/group-state.d.ts +60 -0
  52. package/dist/group-state.d.ts.map +1 -0
  53. package/dist/group-state.js +54 -0
  54. package/dist/index.d.ts +14 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +13 -0
  57. package/dist/query.d.ts +104 -0
  58. package/dist/query.d.ts.map +1 -0
  59. package/dist/query.js +128 -0
  60. package/dist/schema-helpers.d.ts +69 -0
  61. package/dist/schema-helpers.d.ts.map +1 -0
  62. package/dist/schema-helpers.js +139 -0
  63. package/dist/schemas.d.ts +140 -0
  64. package/dist/schemas.d.ts.map +1 -0
  65. package/dist/schemas.js +70 -0
  66. package/dist/tool-generators/generate-basic-state-tools.d.ts +23 -0
  67. package/dist/tool-generators/generate-basic-state-tools.d.ts.map +1 -0
  68. package/dist/tool-generators/generate-basic-state-tools.js +95 -0
  69. package/dist/tool-generators/generate-fixed-shape-tools.d.ts +8 -0
  70. package/dist/tool-generators/generate-fixed-shape-tools.d.ts.map +1 -0
  71. package/dist/tool-generators/generate-fixed-shape-tools.js +53 -0
  72. package/dist/tool-generators/index.d.ts +6 -0
  73. package/dist/tool-generators/index.d.ts.map +1 -0
  74. package/dist/tool-generators/index.js +3 -0
  75. package/dist/tool-generators/schema-analysis.d.ts +18 -0
  76. package/dist/tool-generators/schema-analysis.d.ts.map +1 -0
  77. package/dist/tool-generators/schema-analysis.js +142 -0
  78. package/dist/tool-generators/schema-helpers.d.ts +87 -0
  79. package/dist/tool-generators/schema-helpers.d.ts.map +1 -0
  80. package/dist/tool-generators/schema-helpers.js +157 -0
  81. package/dist/tool-generators/tool-generator.d.ts +11 -0
  82. package/dist/tool-generators/tool-generator.d.ts.map +1 -0
  83. package/dist/tool-generators/tool-generator.js +437 -0
  84. package/dist/tool-generators/types.d.ts +26 -0
  85. package/dist/tool-generators/types.d.ts.map +1 -0
  86. package/dist/tool-generators/types.js +1 -0
  87. package/dist/tool-generators/utils.d.ts +16 -0
  88. package/dist/tool-generators/utils.d.ts.map +1 -0
  89. package/dist/tool-generators/utils.js +35 -0
  90. package/dist/types.d.ts +17 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +1 -0
  93. package/dist/utils.d.ts +31 -0
  94. package/dist/utils.d.ts.map +1 -0
  95. package/dist/utils.js +108 -0
  96. package/dist/web.d.ts +680 -0
  97. package/dist/web.d.ts.map +1 -0
  98. package/dist/web.js +1312 -0
  99. package/dist/zod-to-tools.d.ts +49 -0
  100. package/dist/zod-to-tools.d.ts.map +1 -0
  101. package/dist/zod-to-tools.js +623 -0
  102. package/package.json +58 -0
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Marks a field as the unique identifier for array elements.
4
+ * Enables ID-based tools instead of index-based.
5
+ * Only one field per schema can be marked with id().
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const TodoSchema = z.object({
10
+ * id: id(z.string()),
11
+ * value: z.string()
12
+ * });
13
+ * ```
14
+ */
15
+ export declare function id<T extends z.ZodTypeAny>(schema: T): T;
16
+ /**
17
+ * Marks a field as system-generated.
18
+ * Field is excluded from input schemas (add/set).
19
+ * MUST have a default() — error thrown otherwise.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const TodoSchema = z.object({
24
+ * id: id(system(z.string().default(() => crypto.randomUUID()))),
25
+ * created_at: system(z.number().default(() => Date.now()))
26
+ * });
27
+ * ```
28
+ */
29
+ export declare function system<T extends z.ZodTypeAny>(schema: T): T;
30
+ /**
31
+ * Checks if a field is marked with id().
32
+ */
33
+ export declare function isKeyField(field: z.ZodTypeAny): boolean;
34
+ /**
35
+ * Checks if a field is marked with system().
36
+ */
37
+ export declare function isSystemField(field: z.ZodTypeAny): boolean;
38
+ /**
39
+ * Checks if a schema has a default value.
40
+ */
41
+ export declare function hasDefault(schema: z.ZodTypeAny): boolean;
42
+ /**
43
+ * Unwraps a schema from ZodDefault, ZodOptional, ZodNullable wrappers.
44
+ * Returns the innermost schema.
45
+ */
46
+ export declare function unwrapSchema(schema: z.ZodTypeAny): z.ZodTypeAny;
47
+ /**
48
+ * Unwraps ZodDefault to get the inner schema.
49
+ */
50
+ export declare function unwrapDefault(schema: z.ZodTypeAny): z.ZodTypeAny;
51
+ /**
52
+ * Derives an input schema for add operations.
53
+ * - system() fields are excluded
54
+ * - default() fields become optional
55
+ * - other fields remain required
56
+ */
57
+ export declare function deriveAddInputSchema(schema: z.ZodObject<z.ZodRawShape>): z.ZodObject<z.ZodRawShape>;
58
+ /**
59
+ * Derives an input schema for set operations (partial updates).
60
+ * - system() fields are excluded
61
+ * - all other fields become optional
62
+ */
63
+ export declare function deriveSetInputSchema(schema: z.ZodObject<z.ZodRawShape>): z.ZodObject<z.ZodRawShape>;
64
+ /**
65
+ * Validates that all system() fields have default values.
66
+ * Throws an error if a system field lacks a default.
67
+ */
68
+ export declare function validateSystemFields(schema: z.ZodObject<z.ZodRawShape>): void;
69
+ //# sourceMappingURL=schema-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-helpers.d.ts","sourceRoot":"","sources":["../src/schema-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;GAYG;AACH,wBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAGvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAG3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CAE1D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CASxD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAa/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAMhE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAiBnG;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAanG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,IAAI,CAa7E"}
@@ -0,0 +1,139 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Marks a field as the unique identifier for array elements.
4
+ * Enables ID-based tools instead of index-based.
5
+ * Only one field per schema can be marked with id().
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const TodoSchema = z.object({
10
+ * id: id(z.string()),
11
+ * value: z.string()
12
+ * });
13
+ * ```
14
+ */
15
+ export function id(schema) {
16
+ schema._def.__mcpWebKey = true;
17
+ return schema;
18
+ }
19
+ /**
20
+ * Marks a field as system-generated.
21
+ * Field is excluded from input schemas (add/set).
22
+ * MUST have a default() — error thrown otherwise.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const TodoSchema = z.object({
27
+ * id: id(system(z.string().default(() => crypto.randomUUID()))),
28
+ * created_at: system(z.number().default(() => Date.now()))
29
+ * });
30
+ * ```
31
+ */
32
+ export function system(schema) {
33
+ schema._def.__mcpWebSystem = true;
34
+ return schema;
35
+ }
36
+ /**
37
+ * Checks if a field is marked with id().
38
+ */
39
+ export function isKeyField(field) {
40
+ return field._def.__mcpWebKey === true;
41
+ }
42
+ /**
43
+ * Checks if a field is marked with system().
44
+ */
45
+ export function isSystemField(field) {
46
+ return field._def.__mcpWebSystem === true;
47
+ }
48
+ /**
49
+ * Checks if a schema has a default value.
50
+ */
51
+ export function hasDefault(schema) {
52
+ // Check for ZodDefault wrapper
53
+ if (schema instanceof z.ZodDefault) {
54
+ return true;
55
+ }
56
+ // Check _def for default value
57
+ const def = schema._def;
58
+ return def.defaultValue !== undefined || typeof def.defaultValue === 'function';
59
+ }
60
+ /**
61
+ * Unwraps a schema from ZodDefault, ZodOptional, ZodNullable wrappers.
62
+ * Returns the innermost schema.
63
+ */
64
+ export function unwrapSchema(schema) {
65
+ let current = schema;
66
+ while (current instanceof z.ZodDefault ||
67
+ current instanceof z.ZodOptional ||
68
+ current instanceof z.ZodNullable) {
69
+ const def = current._def;
70
+ current = def.innerType || current;
71
+ }
72
+ return current;
73
+ }
74
+ /**
75
+ * Unwraps ZodDefault to get the inner schema.
76
+ */
77
+ export function unwrapDefault(schema) {
78
+ if (schema instanceof z.ZodDefault) {
79
+ const def = schema._def;
80
+ return def.innerType;
81
+ }
82
+ return schema;
83
+ }
84
+ /**
85
+ * Derives an input schema for add operations.
86
+ * - system() fields are excluded
87
+ * - default() fields become optional
88
+ * - other fields remain required
89
+ */
90
+ export function deriveAddInputSchema(schema) {
91
+ const inputShape = {};
92
+ for (const [key, field] of Object.entries(schema.shape)) {
93
+ const zodField = field;
94
+ // Skip system fields entirely
95
+ if (isSystemField(zodField))
96
+ continue;
97
+ // Fields with default() become optional in add
98
+ if (hasDefault(zodField)) {
99
+ inputShape[key] = unwrapDefault(zodField).optional();
100
+ }
101
+ else {
102
+ inputShape[key] = zodField;
103
+ }
104
+ }
105
+ return z.object(inputShape);
106
+ }
107
+ /**
108
+ * Derives an input schema for set operations (partial updates).
109
+ * - system() fields are excluded
110
+ * - all other fields become optional
111
+ */
112
+ export function deriveSetInputSchema(schema) {
113
+ const inputShape = {};
114
+ for (const [key, field] of Object.entries(schema.shape)) {
115
+ const zodField = field;
116
+ // Skip system fields entirely
117
+ if (isSystemField(zodField))
118
+ continue;
119
+ // All fields optional for partial updates
120
+ inputShape[key] = unwrapDefault(zodField).optional();
121
+ }
122
+ return z.object(inputShape);
123
+ }
124
+ /**
125
+ * Validates that all system() fields have default values.
126
+ * Throws an error if a system field lacks a default.
127
+ */
128
+ export function validateSystemFields(schema) {
129
+ for (const [key, field] of Object.entries(schema.shape)) {
130
+ const zodField = field;
131
+ if (isSystemField(zodField) && !hasDefault(zodField)) {
132
+ throw new Error(`Error: Field '${key}' is marked as system() but has no default value.\n\n` +
133
+ `System fields are excluded from input schemas, so a default is required.\n` +
134
+ `The handler uses this default to fill in the value when creating new items.\n\n` +
135
+ `Fix: Add a default value or generator:\n` +
136
+ ` ${key}: system(z.number().default(() => Date.now()))`);
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,140 @@
1
+ import { z } from 'zod';
2
+ export declare const EphemeralContextSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ value: z.ZodUnknown;
5
+ description: z.ZodOptional<z.ZodString>;
6
+ schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
7
+ }, z.core.$strip>;
8
+ export declare const ContextItemSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
9
+ name: z.ZodString;
10
+ description: z.ZodString;
11
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
12
+ inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
13
+ outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ name: z.ZodString;
16
+ description: z.ZodString;
17
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
18
+ inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
19
+ outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
20
+ }, z.core.$strip>]>, z.ZodObject<{
21
+ name: z.ZodString;
22
+ value: z.ZodUnknown;
23
+ description: z.ZodOptional<z.ZodString>;
24
+ schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
25
+ }, z.core.$strip>]>;
26
+ export declare const QueryRequestSchema: z.ZodObject<{
27
+ prompt: z.ZodString;
28
+ context: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
29
+ name: z.ZodString;
30
+ description: z.ZodString;
31
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
32
+ inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
33
+ outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ name: z.ZodString;
36
+ description: z.ZodString;
37
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
38
+ inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
39
+ outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
40
+ }, z.core.$strip>]>, z.ZodObject<{
41
+ name: z.ZodString;
42
+ value: z.ZodUnknown;
43
+ description: z.ZodOptional<z.ZodString>;
44
+ schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
45
+ }, z.core.$strip>]>>>;
46
+ responseTool: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
47
+ name: z.ZodString;
48
+ description: z.ZodString;
49
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
50
+ inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
51
+ outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
52
+ }, z.core.$strip>, z.ZodObject<{
53
+ name: z.ZodString;
54
+ description: z.ZodString;
55
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
56
+ inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
57
+ outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
58
+ }, z.core.$strip>]>>;
59
+ tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
60
+ name: z.ZodString;
61
+ description: z.ZodString;
62
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
63
+ inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
64
+ outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
65
+ }, z.core.$strip>, z.ZodObject<{
66
+ name: z.ZodString;
67
+ description: z.ZodString;
68
+ handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
69
+ inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
70
+ outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
71
+ }, z.core.$strip>]>>>;
72
+ restrictTools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
73
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
74
+ }, z.core.$strip>;
75
+ /**
76
+ * Client-side query response result schemas.
77
+ *
78
+ * These schemas represent individual query lifecycle events as consumed by the web library from the bridge.
79
+ * They differ slightly from the wire-format schemas in @mcp-web/types/query because:
80
+ * - Wire format (types package): Optimized for WebSocket transmission between bridge and frontend
81
+ * - Client format (web package): Optimized for consumption by the MCPWeb class
82
+ *
83
+ * The main difference is that `QueryResponseResultCompleteSchema` includes the full toolCalls array,
84
+ * while the wire format `QueryCompleteBridgeMessageSchema` is the same but sent over WebSocket.
85
+ */
86
+ export declare const QueryResponseResultAcceptedSchema: z.ZodObject<{
87
+ type: z.ZodDefault<z.ZodLiteral<"query_accepted">>;
88
+ uuid: z.ZodString;
89
+ }, z.core.$strip>;
90
+ export declare const QueryResponseResultProgressSchema: z.ZodObject<{
91
+ type: z.ZodDefault<z.ZodLiteral<"query_progress">>;
92
+ uuid: z.ZodString;
93
+ message: z.ZodString;
94
+ }, z.core.$strip>;
95
+ export declare const QueryResponseResultCompleteSchema: z.ZodObject<{
96
+ type: z.ZodDefault<z.ZodLiteral<"query_complete">>;
97
+ uuid: z.ZodString;
98
+ message: z.ZodOptional<z.ZodString>;
99
+ toolCalls: z.ZodArray<z.ZodObject<{
100
+ tool: z.ZodString;
101
+ arguments: z.ZodUnknown;
102
+ result: z.ZodUnknown;
103
+ }, z.core.$strip>>;
104
+ }, z.core.$strip>;
105
+ export declare const QueryResponseResultFailureSchema: z.ZodObject<{
106
+ type: z.ZodDefault<z.ZodLiteral<"query_failure">>;
107
+ uuid: z.ZodString;
108
+ error: z.ZodString;
109
+ }, z.core.$strip>;
110
+ export declare const QueryResponseResultCancelSchema: z.ZodObject<{
111
+ type: z.ZodDefault<z.ZodLiteral<"query_cancel">>;
112
+ uuid: z.ZodString;
113
+ reason: z.ZodOptional<z.ZodString>;
114
+ }, z.core.$strip>;
115
+ export declare const QueryResponseResultSchema: z.ZodUnion<readonly [z.ZodObject<{
116
+ type: z.ZodDefault<z.ZodLiteral<"query_accepted">>;
117
+ uuid: z.ZodString;
118
+ }, z.core.$strip>, z.ZodObject<{
119
+ type: z.ZodDefault<z.ZodLiteral<"query_progress">>;
120
+ uuid: z.ZodString;
121
+ message: z.ZodString;
122
+ }, z.core.$strip>, z.ZodObject<{
123
+ type: z.ZodDefault<z.ZodLiteral<"query_complete">>;
124
+ uuid: z.ZodString;
125
+ message: z.ZodOptional<z.ZodString>;
126
+ toolCalls: z.ZodArray<z.ZodObject<{
127
+ tool: z.ZodString;
128
+ arguments: z.ZodUnknown;
129
+ result: z.ZodUnknown;
130
+ }, z.core.$strip>>;
131
+ }, z.core.$strip>, z.ZodObject<{
132
+ type: z.ZodDefault<z.ZodLiteral<"query_failure">>;
133
+ uuid: z.ZodString;
134
+ error: z.ZodString;
135
+ }, z.core.$strip>, z.ZodObject<{
136
+ type: z.ZodDefault<z.ZodLiteral<"query_cancel">>;
137
+ uuid: z.ZodString;
138
+ reason: z.ZodOptional<z.ZodString>;
139
+ }, z.core.$strip>]>;
140
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,sBAAsB;;;;;iBAKjC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;0BAqChB,GAAG,qCAGS,GAAG;;;;;;0BAiB2B,GACvD,qCAAqC,GAAG;;;;;;;;mBA1D+C,CAAC;AAEzF,eAAO,MAAM,kBAAkB;;;;;8BAmCjB,GAAG,qCAGS,GAAG;;;;;;8BAiB2B,GACvD,qCAAqC,GAAG;;;;;;;;;;;;8BArB3B,GAAG,qCAGS,GAAG;;;;;;8BAiB2B,GACvD,qCAAqC,GAAG;;;;;;;8BArB3B,GAAG,qCAGS,GAAG;;;;;;8BAiB2B,GACvD,qCAAqC,GAAG;;;;;;iBA3CvC,CAAC;AAEH;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,iCAAiC;;;iBAG5C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;iBAI5C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;;;;;;iBAS5C,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;iBAI3C,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;iBAI1C,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;mBAMpC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { ToolDefinitionSchema } from '@mcp-web/types';
2
+ import { z } from 'zod';
3
+ export const EphemeralContextSchema = z.object({
4
+ name: z.string(),
5
+ value: z.unknown(),
6
+ description: z.string().optional(),
7
+ schema: z.custom().optional()
8
+ });
9
+ export const ContextItemSchema = z.union([ToolDefinitionSchema, EphemeralContextSchema]);
10
+ export const QueryRequestSchema = z.object({
11
+ /** Query prompt */
12
+ prompt: z.string(),
13
+ /** Context items to use for the query */
14
+ context: z.array(ContextItemSchema).optional(),
15
+ /** Tool to use for completing a query */
16
+ responseTool: ToolDefinitionSchema.optional(),
17
+ /** Tools available for this query (optimization - avoids listTools call) */
18
+ tools: z.array(ToolDefinitionSchema).optional(),
19
+ /** If true, only tools listed in 'tools' array can be called */
20
+ restrictTools: z.boolean().optional().default(false),
21
+ /** Timeout for the query */
22
+ timeout: z.number().optional().default(30000),
23
+ });
24
+ /**
25
+ * Client-side query response result schemas.
26
+ *
27
+ * These schemas represent individual query lifecycle events as consumed by the web library from the bridge.
28
+ * They differ slightly from the wire-format schemas in @mcp-web/types/query because:
29
+ * - Wire format (types package): Optimized for WebSocket transmission between bridge and frontend
30
+ * - Client format (web package): Optimized for consumption by the MCPWeb class
31
+ *
32
+ * The main difference is that `QueryResponseResultCompleteSchema` includes the full toolCalls array,
33
+ * while the wire format `QueryCompleteBridgeMessageSchema` is the same but sent over WebSocket.
34
+ */
35
+ export const QueryResponseResultAcceptedSchema = z.object({
36
+ type: z.literal('query_accepted').default('query_accepted'),
37
+ uuid: z.string(),
38
+ });
39
+ export const QueryResponseResultProgressSchema = z.object({
40
+ type: z.literal('query_progress').default('query_progress'),
41
+ uuid: z.string(),
42
+ message: z.string(),
43
+ });
44
+ export const QueryResponseResultCompleteSchema = z.object({
45
+ type: z.literal('query_complete').default('query_complete'),
46
+ uuid: z.string(),
47
+ message: z.string().optional(),
48
+ toolCalls: z.array(z.object({
49
+ tool: z.string(),
50
+ arguments: z.unknown(),
51
+ result: z.unknown()
52
+ })),
53
+ });
54
+ export const QueryResponseResultFailureSchema = z.object({
55
+ type: z.literal('query_failure').default('query_failure'),
56
+ uuid: z.string(),
57
+ error: z.string(),
58
+ });
59
+ export const QueryResponseResultCancelSchema = z.object({
60
+ type: z.literal('query_cancel').default('query_cancel'),
61
+ uuid: z.string(),
62
+ reason: z.string().optional(),
63
+ });
64
+ export const QueryResponseResultSchema = z.union([
65
+ QueryResponseResultAcceptedSchema,
66
+ QueryResponseResultProgressSchema,
67
+ QueryResponseResultCompleteSchema,
68
+ QueryResponseResultFailureSchema,
69
+ QueryResponseResultCancelSchema,
70
+ ]);
@@ -0,0 +1,23 @@
1
+ import type { ToolDefinitionZod } from '@mcp-web/types';
2
+ import type { SplitPlan, DecompositionOptions } from '@mcp-web/decompose-zod-schema';
3
+ import { z } from 'zod';
4
+ export interface BasicStateToolOptions<T> {
5
+ name: string;
6
+ description: string;
7
+ get: () => T;
8
+ set: (value: T) => void;
9
+ schema: z.ZodType<T> | z.core.JSONSchema.JSONSchema;
10
+ schemaSplit?: SplitPlan | DecompositionOptions;
11
+ }
12
+ export interface BasicStateToolsResult {
13
+ getter: ToolDefinitionZod;
14
+ setters: ToolDefinitionZod[];
15
+ }
16
+ /**
17
+ * Generates basic getter and setter tools for state management.
18
+ * Returns tool definitions without registering them - the caller is responsible for registration.
19
+ *
20
+ * @returns Object containing getter tool and array of setter tools (1 for simple, N for decomposed)
21
+ */
22
+ export declare function generateBasicStateTools<T>(options: BasicStateToolOptions<T>): BasicStateToolsResult;
23
+ //# sourceMappingURL=generate-basic-state-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-basic-state-tools.d.ts","sourceRoot":"","sources":["../../src/tool-generators/generate-basic-state-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAoB,SAAS,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAEvG,OAAO,EAAa,CAAC,EAAE,MAAM,KAAK,CAAC;AAGnC,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;IACpD,WAAW,CAAC,EAAE,SAAS,GAAG,oBAAoB,CAAC;CAChD;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,qBAAqB,CAgGvB"}
@@ -0,0 +1,95 @@
1
+ import { applyPartialUpdate, decomposeSchema } from '@mcp-web/decompose-zod-schema';
2
+ import { ZodObject, z } from 'zod';
3
+ import { isZodSchema, validateInput } from '../utils.js';
4
+ /**
5
+ * Generates basic getter and setter tools for state management.
6
+ * Returns tool definitions without registering them - the caller is responsible for registration.
7
+ *
8
+ * @returns Object containing getter tool and array of setter tools (1 for simple, N for decomposed)
9
+ */
10
+ export function generateBasicStateTools(options) {
11
+ const { name, description, get, set, schema, schemaSplit } = options;
12
+ // Always create a getter tool
13
+ const getter = {
14
+ name: `get_${name}`,
15
+ description: `Get the current value of ${name}. ${description}`,
16
+ handler: get,
17
+ outputSchema: schema,
18
+ };
19
+ const setters = [];
20
+ // Determine if we should decompose the schema
21
+ const isZodObjectSchema = isZodSchema(schema) && schema instanceof ZodObject;
22
+ const shouldDecompose = isZodObjectSchema && schemaSplit !== undefined;
23
+ let decomposedSchemas = [];
24
+ if (shouldDecompose && schemaSplit) {
25
+ try {
26
+ decomposedSchemas = decomposeSchema(schema, schemaSplit);
27
+ }
28
+ catch (error) {
29
+ console.warn(`Failed to decompose schema for ${name}:`, error);
30
+ }
31
+ }
32
+ if (decomposedSchemas.length > 0) {
33
+ // Add decomposed setter tools
34
+ for (const decomposed of decomposedSchemas) {
35
+ const setterTool = {
36
+ name: `set_${name}_${decomposed.name}`,
37
+ description: `Set ${decomposed.name} properties of ${name}. ${description}`,
38
+ handler: (partialValue) => {
39
+ try {
40
+ const currentValue = get();
41
+ const updatedValue = applyPartialUpdate(currentValue, decomposed.targetPaths, partialValue);
42
+ const validatedValue = validateInput(updatedValue, schema);
43
+ set(validatedValue);
44
+ return { success: true };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ success: false,
49
+ error: error instanceof Error ? error.message : 'Unknown error',
50
+ };
51
+ }
52
+ },
53
+ inputSchema: decomposed.schema,
54
+ outputSchema: z.object({
55
+ success: z.boolean(),
56
+ error: z.string().optional(),
57
+ }),
58
+ };
59
+ setters.push(setterTool);
60
+ }
61
+ }
62
+ else {
63
+ // Add single setter tool
64
+ // Wrap non-object schemas in a value property (MCP requires object inputs)
65
+ const inputSchema = isZodObjectSchema
66
+ ? schema
67
+ : z.object({ value: schema });
68
+ const setterTool = {
69
+ name: `set_${name}`,
70
+ description: `Set the value of ${name}. ${description}`,
71
+ handler: (newValue) => {
72
+ try {
73
+ // Unwrap if we wrapped in value property
74
+ const actualValue = isZodObjectSchema ? newValue : newValue.value;
75
+ const validatedValue = validateInput(actualValue, schema);
76
+ set(validatedValue);
77
+ return { success: true };
78
+ }
79
+ catch (error) {
80
+ return {
81
+ success: false,
82
+ error: error instanceof Error ? error.message : 'Unknown error',
83
+ };
84
+ }
85
+ },
86
+ inputSchema,
87
+ outputSchema: z.object({
88
+ success: z.boolean(),
89
+ error: z.string().optional(),
90
+ }),
91
+ };
92
+ setters.push(setterTool);
93
+ }
94
+ return { getter, setters };
95
+ }
@@ -0,0 +1,8 @@
1
+ import type { ToolDefinitionZod } from '@mcp-web/types';
2
+ import type { SchemaShape, ToolGenerationOptions } from './types.js';
3
+ /**
4
+ * Generates getter and setter tools for fixed-shape schemas.
5
+ * Fixed-shape includes: primitives, tuples, and objects with only fixed props.
6
+ */
7
+ export declare function generateFixedShapeTools(options: ToolGenerationOptions, shape: SchemaShape): ToolDefinitionZod[];
8
+ //# sourceMappingURL=generate-fixed-shape-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-fixed-shape-tools.d.ts","sourceRoot":"","sources":["../../src/tool-generators/generate-fixed-shape-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrE;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,KAAK,EAAE,WAAW,GACjB,iBAAiB,EAAE,CAgDrB"}
@@ -0,0 +1,53 @@
1
+ import { z } from 'zod';
2
+ import { deriveSetInputSchema, unwrapSchema } from './schema-helpers.js';
3
+ import { deepMerge } from './utils.js';
4
+ /**
5
+ * Generates getter and setter tools for fixed-shape schemas.
6
+ * Fixed-shape includes: primitives, tuples, and objects with only fixed props.
7
+ */
8
+ export function generateFixedShapeTools(options, shape) {
9
+ const { name, description, get, set, schema } = options;
10
+ const tools = [];
11
+ const unwrapped = unwrapSchema(schema);
12
+ // Getter tool
13
+ tools.push({
14
+ name: `get_${name}`,
15
+ description: `Get the current ${description}`,
16
+ inputSchema: z.object({}),
17
+ handler: async () => {
18
+ return get();
19
+ },
20
+ });
21
+ // Setter tool - behavior depends on subtype
22
+ if (shape.subtype === 'primitive' || shape.subtype === 'tuple') {
23
+ // Full replacement for primitives and tuples
24
+ tools.push({
25
+ name: `set_${name}`,
26
+ description: `Set the ${description}`,
27
+ inputSchema: z.object({ value: schema }),
28
+ handler: async (input) => {
29
+ const validated = schema.parse(input.value);
30
+ set(validated);
31
+ return { success: true, value: validated };
32
+ },
33
+ });
34
+ }
35
+ else if (shape.subtype === 'object') {
36
+ // Partial update with deep merge for objects
37
+ const objectSchema = unwrapped;
38
+ const setInputSchema = deriveSetInputSchema(objectSchema);
39
+ tools.push({
40
+ name: `set_${name}`,
41
+ description: `Update the ${description} (partial update with deep merge)`,
42
+ inputSchema: setInputSchema,
43
+ handler: async (input) => {
44
+ const current = get();
45
+ const merged = deepMerge(current, input);
46
+ const validated = schema.parse(merged);
47
+ set(validated);
48
+ return { success: true, value: validated };
49
+ },
50
+ });
51
+ }
52
+ return tools;
53
+ }
@@ -0,0 +1,6 @@
1
+ export { id, system } from './schema-helpers.js';
2
+ export { generateToolsForSchema } from './tool-generator.js';
3
+ export { generateBasicStateTools } from './generate-basic-state-tools.js';
4
+ export type { BasicStateToolOptions, BasicStateToolsResult } from './generate-basic-state-tools.js';
5
+ export type { GeneratedTools, KeyFieldResult, SchemaShape, ToolGenerationOptions } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAEpG,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { id, system } from './schema-helpers.js';
2
+ export { generateToolsForSchema } from './tool-generator.js';
3
+ export { generateBasicStateTools } from './generate-basic-state-tools.js';
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import type { KeyFieldResult, SchemaShape } from './types.js';
3
+ /**
4
+ * Analyzes a schema to determine its shape characteristics.
5
+ */
6
+ export declare function analyzeSchemaShape(schema: z.ZodTypeAny): SchemaShape;
7
+ /**
8
+ * Detects the ID field in an object schema.
9
+ * Returns information about explicit id() markers.
10
+ * Throws an error if multiple id() markers are found.
11
+ */
12
+ export declare function findIdField(schema: z.ZodObject<z.ZodRawShape>): KeyFieldResult;
13
+ /**
14
+ * Validates that a schema only uses supported types.
15
+ * Throws an error if unsupported types are found.
16
+ */
17
+ export declare function validateSupportedTypes(schema: z.ZodTypeAny, path?: string): string[];
18
+ //# sourceMappingURL=schema-analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-analysis.d.ts","sourceRoot":"","sources":["../../src/tool-generators/schema-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,WAAW,CA+EpE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,cAAc,CAuB9E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,SAAS,GAAG,MAAM,EAAE,CA0CpF"}