@mcp-web/core 0.1.0 → 0.1.2
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.
- package/dist/web.d.ts +1 -1
- package/dist/web.js +1 -1
- package/package.json +9 -4
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts +0 -8
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts.map +0 -1
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.js +0 -53
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts +0 -2
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.js +0 -331
- package/dist/expanded-schema-tools/index.d.ts +0 -4
- package/dist/expanded-schema-tools/index.d.ts.map +0 -1
- package/dist/expanded-schema-tools/index.js +0 -2
- package/dist/expanded-schema-tools/integration.test.d.ts +0 -2
- package/dist/expanded-schema-tools/integration.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/integration.test.js +0 -599
- package/dist/expanded-schema-tools/schema-analysis.d.ts +0 -18
- package/dist/expanded-schema-tools/schema-analysis.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-analysis.js +0 -142
- package/dist/expanded-schema-tools/schema-analysis.test.d.ts +0 -2
- package/dist/expanded-schema-tools/schema-analysis.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-analysis.test.js +0 -314
- package/dist/expanded-schema-tools/schema-helpers.d.ts +0 -69
- package/dist/expanded-schema-tools/schema-helpers.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-helpers.js +0 -139
- package/dist/expanded-schema-tools/schema-helpers.test.d.ts +0 -2
- package/dist/expanded-schema-tools/schema-helpers.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-helpers.test.js +0 -223
- package/dist/expanded-schema-tools/tool-generator.d.ts +0 -10
- package/dist/expanded-schema-tools/tool-generator.d.ts.map +0 -1
- package/dist/expanded-schema-tools/tool-generator.js +0 -430
- package/dist/expanded-schema-tools/tool-generator.test.d.ts +0 -2
- package/dist/expanded-schema-tools/tool-generator.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/tool-generator.test.js +0 -689
- package/dist/expanded-schema-tools/types.d.ts +0 -26
- package/dist/expanded-schema-tools/types.d.ts.map +0 -1
- package/dist/expanded-schema-tools/types.js +0 -1
- package/dist/expanded-schema-tools/utils.d.ts +0 -16
- package/dist/expanded-schema-tools/utils.d.ts.map +0 -1
- package/dist/expanded-schema-tools/utils.js +0 -35
- package/dist/expanded-schema-tools/utils.test.d.ts +0 -2
- package/dist/expanded-schema-tools/utils.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/utils.test.js +0 -169
- package/dist/schema-helpers.d.ts +0 -69
- package/dist/schema-helpers.d.ts.map +0 -1
- package/dist/schema-helpers.js +0 -139
- package/dist/zod-to-tools.d.ts +0 -49
- package/dist/zod-to-tools.d.ts.map +0 -1
- package/dist/zod-to-tools.js +0 -623
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from '@mcp-web/types';
|
|
2
|
-
import type { z } from 'zod';
|
|
3
|
-
export interface ToolGenerationOptions {
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
get: () => unknown;
|
|
7
|
-
set: (value: unknown) => void;
|
|
8
|
-
schema: z.ZodTypeAny;
|
|
9
|
-
}
|
|
10
|
-
export interface GeneratedTools {
|
|
11
|
-
tools: ToolDefinition[];
|
|
12
|
-
warnings: string[];
|
|
13
|
-
}
|
|
14
|
-
export interface SchemaShape {
|
|
15
|
-
type: 'fixed' | 'dynamic' | 'mixed' | 'unsupported';
|
|
16
|
-
subtype: 'object' | 'array' | 'record' | 'primitive' | 'tuple' | 'unknown';
|
|
17
|
-
hasOptionalFields: boolean;
|
|
18
|
-
optionalPaths: string[];
|
|
19
|
-
fixedPaths: string[];
|
|
20
|
-
dynamicPaths: string[];
|
|
21
|
-
}
|
|
22
|
-
export interface KeyFieldResult {
|
|
23
|
-
type: 'explicit' | 'none';
|
|
24
|
-
field?: string;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,OAAO,CAAC;IACnB,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;IACpD,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3E,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deep merge two objects recursively.
|
|
3
|
-
* Used for partial updates to state objects.
|
|
4
|
-
*
|
|
5
|
-
* @param target - The target object to merge into
|
|
6
|
-
* @param source - The source object to merge from
|
|
7
|
-
* @returns The merged result
|
|
8
|
-
*
|
|
9
|
-
* Key behaviors:
|
|
10
|
-
* - `undefined` in source → keep target value (no change)
|
|
11
|
-
* - `null` in source → set to null (explicit clear)
|
|
12
|
-
* - Nested objects → recursively merged
|
|
13
|
-
* - Arrays → replaced entirely (not merged)
|
|
14
|
-
*/
|
|
15
|
-
export declare function deepMerge(target: unknown, source: unknown): unknown;
|
|
16
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAenE"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deep merge two objects recursively.
|
|
3
|
-
* Used for partial updates to state objects.
|
|
4
|
-
*
|
|
5
|
-
* @param target - The target object to merge into
|
|
6
|
-
* @param source - The source object to merge from
|
|
7
|
-
* @returns The merged result
|
|
8
|
-
*
|
|
9
|
-
* Key behaviors:
|
|
10
|
-
* - `undefined` in source → keep target value (no change)
|
|
11
|
-
* - `null` in source → set to null (explicit clear)
|
|
12
|
-
* - Nested objects → recursively merged
|
|
13
|
-
* - Arrays → replaced entirely (not merged)
|
|
14
|
-
*/
|
|
15
|
-
export function deepMerge(target, source) {
|
|
16
|
-
// Base cases
|
|
17
|
-
if (source === null)
|
|
18
|
-
return source; // Explicit null clears the value
|
|
19
|
-
if (source === undefined)
|
|
20
|
-
return target; // Undefined means "no change"
|
|
21
|
-
if (typeof source !== 'object')
|
|
22
|
-
return source;
|
|
23
|
-
if (Array.isArray(source))
|
|
24
|
-
return source; // Arrays are replaced, not merged
|
|
25
|
-
if (typeof target !== 'object' || target === null)
|
|
26
|
-
return source;
|
|
27
|
-
if (Array.isArray(target))
|
|
28
|
-
return source;
|
|
29
|
-
// Object merge: recursively merge properties
|
|
30
|
-
const result = { ...target };
|
|
31
|
-
for (const [key, value] of Object.entries(source)) {
|
|
32
|
-
result[key] = deepMerge(result[key], value);
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'bun:test';
|
|
2
|
-
import { deepMerge } from './utils.js';
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Basic Merge Cases
|
|
5
|
-
// ============================================================================
|
|
6
|
-
test('deepMerge - merges two simple objects', () => {
|
|
7
|
-
const target = { a: 1, b: 2 };
|
|
8
|
-
const source = { c: 3 };
|
|
9
|
-
const result = deepMerge(target, source);
|
|
10
|
-
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
|
11
|
-
});
|
|
12
|
-
test('deepMerge - merges with nested objects recursively', () => {
|
|
13
|
-
const target = {
|
|
14
|
-
user: { name: 'Alice', age: 30 },
|
|
15
|
-
settings: { theme: 'dark' },
|
|
16
|
-
};
|
|
17
|
-
const source = {
|
|
18
|
-
user: { age: 31, email: 'alice@example.com' },
|
|
19
|
-
settings: { notifications: true },
|
|
20
|
-
};
|
|
21
|
-
const result = deepMerge(target, source);
|
|
22
|
-
expect(result).toEqual({
|
|
23
|
-
user: { name: 'Alice', age: 31, email: 'alice@example.com' },
|
|
24
|
-
settings: { theme: 'dark', notifications: true },
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
test('deepMerge - merges with overlapping keys', () => {
|
|
28
|
-
const target = { a: 1, b: 2, c: 3 };
|
|
29
|
-
const source = { b: 20, c: 30 };
|
|
30
|
-
const result = deepMerge(target, source);
|
|
31
|
-
expect(result).toEqual({ a: 1, b: 20, c: 30 });
|
|
32
|
-
});
|
|
33
|
-
// ============================================================================
|
|
34
|
-
// Null/Undefined Handling
|
|
35
|
-
// ============================================================================
|
|
36
|
-
test('deepMerge - null in source sets value to null (explicit clear)', () => {
|
|
37
|
-
const target = { a: 1, b: 2 };
|
|
38
|
-
const source = { b: null };
|
|
39
|
-
const result = deepMerge(target, source);
|
|
40
|
-
expect(result).toEqual({ a: 1, b: null });
|
|
41
|
-
});
|
|
42
|
-
test('deepMerge - undefined in source keeps target value (no change)', () => {
|
|
43
|
-
const target = { a: 1, b: 2 };
|
|
44
|
-
const source = { b: undefined };
|
|
45
|
-
const result = deepMerge(target, source);
|
|
46
|
-
expect(result).toEqual({ a: 1, b: 2 });
|
|
47
|
-
});
|
|
48
|
-
test('deepMerge - null target, non-null source replaces with source', () => {
|
|
49
|
-
const target = null;
|
|
50
|
-
const source = { a: 1 };
|
|
51
|
-
const result = deepMerge(target, source);
|
|
52
|
-
expect(result).toEqual({ a: 1 });
|
|
53
|
-
});
|
|
54
|
-
test('deepMerge - nested null clears nested value', () => {
|
|
55
|
-
const target = {
|
|
56
|
-
user: { name: 'Alice', email: 'alice@example.com' },
|
|
57
|
-
};
|
|
58
|
-
const source = {
|
|
59
|
-
user: { email: null },
|
|
60
|
-
};
|
|
61
|
-
const result = deepMerge(target, source);
|
|
62
|
-
expect(result).toEqual({
|
|
63
|
-
user: { name: 'Alice', email: null },
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
// ============================================================================
|
|
67
|
-
// Array Behavior
|
|
68
|
-
// ============================================================================
|
|
69
|
-
test('deepMerge - arrays are replaced entirely (not merged)', () => {
|
|
70
|
-
const target = { tags: ['a', 'b', 'c'] };
|
|
71
|
-
const source = { tags: ['x', 'y'] };
|
|
72
|
-
const result = deepMerge(target, source);
|
|
73
|
-
expect(result).toEqual({ tags: ['x', 'y'] });
|
|
74
|
-
});
|
|
75
|
-
test('deepMerge - nested arrays within objects are replaced', () => {
|
|
76
|
-
const target = {
|
|
77
|
-
user: { name: 'Alice', tags: ['a', 'b'] },
|
|
78
|
-
};
|
|
79
|
-
const source = {
|
|
80
|
-
user: { tags: ['x'] },
|
|
81
|
-
};
|
|
82
|
-
const result = deepMerge(target, source);
|
|
83
|
-
expect(result).toEqual({
|
|
84
|
-
user: { name: 'Alice', tags: ['x'] },
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
test('deepMerge - array at root replaces target', () => {
|
|
88
|
-
const target = [1, 2, 3];
|
|
89
|
-
const source = [4, 5];
|
|
90
|
-
const result = deepMerge(target, source);
|
|
91
|
-
expect(result).toEqual([4, 5]);
|
|
92
|
-
});
|
|
93
|
-
// ============================================================================
|
|
94
|
-
// Edge Cases
|
|
95
|
-
// ============================================================================
|
|
96
|
-
test('deepMerge - empty objects', () => {
|
|
97
|
-
const target = {};
|
|
98
|
-
const source = {};
|
|
99
|
-
const result = deepMerge(target, source);
|
|
100
|
-
expect(result).toEqual({});
|
|
101
|
-
});
|
|
102
|
-
test('deepMerge - empty source returns target', () => {
|
|
103
|
-
const target = { a: 1, b: 2 };
|
|
104
|
-
const source = {};
|
|
105
|
-
const result = deepMerge(target, source);
|
|
106
|
-
expect(result).toEqual({ a: 1, b: 2 });
|
|
107
|
-
});
|
|
108
|
-
test('deepMerge - primitives in source replace target', () => {
|
|
109
|
-
const target = { a: { nested: true } };
|
|
110
|
-
const source = { a: 'string' };
|
|
111
|
-
const result = deepMerge(target, source);
|
|
112
|
-
expect(result).toEqual({ a: 'string' });
|
|
113
|
-
});
|
|
114
|
-
test('deepMerge - deep nesting (3+ levels)', () => {
|
|
115
|
-
const target = {
|
|
116
|
-
level1: {
|
|
117
|
-
level2: {
|
|
118
|
-
level3: {
|
|
119
|
-
value: 'original',
|
|
120
|
-
keep: true,
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
const source = {
|
|
126
|
-
level1: {
|
|
127
|
-
level2: {
|
|
128
|
-
level3: {
|
|
129
|
-
value: 'updated',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
const result = deepMerge(target, source);
|
|
135
|
-
expect(result).toEqual({
|
|
136
|
-
level1: {
|
|
137
|
-
level2: {
|
|
138
|
-
level3: {
|
|
139
|
-
value: 'updated',
|
|
140
|
-
keep: true,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
test('deepMerge - undefined source returns target', () => {
|
|
147
|
-
const target = { a: 1 };
|
|
148
|
-
const source = undefined;
|
|
149
|
-
const result = deepMerge(target, source);
|
|
150
|
-
expect(result).toEqual({ a: 1 });
|
|
151
|
-
});
|
|
152
|
-
test('deepMerge - primitive target and object source', () => {
|
|
153
|
-
const target = 'string';
|
|
154
|
-
const source = { a: 1 };
|
|
155
|
-
const result = deepMerge(target, source);
|
|
156
|
-
expect(result).toEqual({ a: 1 });
|
|
157
|
-
});
|
|
158
|
-
test('deepMerge - number source replaces any target', () => {
|
|
159
|
-
const target = { nested: { value: true } };
|
|
160
|
-
const source = 42;
|
|
161
|
-
const result = deepMerge(target, source);
|
|
162
|
-
expect(result).toBe(42);
|
|
163
|
-
});
|
|
164
|
-
test('deepMerge - boolean source replaces any target', () => {
|
|
165
|
-
const target = { a: 1 };
|
|
166
|
-
const source = false;
|
|
167
|
-
const result = deepMerge(target, source);
|
|
168
|
-
expect(result).toBe(false);
|
|
169
|
-
});
|
package/dist/schema-helpers.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/schema-helpers.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/zod-to-tools.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from '@mcp-web/types';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import type { MCPWeb } from './web.js';
|
|
4
|
-
export interface ToolGenerationOptions {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
get: () => unknown;
|
|
8
|
-
set: (value: unknown) => void;
|
|
9
|
-
schema: z.ZodTypeAny;
|
|
10
|
-
}
|
|
11
|
-
export interface GeneratedTools {
|
|
12
|
-
tools: ToolDefinition[];
|
|
13
|
-
warnings: string[];
|
|
14
|
-
}
|
|
15
|
-
export interface SchemaShape {
|
|
16
|
-
type: 'fixed' | 'dynamic' | 'mixed' | 'unsupported';
|
|
17
|
-
subtype: 'object' | 'array' | 'record' | 'primitive' | 'tuple' | 'unknown';
|
|
18
|
-
hasOptionalFields: boolean;
|
|
19
|
-
optionalPaths: string[];
|
|
20
|
-
fixedPaths: string[];
|
|
21
|
-
dynamicPaths: string[];
|
|
22
|
-
}
|
|
23
|
-
export interface KeyFieldResult {
|
|
24
|
-
type: 'explicit' | 'none';
|
|
25
|
-
field?: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Generates MCP tools for a schema based on its shape.
|
|
29
|
-
* - Fixed-shape schemas → get + set with deep merge
|
|
30
|
-
* - Dynamic-shape schemas → get + add + set + delete (arrays) or get + set + delete (records)
|
|
31
|
-
* - Mixed schemas → asymmetric get/set + collection tools
|
|
32
|
-
*/
|
|
33
|
-
export declare function generateToolsForSchema(options: ToolGenerationOptions, mcpWeb: MCPWeb): GeneratedTools;
|
|
34
|
-
/**
|
|
35
|
-
* Analyzes a schema to determine its shape characteristics.
|
|
36
|
-
*/
|
|
37
|
-
export declare function analyzeSchemaShape(schema: z.ZodTypeAny): SchemaShape;
|
|
38
|
-
/**
|
|
39
|
-
* Detects the ID field in an object schema.
|
|
40
|
-
* Returns information about explicit id() markers.
|
|
41
|
-
* Throws an error if multiple id() markers are found.
|
|
42
|
-
*/
|
|
43
|
-
export declare function isIdField(schema: z.ZodObject<z.ZodRawShape>): KeyFieldResult;
|
|
44
|
-
/**
|
|
45
|
-
* Validates that a schema only uses supported types.
|
|
46
|
-
* Throws an error if unsupported types are found.
|
|
47
|
-
*/
|
|
48
|
-
export declare function validateSupportedTypes(schema: z.ZodTypeAny, path?: string): string[];
|
|
49
|
-
//# sourceMappingURL=zod-to-tools.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod-to-tools.d.ts","sourceRoot":"","sources":["../src/zod-to-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMvC,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,OAAO,CAAC;IACnB,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;IACpD,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3E,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,MAAM,GACb,cAAc,CAsDhB;AAMD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,WAAW,CAmFpE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,cAAc,CAuB5E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,SAAS,GAAG,MAAM,EAAE,CA0CpF"}
|