simple-webmcp 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.
- package/.agents/skills/webmcp-simple/SKILL.md +136 -0
- package/.agents/skills/webmcp-simple/references/api.md +77 -0
- package/.agents/skills/webmcp-simple/references/recipes.md +113 -0
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/index.cjs +849 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +826 -0
- package/dist/index.js.map +1 -0
- package/dist/polyfill.cjs +68 -0
- package/dist/polyfill.cjs.map +1 -0
- package/dist/polyfill.d.cts +18 -0
- package/dist/polyfill.d.ts +18 -0
- package/dist/polyfill.js +62 -0
- package/dist/polyfill.js.map +1 -0
- package/dist/react.cjs +110 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +30 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.js +106 -0
- package/dist/react.js.map +1 -0
- package/dist/types-D-cwSfEU.d.cts +126 -0
- package/dist/types-D-cwSfEU.d.ts +126 -0
- package/dist/zod.cjs +144 -0
- package/dist/zod.cjs.map +1 -0
- package/dist/zod.d.cts +20 -0
- package/dist/zod.d.ts +20 -0
- package/dist/zod.js +137 -0
- package/dist/zod.js.map +1 -0
- package/package.json +100 -0
package/dist/zod.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/internal/schema.ts
|
|
2
|
+
var ZOD_CONVERTER_KEY = "__simpleWebmcp_zodConverter";
|
|
3
|
+
function registerZodConverter(fn) {
|
|
4
|
+
globalThis[ZOD_CONVERTER_KEY] = fn;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/zod.ts
|
|
8
|
+
function convertZodDef(z) {
|
|
9
|
+
const def = z._def ?? z.def ?? z._zod?.def ?? null;
|
|
10
|
+
const typeName = def?.typeName ?? z._zod?.traits?.type ?? z.typeName ?? void 0;
|
|
11
|
+
const ctor = z.constructor?.name || "";
|
|
12
|
+
if (typeName === "ZodOptional" || ctor === "ZodOptional") {
|
|
13
|
+
const inner = z.unwrap?.() ?? def?.innerType ?? def?.type ?? null;
|
|
14
|
+
if (inner) return convertZodDef(inner);
|
|
15
|
+
}
|
|
16
|
+
if (typeName === "ZodDefault" || ctor === "ZodDefault") {
|
|
17
|
+
const inner = def?.innerType ?? z._def?.innerType ?? null;
|
|
18
|
+
const json = inner ? convertZodDef(inner) : { type: "string" };
|
|
19
|
+
const defVal = typeof def?.defaultValue === "function" ? def.defaultValue() : def?.defaultValue;
|
|
20
|
+
if (defVal !== void 0) json.default = defVal;
|
|
21
|
+
return json;
|
|
22
|
+
}
|
|
23
|
+
if (typeName === "ZodNullable" || ctor === "ZodNullable") {
|
|
24
|
+
const inner = def?.innerType ?? null;
|
|
25
|
+
const json = inner ? convertZodDef(inner) : { type: "string" };
|
|
26
|
+
return json;
|
|
27
|
+
}
|
|
28
|
+
if (typeName === "ZodEffects" || ctor === "ZodEffects") {
|
|
29
|
+
const inner = def?.schema ?? null;
|
|
30
|
+
if (inner) return convertZodDef(inner);
|
|
31
|
+
}
|
|
32
|
+
if (typeName === "ZodString" || ctor === "ZodString") {
|
|
33
|
+
const j = { type: "string" };
|
|
34
|
+
if (def?.checks) {
|
|
35
|
+
for (const c of def.checks) {
|
|
36
|
+
if (c.kind === "min") j.minLength = c.value;
|
|
37
|
+
if (c.kind === "max") j.maxLength = c.value;
|
|
38
|
+
if (c.kind === "regex") j.pattern = c.regex?.source;
|
|
39
|
+
if (c.kind === "email") j.format = "email";
|
|
40
|
+
if (c.kind === "url") j.format = "uri";
|
|
41
|
+
if (c.kind === "uuid") j.format = "uuid";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (z.description) j.description = z.description;
|
|
45
|
+
else if (def?.description) j.description = def.description;
|
|
46
|
+
return j;
|
|
47
|
+
}
|
|
48
|
+
if (typeName === "ZodNumber" || ctor === "ZodNumber") {
|
|
49
|
+
const j = { type: "number" };
|
|
50
|
+
if (def?.checks) {
|
|
51
|
+
for (const c of def.checks) {
|
|
52
|
+
if (c.kind === "min") j.minimum = c.value;
|
|
53
|
+
if (c.kind === "max") j.maximum = c.value;
|
|
54
|
+
if (c.kind === "int") j.type = "integer";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (z.description) j.description = z.description;
|
|
58
|
+
return j;
|
|
59
|
+
}
|
|
60
|
+
if (typeName === "ZodBoolean" || ctor === "ZodBoolean") return { type: "boolean" };
|
|
61
|
+
if (typeName === "ZodBigInt" || ctor === "ZodBigInt") return { type: "integer" };
|
|
62
|
+
if (typeName === "ZodDate" || ctor === "ZodDate") return { type: "string", format: "date-time" };
|
|
63
|
+
if (typeName === "ZodEnum" || ctor === "ZodEnum") {
|
|
64
|
+
const values = def?.values ?? z._def?.values ?? z.options ?? [];
|
|
65
|
+
return { type: "string", enum: values };
|
|
66
|
+
}
|
|
67
|
+
if (typeName === "ZodNativeEnum" || ctor === "ZodNativeEnum") {
|
|
68
|
+
const values = def?.values ? Object.values(def.values) : [];
|
|
69
|
+
return { type: "string", enum: values };
|
|
70
|
+
}
|
|
71
|
+
if (typeName === "ZodLiteral" || ctor === "ZodLiteral") {
|
|
72
|
+
const val = def?.value ?? z.value;
|
|
73
|
+
return { enum: [val] };
|
|
74
|
+
}
|
|
75
|
+
if (typeName === "ZodArray" || ctor === "ZodArray") {
|
|
76
|
+
const inner = def?.type ?? def?.element ?? null;
|
|
77
|
+
const items = inner ? convertZodDef(inner) : { type: "string" };
|
|
78
|
+
return { type: "array", items };
|
|
79
|
+
}
|
|
80
|
+
if (typeName === "ZodObject" || ctor === "ZodObject") {
|
|
81
|
+
let shape;
|
|
82
|
+
try {
|
|
83
|
+
shape = typeof z.shape === "object" ? z.shape : def?.shape?.() ?? def?.shape ?? z._def?.shape?.() ?? void 0;
|
|
84
|
+
if (typeof shape === "function") shape = shape();
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
if (!shape) shape = def?.shape ?? {};
|
|
88
|
+
const properties = {};
|
|
89
|
+
const required = [];
|
|
90
|
+
for (const [k, v] of Object.entries(shape)) {
|
|
91
|
+
const propJson = convertZodDef(v);
|
|
92
|
+
properties[k] = propJson;
|
|
93
|
+
const isOpt = v?._def?.typeName === "ZodOptional" || v?.isOptional?.() === true;
|
|
94
|
+
if (!isOpt) required.push(k);
|
|
95
|
+
const desc = v?.description ?? v?._def?.description;
|
|
96
|
+
if (desc && !properties[k].description) properties[k].description = desc;
|
|
97
|
+
}
|
|
98
|
+
const j = { type: "object", properties, required: required.length ? required : void 0, additionalProperties: false };
|
|
99
|
+
return j;
|
|
100
|
+
}
|
|
101
|
+
if (typeName === "ZodRecord" || ctor === "ZodRecord") {
|
|
102
|
+
return { type: "object", additionalProperties: true };
|
|
103
|
+
}
|
|
104
|
+
if (typeName === "ZodUnion" || ctor === "ZodUnion") {
|
|
105
|
+
const opts = def?.options ?? def?.types ?? [];
|
|
106
|
+
return { anyOf: opts.map((o) => convertZodDef(o)) };
|
|
107
|
+
}
|
|
108
|
+
if (typeName === "ZodDiscriminatedUnion" || ctor === "ZodDiscriminatedUnion") {
|
|
109
|
+
const opts = def?.options ?? [];
|
|
110
|
+
return { anyOf: opts.map((o) => convertZodDef(o)) };
|
|
111
|
+
}
|
|
112
|
+
if (typeName === "ZodIntersection" || ctor === "ZodIntersection") {
|
|
113
|
+
const left = def?.left ?? null;
|
|
114
|
+
const right = def?.right ?? null;
|
|
115
|
+
const all = [left, right].filter(Boolean).map((o) => convertZodDef(o));
|
|
116
|
+
return { allOf: all };
|
|
117
|
+
}
|
|
118
|
+
return { type: "string" };
|
|
119
|
+
}
|
|
120
|
+
function zodLikeToJsonSchema(schema) {
|
|
121
|
+
const anyS = schema;
|
|
122
|
+
if (!anyS || typeof anyS !== "object") return null;
|
|
123
|
+
const hasZodMarker = "_def" in anyS || "_zod" in anyS;
|
|
124
|
+
if (!hasZodMarker) return null;
|
|
125
|
+
try {
|
|
126
|
+
return convertZodDef(anyS);
|
|
127
|
+
} catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
registerZodConverter(zodLikeToJsonSchema);
|
|
132
|
+
var zodToJsonSchema = zodLikeToJsonSchema;
|
|
133
|
+
var zod_default = zodLikeToJsonSchema;
|
|
134
|
+
|
|
135
|
+
export { convertZodDef, zod_default as default, zodLikeToJsonSchema, zodToJsonSchema };
|
|
136
|
+
//# sourceMappingURL=zod.js.map
|
|
137
|
+
//# sourceMappingURL=zod.js.map
|
package/dist/zod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/schema.ts","../src/zod.ts"],"names":[],"mappings":";AAIA,IAAM,iBAAA,GAAoB,6BAAA;AAInB,SAAS,qBAAqB,EAAA,EAAwB;AAC3D,EAAC,UAAA,CAAmB,iBAAiB,CAAA,GAAI,EAAA;AAC3C;;;ACKA,SAAS,cAAc,CAAA,EAAoB;AACzC,EAAA,MAAM,MAAM,CAAA,CAAE,IAAA,IAAQ,EAAE,GAAA,IAAO,CAAA,CAAE,MAAM,GAAA,IAAO,IAAA;AAC9C,EAAA,MAAM,QAAA,GAA+B,KAAK,QAAA,IAAY,CAAA,CAAE,MAAM,MAAA,EAAQ,IAAA,IAAQ,EAAE,QAAA,IAAY,MAAA;AAC5F,EAAA,MAAM,IAAA,GAAO,CAAA,CAAE,WAAA,EAAa,IAAA,IAAQ,EAAA;AAEpC,EAAA,IAAI,QAAA,KAAa,aAAA,IAAiB,IAAA,KAAS,aAAA,EAAe;AACxD,IAAA,MAAM,QAAQ,CAAA,CAAE,MAAA,QAAc,GAAA,EAAK,SAAA,IAAa,KAAK,IAAA,IAAQ,IAAA;AAC7D,IAAA,IAAI,KAAA,EAAO,OAAO,aAAA,CAAc,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,IAAI,QAAA,KAAa,YAAA,IAAgB,IAAA,KAAS,YAAA,EAAc;AACt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,EACtB;AAEA,EAAA,OAAO,EAAE,MAAM,QAAA,EAAS;AAC1B;AAEO,SAAS,oBAAoB,MAAA,EAAoC;AACtE,EAAA,MAAM,IAAA,GAAO,MAAA;AACb,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,UAAU,OAAO,IAAA;AAC9C,EAAA,MAAM,YAAA,GAAe,MAAA,IAAU,IAAA,IAAQ,MAAA,IAAU,IAAA;AACjD,EAAA,IAAI,CAAC,cAAc,OAAO,IAAA;AAC1B,EAAA,IAAI;AACF,IAAA,OAAO,cAAc,IAAI,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAGA,oBAAA,CAAqB,mBAAmB,CAAA;AAIjC,IAAM,eAAA,GAAkB;AAC/B,IAAO,WAAA,GAAQ","file":"zod.js","sourcesContent":["import type { JsonSchema, StandardSchemaV1, FieldDefOrSchema } from '../types.js';\nimport { isStandardSchema, looksLikeJsonSchema } from './utils.js';\n\n// Global registry key for optional Zod converter (split to keep core lean, no hard dep)\nconst ZOD_CONVERTER_KEY = '__simpleWebmcp_zodConverter';\n\ntype ZodConverter = (schema: unknown) => JsonSchema | null;\n\nexport function registerZodConverter(fn: ZodConverter): void {\n (globalThis as any)[ZOD_CONVERTER_KEY] = fn;\n}\n\nfunction getZodConverter(): ZodConverter | null {\n return (globalThis as any)[ZOD_CONVERTER_KEY] ?? null;\n}\n\nfunction zodLikeToJsonSchema(schema: unknown): JsonSchema | null {\n const conv = getZodConverter();\n if (conv) {\n try {\n return conv(schema);\n } catch {\n return null;\n }\n }\n return null;\n}\n\n/**\n * Convert a StandardSchema (maybe Zod) to JSON Schema for WebMCP registration.\n * If conversion fails, returns null → caller uses fallback.\n * Core knows only JSON; Zod support is provided via `import 'simple-webmcp/zod'` which registers converter.\n */\nexport function standardSchemaToJsonSchema(schema: StandardSchemaV1): JsonSchema | null {\n const zodJson = zodLikeToJsonSchema(schema as unknown);\n if (zodJson) return zodJson;\n return null;\n}\n\n/**\n * Convert any `schema` option (JSON Schema or StandardSchema) to JSON Schema.\n * Returns { json, standard } where standard is kept for runtime validation if needed.\n */\nexport function normalizeSchemaInput(\n schema: JsonSchema | StandardSchemaV1 | undefined | null,\n): { json: JsonSchema | null; standard: StandardSchemaV1 | null } {\n if (!schema) return { json: null, standard: null };\n if (looksLikeJsonSchema(schema)) {\n return { json: schema as JsonSchema, standard: null };\n }\n if (isStandardSchema(schema)) {\n const std = schema as StandardSchemaV1;\n const json = standardSchemaToJsonSchema(std);\n return { json, standard: std };\n }\n // If it's a plain object that looks like Zod but without ~standard (older Zod), try convert via registered converter\n const maybeZodJson = zodLikeToJsonSchema(schema as unknown);\n if (maybeZodJson) return { json: maybeZodJson, standard: isStandardSchema(schema) ? (schema as StandardSchemaV1) : null };\n // Unknown — treat as JSON if it has properties, else null\n if (typeof schema === 'object' && schema !== null) {\n // Could be JSON schema without explicit type — treat as json\n return { json: schema as unknown as JsonSchema, standard: null };\n }\n return { json: null, standard: null };\n}\n\n/**\n * Convert a field definition (Partial<JsonSchema> | StandardSchema) to JsonSchema fragment.\n */\nexport function fieldDefToJsonSchema(field: FieldDefOrSchema): JsonSchema {\n if (!field) return {};\n if (isStandardSchema(field)) {\n const json = standardSchemaToJsonSchema(field as StandardSchemaV1);\n if (json) return json;\n // Fallback: unknown standard field → placeholder object\n return { type: 'string' };\n }\n // It's a FieldDef (Partial<JsonSchema>)\n return field as JsonSchema;\n}\n\n/**\n * Merge `fields` patch onto base schema per corrected hierarchy:\n * base = schema (whole) or inferred; fields decorates it.\n */\nexport function applyFieldsPatch(base: JsonSchema, fields?: Record<string, FieldDefOrSchema>): JsonSchema {\n if (!fields || Object.keys(fields).length === 0) return base;\n const result: JsonSchema = {\n ...base,\n properties: { ...(base.properties || {}) },\n required: [...(base.required || [])],\n };\n if (!result.properties) result.properties = {};\n if (!result.required) result.required = [];\n\n for (const [key, field] of Object.entries(fields)) {\n const isStd = isStandardSchema(field);\n if (isStd) {\n const json = standardSchemaToJsonSchema(field as StandardSchemaV1);\n const fragment = json ?? { type: 'string' };\n result.properties[key] = fragment;\n const anyField = field as any;\n const isOpt = anyField?._def?.typeName === 'ZodOptional' || anyField?.isOptional?.() === true;\n if (!isOpt) {\n if (!result.required.includes(key)) result.required.push(key);\n } else {\n result.required = result.required.filter((k) => k !== key);\n }\n const desc = anyField?.description ?? anyField?._def?.description;\n if (desc && !(result.properties[key] as any).description) (result.properties[key] as any).description = desc;\n } else {\n const patch = field as JsonSchema;\n const existing = (result.properties[key] as JsonSchema) || {};\n const merged: JsonSchema = { ...existing, ...patch };\n result.properties[key] = merged;\n if ('required' in patch) {\n const req = (patch as any).required;\n if (req === false) {\n result.required = result.required.filter((k) => k !== key);\n delete (merged as any).required;\n } else if (req === true) {\n if (!result.required.includes(key)) result.required.push(key);\n delete (merged as any).required;\n }\n } else {\n if (!(key in (base.properties || {})) && !(patch as any).required) {\n const hasDefault = 'default' in patch;\n if (!hasDefault && !result.required.includes(key)) result.required.push(key);\n }\n }\n }\n }\n\n if (result.required && result.required.length === 0) delete (result as any).required;\n return result;\n}\n\n/**\n * Build final inputSchema per hierarchy:\n * 1. whole schema (schema) if json available → base\n * 2. else inferred schema\n * 3. then fields patch\n */\nexport function buildFinalInputSchema(opts: {\n wholeSchema?: JsonSchema | StandardSchemaV1;\n inferred: JsonSchema;\n fields?: Record<string, FieldDefOrSchema>;\n}): { json: JsonSchema; standard: StandardSchemaV1 | null } {\n const wholeNorm = normalizeSchemaInput(opts.wholeSchema);\n let baseJson: JsonSchema;\n let standard: StandardSchemaV1 | null = wholeNorm.standard;\n\n if (wholeNorm.json) {\n baseJson = wholeNorm.json;\n } else if (wholeNorm.standard && !wholeNorm.json) {\n baseJson = opts.inferred;\n } else {\n baseJson = opts.inferred;\n }\n\n if (!baseJson.type) baseJson.type = 'object';\n if (!baseJson.properties) baseJson.properties = {};\n if (baseJson.additionalProperties == null) baseJson.additionalProperties = false;\n\n const patched = applyFieldsPatch(baseJson, opts.fields);\n\n return { json: patched, standard };\n}\n\n/**\n * Normalize outputSchema similarly but without fields\n */\nexport function normalizeOutputSchema(schema?: JsonSchema | StandardSchemaV1): { json?: JsonSchema; standard?: StandardSchemaV1 } {\n if (!schema) return {};\n const norm = normalizeSchemaInput(schema);\n if (norm.json) return { json: norm.json, standard: norm.standard ?? undefined };\n if (norm.standard) return { standard: norm.standard };\n return {};\n}\n","/**\n * simple-webmcp/zod — optional Zod → JSON Schema converter\n * Importing this registers a global converter so `webmcp(fn, {schema: z.object(...)})`\n * and per-field `fields: {query: z.string()}` just work without manual conversion.\n *\n * Usage:\n * import 'simple-webmcp/zod'; // side-effect — enables Zod in core\n * import { zodToJsonSchema } from 'simple-webmcp/zod'; // or manual convert\n *\n * Keep this separate from core to hit 3KB gz target (core no Zod).\n */\n\nimport type { JsonSchema } from './types.js';\nimport { registerZodConverter } from './internal/schema.js';\n\nfunction convertZodDef(z: any): JsonSchema {\n const def = z._def ?? z.def ?? z._zod?.def ?? null;\n const typeName: string | undefined = def?.typeName ?? z._zod?.traits?.type ?? z.typeName ?? undefined;\n const ctor = z.constructor?.name || '';\n\n if (typeName === 'ZodOptional' || ctor === 'ZodOptional') {\n const inner = z.unwrap?.() ?? def?.innerType ?? def?.type ?? null;\n if (inner) return convertZodDef(inner);\n }\n if (typeName === 'ZodDefault' || ctor === 'ZodDefault') {\n const inner = def?.innerType ?? z._def?.innerType ?? null;\n const json = inner ? convertZodDef(inner) : ({ type: 'string' } as JsonSchema);\n const defVal = typeof def?.defaultValue === 'function' ? def.defaultValue() : def?.defaultValue;\n if (defVal !== undefined) (json as any).default = defVal;\n return json;\n }\n if (typeName === 'ZodNullable' || ctor === 'ZodNullable') {\n const inner = def?.innerType ?? null;\n const json = inner ? convertZodDef(inner) : ({ type: 'string' } as JsonSchema);\n return json;\n }\n if (typeName === 'ZodEffects' || ctor === 'ZodEffects') {\n const inner = def?.schema ?? null;\n if (inner) return convertZodDef(inner);\n }\n\n if (typeName === 'ZodString' || ctor === 'ZodString') {\n const j: JsonSchema = { type: 'string' };\n if (def?.checks) {\n for (const c of def.checks) {\n if (c.kind === 'min') j.minLength = c.value;\n if (c.kind === 'max') j.maxLength = c.value;\n if (c.kind === 'regex') j.pattern = c.regex?.source;\n if (c.kind === 'email') j.format = 'email';\n if (c.kind === 'url') j.format = 'uri';\n if (c.kind === 'uuid') j.format = 'uuid';\n }\n }\n if (z.description) j.description = z.description;\n else if (def?.description) j.description = def.description;\n return j;\n }\n if (typeName === 'ZodNumber' || ctor === 'ZodNumber') {\n const j: JsonSchema = { type: 'number' };\n if (def?.checks) {\n for (const c of def.checks) {\n if (c.kind === 'min') j.minimum = c.value;\n if (c.kind === 'max') j.maximum = c.value;\n if (c.kind === 'int') j.type = 'integer';\n }\n }\n if (z.description) j.description = z.description;\n return j;\n }\n if (typeName === 'ZodBoolean' || ctor === 'ZodBoolean') return { type: 'boolean' };\n if (typeName === 'ZodBigInt' || ctor === 'ZodBigInt') return { type: 'integer' };\n if (typeName === 'ZodDate' || ctor === 'ZodDate') return { type: 'string', format: 'date-time' };\n if (typeName === 'ZodEnum' || ctor === 'ZodEnum') {\n const values = def?.values ?? z._def?.values ?? z.options ?? [];\n return { type: 'string', enum: values };\n }\n if (typeName === 'ZodNativeEnum' || ctor === 'ZodNativeEnum') {\n const values = def?.values ? Object.values(def.values) : [];\n return { type: 'string', enum: values };\n }\n if (typeName === 'ZodLiteral' || ctor === 'ZodLiteral') {\n const val = def?.value ?? z.value;\n return { enum: [val] };\n }\n if (typeName === 'ZodArray' || ctor === 'ZodArray') {\n const inner = def?.type ?? def?.element ?? null;\n const items = inner ? convertZodDef(inner) : ({ type: 'string' } as JsonSchema);\n return { type: 'array', items };\n }\n if (typeName === 'ZodObject' || ctor === 'ZodObject') {\n let shape: Record<string, any> | undefined;\n try {\n shape = typeof z.shape === 'object' ? z.shape : def?.shape?.() ?? def?.shape ?? z._def?.shape?.() ?? undefined;\n if (typeof shape === 'function') shape = shape();\n } catch {}\n if (!shape) shape = def?.shape ?? {};\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n for (const [k, v] of Object.entries(shape as Record<string, any>)) {\n const propJson = convertZodDef(v);\n properties[k] = propJson;\n const isOpt = (v as any)?._def?.typeName === 'ZodOptional' || (v as any)?.isOptional?.() === true;\n if (!isOpt) required.push(k);\n const desc = (v as any)?.description ?? (v as any)?._def?.description;\n if (desc && !properties[k].description) properties[k].description = desc;\n }\n const j: JsonSchema = { type: 'object', properties, required: required.length ? required : undefined, additionalProperties: false };\n return j;\n }\n if (typeName === 'ZodRecord' || ctor === 'ZodRecord') {\n return { type: 'object', additionalProperties: true };\n }\n if (typeName === 'ZodUnion' || ctor === 'ZodUnion') {\n const opts = def?.options ?? def?.types ?? [];\n return { anyOf: (opts as any[]).map((o) => convertZodDef(o)) };\n }\n if (typeName === 'ZodDiscriminatedUnion' || ctor === 'ZodDiscriminatedUnion') {\n const opts = def?.options ?? [];\n return { anyOf: (opts as any[]).map((o) => convertZodDef(o)) };\n }\n if (typeName === 'ZodIntersection' || ctor === 'ZodIntersection') {\n const left = def?.left ?? null;\n const right = def?.right ?? null;\n const all = [left, right].filter(Boolean).map((o) => convertZodDef(o));\n return { allOf: all };\n }\n\n return { type: 'string' };\n}\n\nexport function zodLikeToJsonSchema(schema: unknown): JsonSchema | null {\n const anyS = schema as any;\n if (!anyS || typeof anyS !== 'object') return null;\n const hasZodMarker = '_def' in anyS || '_zod' in anyS;\n if (!hasZodMarker) return null;\n try {\n return convertZodDef(anyS);\n } catch {\n return null;\n }\n}\n\n// Register globally so core `standardSchemaToJsonSchema` picks it up\nregisterZodConverter(zodLikeToJsonSchema);\n\n// Also export helpers for manual use\nexport { convertZodDef };\nexport const zodToJsonSchema = zodLikeToJsonSchema;\nexport default zodLikeToJsonSchema;\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "simple-webmcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Turn any JS/TS function into a WebMCP tool — function-first, type-safe, lean. One line: webmcp(fn) still callable, auto-registers with React lifecycle or globally.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"webmcp",
|
|
8
|
+
"mcp",
|
|
9
|
+
"ai",
|
|
10
|
+
"tool",
|
|
11
|
+
"sdk",
|
|
12
|
+
"react",
|
|
13
|
+
"nextjs",
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Muhammed Emin Gure",
|
|
18
|
+
"url": "https://github.com/emingure"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/emingure/simple-webmcp.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/emingure/simple-webmcp/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/emingure/simple-webmcp#readme",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./react": {
|
|
36
|
+
"types": "./dist/react.d.ts",
|
|
37
|
+
"import": "./dist/react.js",
|
|
38
|
+
"require": "./dist/react.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./polyfill": {
|
|
41
|
+
"import": "./dist/polyfill.js",
|
|
42
|
+
"require": "./dist/polyfill.cjs"
|
|
43
|
+
},
|
|
44
|
+
"./zod": {
|
|
45
|
+
"types": "./dist/zod.d.ts",
|
|
46
|
+
"import": "./dist/zod.js",
|
|
47
|
+
"require": "./dist/zod.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/index.cjs",
|
|
51
|
+
"module": "./dist/index.js",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"sideEffects": false,
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"README.md",
|
|
57
|
+
"LICENSE",
|
|
58
|
+
".agents/skills"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup",
|
|
62
|
+
"dev": "tsup --watch",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"lint": "eslint src --ext .ts,.tsx || true",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest",
|
|
67
|
+
"coverage": "vitest run --coverage",
|
|
68
|
+
"docs:dev": "vitepress dev docs",
|
|
69
|
+
"docs:build": "vitepress build docs",
|
|
70
|
+
"docs:preview": "vitepress preview docs",
|
|
71
|
+
"prepublishOnly": "npm run build && npm run typecheck && npm test",
|
|
72
|
+
"prepare": "npm run build"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"react": ">=18"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"react": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@testing-library/react": "^14.3.1",
|
|
84
|
+
"@types/node": "^22.7.4",
|
|
85
|
+
"@types/react": "^18.3.12",
|
|
86
|
+
"jsdom": "^25.0.1",
|
|
87
|
+
"react": "^18.3.1",
|
|
88
|
+
"react-dom": "^18.3.1",
|
|
89
|
+
"tsup": "^8.3.5",
|
|
90
|
+
"typescript": "^5.7.2",
|
|
91
|
+
"vitepress": "^1.6.3",
|
|
92
|
+
"vitest": "^3.0.0"
|
|
93
|
+
},
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">=18"
|
|
96
|
+
},
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"access": "public"
|
|
99
|
+
}
|
|
100
|
+
}
|