@vleap/warps-mcp 1.0.0-beta.10

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.
@@ -0,0 +1,48 @@
1
+ import { Warp, WarpClientConfig } from '@vleap/warps';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
3
+
4
+ declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
+
6
+ declare const convertMcpToolToWarp: (config: WarpClientConfig, tool: {
7
+ name: string;
8
+ description?: string;
9
+ inputSchema?: any;
10
+ outputSchema?: any;
11
+ }, url: string, headers?: Record<string, string>) => Promise<Warp>;
12
+ declare const convertWarpToMcpCapabilities: (warp: Warp) => {
13
+ tools: any[];
14
+ resources?: any[];
15
+ };
16
+
17
+ type McpTool = {
18
+ name: string;
19
+ description?: string;
20
+ inputSchema?: any;
21
+ outputSchema?: any;
22
+ };
23
+ type McpResource = {
24
+ name?: string;
25
+ uri: string;
26
+ description?: string;
27
+ mimeType?: string;
28
+ };
29
+ type McpCapabilities = {
30
+ tools?: McpTool[];
31
+ resources?: McpResource[];
32
+ };
33
+ type WarpExecutor = (warp: Warp, inputs: string[]) => Promise<any>;
34
+ type McpServerConfig = {
35
+ name: string;
36
+ version?: string;
37
+ executor?: WarpExecutor;
38
+ };
39
+
40
+ declare const createMcpServerFromWarps: (config: McpServerConfig, warps: Warp[], capabilities: McpCapabilities[], executor?: WarpExecutor) => McpServer;
41
+
42
+ declare class WarpMcp {
43
+ private readonly config;
44
+ constructor(config: WarpClientConfig);
45
+ getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
46
+ }
47
+
48
+ export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, createMcpServerFromWarps };
@@ -0,0 +1,48 @@
1
+ import { Warp, WarpClientConfig } from '@vleap/warps';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
3
+
4
+ declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
+
6
+ declare const convertMcpToolToWarp: (config: WarpClientConfig, tool: {
7
+ name: string;
8
+ description?: string;
9
+ inputSchema?: any;
10
+ outputSchema?: any;
11
+ }, url: string, headers?: Record<string, string>) => Promise<Warp>;
12
+ declare const convertWarpToMcpCapabilities: (warp: Warp) => {
13
+ tools: any[];
14
+ resources?: any[];
15
+ };
16
+
17
+ type McpTool = {
18
+ name: string;
19
+ description?: string;
20
+ inputSchema?: any;
21
+ outputSchema?: any;
22
+ };
23
+ type McpResource = {
24
+ name?: string;
25
+ uri: string;
26
+ description?: string;
27
+ mimeType?: string;
28
+ };
29
+ type McpCapabilities = {
30
+ tools?: McpTool[];
31
+ resources?: McpResource[];
32
+ };
33
+ type WarpExecutor = (warp: Warp, inputs: string[]) => Promise<any>;
34
+ type McpServerConfig = {
35
+ name: string;
36
+ version?: string;
37
+ executor?: WarpExecutor;
38
+ };
39
+
40
+ declare const createMcpServerFromWarps: (config: McpServerConfig, warps: Warp[], capabilities: McpCapabilities[], executor?: WarpExecutor) => McpServer;
41
+
42
+ declare class WarpMcp {
43
+ private readonly config;
44
+ constructor(config: WarpClientConfig);
45
+ getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
46
+ }
47
+
48
+ export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, createMcpServerFromWarps };
package/dist/index.js ADDED
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ WarpMcp: () => WarpMcp,
24
+ convertMcpArgsToWarpInputs: () => convertMcpArgsToWarpInputs,
25
+ convertMcpToolToWarp: () => convertMcpToolToWarp,
26
+ convertWarpToMcpCapabilities: () => convertWarpToMcpCapabilities,
27
+ createMcpServerFromWarps: () => createMcpServerFromWarps
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/helpers/execution.ts
32
+ var import_warps = require("@vleap/warps");
33
+ var convertMcpArgsToWarpInputs = (warp, args) => {
34
+ const { action } = (0, import_warps.getWarpPrimaryAction)(warp);
35
+ if (!action.inputs) return [];
36
+ const serializer = new import_warps.WarpSerializer();
37
+ return action.inputs.map((input) => {
38
+ const key = input.as || input.name;
39
+ const value = args[key] ?? input.default ?? null;
40
+ if (value === null && input.type === "bool") {
41
+ return serializer.nativeToString(input.type, false);
42
+ }
43
+ return serializer.nativeToString(input.type, value);
44
+ });
45
+ };
46
+
47
+ // src/helpers/warps.ts
48
+ var import_warps2 = require("@vleap/warps");
49
+ var import_zod = require("zod");
50
+ var convertMcpToolToWarp = async (config, tool, url, headers) => {
51
+ const inputs = [];
52
+ if (tool.inputSchema?.properties) {
53
+ const properties = tool.inputSchema.properties;
54
+ const required = tool.inputSchema.required || [];
55
+ Object.entries(properties).forEach(([key, value]) => {
56
+ const isRequired = required.includes(key);
57
+ const inputType = convertJsonSchemaTypeToWarpType(value.type, value.format);
58
+ const inputDef = {
59
+ name: key,
60
+ label: value.title || { en: key },
61
+ description: value.description ? { en: value.description.trim() } : null,
62
+ type: inputType,
63
+ position: `payload:${key}`,
64
+ source: "field",
65
+ required: isRequired,
66
+ default: value.default
67
+ };
68
+ inputs.push(inputDef);
69
+ });
70
+ }
71
+ const output = {};
72
+ if (tool.outputSchema?.properties) {
73
+ Object.keys(tool.outputSchema.properties).forEach((key) => {
74
+ output[key] = `out.${key}`;
75
+ });
76
+ }
77
+ const mcpAction = {
78
+ type: "mcp",
79
+ label: { en: tool.name },
80
+ description: tool.description ? { en: tool.description.trim() } : null,
81
+ destination: { url, tool: tool.name, headers },
82
+ inputs
83
+ };
84
+ return await new import_warps2.WarpBuilder(config).setName(tool.name).setTitle({ en: tool.name }).setDescription(tool.description ? { en: tool.description.trim() } : null).addAction(mcpAction).setOutput(Object.keys(output).length > 0 ? output : null).build(false);
85
+ };
86
+ var convertWarpToMcpCapabilities = (warp) => {
87
+ const tools = [];
88
+ const warpDescription = extractText(warp.description);
89
+ let primaryActionInputs;
90
+ try {
91
+ const { action: primaryAction } = (0, import_warps2.getWarpPrimaryAction)(warp);
92
+ primaryActionInputs = primaryAction.inputs;
93
+ console.log(`[MCP] Warp ${warp.name} - primaryActionInputs:`, primaryActionInputs?.length || 0, primaryActionInputs?.map((i) => ({ name: i.name, source: i.source, position: i.position })));
94
+ } catch (error) {
95
+ console.log(`[MCP] Warp ${warp.name} - failed to get primary action:`, error);
96
+ primaryActionInputs = void 0;
97
+ }
98
+ warp.actions.forEach((action, index) => {
99
+ const actionDescription = extractText(action.description);
100
+ const description = warpDescription || actionDescription;
101
+ if (action.type === "mcp") {
102
+ const mcpAction = action;
103
+ if (mcpAction.destination) {
104
+ const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs);
105
+ tools.push(tool);
106
+ }
107
+ } else {
108
+ const tool = convertActionToTool(warp, action, description, index, primaryActionInputs);
109
+ tools.push(tool);
110
+ }
111
+ });
112
+ console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${warp.name}, tools: ${tools.length}, tools with schema:`, tools.filter((t) => t.inputSchema).length);
113
+ return { tools, resources: [] };
114
+ };
115
+ var extractText = (text) => {
116
+ if (!text) return void 0;
117
+ if (typeof text === "string") return text;
118
+ if (typeof text === "object" && "en" in text) return text.en;
119
+ return void 0;
120
+ };
121
+ var buildZodSchemaFromInput = (input) => {
122
+ let schema;
123
+ const inputType = input.type.toLowerCase();
124
+ if (inputType === "string" || inputType === "address" || inputType === "hex") {
125
+ schema = import_zod.z.string();
126
+ } else if (inputType === "number" || inputType === "uint8" || inputType === "uint16" || inputType === "uint32" || inputType === "uint64" || inputType === "uint128" || inputType === "uint256") {
127
+ schema = import_zod.z.number();
128
+ } else if (inputType === "bool" || inputType === "boolean") {
129
+ schema = import_zod.z.boolean();
130
+ } else if (inputType === "biguint") {
131
+ schema = import_zod.z.string();
132
+ } else {
133
+ schema = import_zod.z.string();
134
+ }
135
+ if (typeof input.min === "number") {
136
+ if (schema instanceof import_zod.z.ZodNumber) {
137
+ schema = schema.min(input.min);
138
+ }
139
+ }
140
+ if (typeof input.max === "number") {
141
+ if (schema instanceof import_zod.z.ZodNumber) {
142
+ schema = schema.max(input.max);
143
+ }
144
+ }
145
+ if (input.pattern) {
146
+ if (schema instanceof import_zod.z.ZodString) {
147
+ schema = schema.regex(new RegExp(input.pattern));
148
+ }
149
+ }
150
+ const enumValues = extractEnumValues(input.options);
151
+ if (enumValues && enumValues.length > 0) {
152
+ if (schema instanceof import_zod.z.ZodString) {
153
+ schema = import_zod.z.enum(enumValues);
154
+ } else if (schema instanceof import_zod.z.ZodNumber) {
155
+ const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v));
156
+ if (numberValues.length > 0) {
157
+ schema = schema.refine((val) => numberValues.includes(val), {
158
+ message: `Value must be one of: ${numberValues.join(", ")}`
159
+ });
160
+ }
161
+ }
162
+ }
163
+ const descriptionParts = [];
164
+ const inputDescription = extractText(input.description);
165
+ if (inputDescription) {
166
+ descriptionParts.push(inputDescription);
167
+ }
168
+ if (input.bot) {
169
+ descriptionParts.push(input.bot);
170
+ }
171
+ descriptionParts.push(`Type: ${input.type}`);
172
+ descriptionParts.push(input.required ? "Required" : "Optional");
173
+ if (enumValues && enumValues.length > 0) {
174
+ descriptionParts.push(`Options: ${enumValues.join(", ")}`);
175
+ }
176
+ const patternDesc = extractText(input.patternDescription);
177
+ if (patternDesc) {
178
+ descriptionParts.push(patternDesc);
179
+ }
180
+ const fullDescription = descriptionParts.join(". ");
181
+ if (fullDescription) {
182
+ schema = schema.describe(fullDescription);
183
+ }
184
+ if (input.required !== true) {
185
+ schema = schema.optional();
186
+ }
187
+ return schema;
188
+ };
189
+ var buildZodInputSchema = (inputs) => {
190
+ const shape = {};
191
+ for (const input of inputs) {
192
+ if (input.source === "hidden") continue;
193
+ if (input.source !== "field") continue;
194
+ const key = input.as || input.name;
195
+ shape[key] = buildZodSchemaFromInput(input);
196
+ }
197
+ console.log("[MCP] buildZodInputSchema - inputs:", inputs.length, "shape keys:", Object.keys(shape));
198
+ return Object.keys(shape).length > 0 ? shape : void 0;
199
+ };
200
+ var convertActionToTool = (warp, action, description, index, primaryActionInputs) => {
201
+ const inputsToUse = primaryActionInputs || action.inputs || [];
202
+ const inputSchema = buildZodInputSchema(inputsToUse);
203
+ const name = sanitizeMcpName(`${warp.name}_${index}`);
204
+ console.log(`[MCP] convertActionToTool - tool: ${name}, inputsToUse: ${inputsToUse.length}, inputSchema keys:`, inputSchema ? Object.keys(inputSchema) : "undefined");
205
+ return {
206
+ name,
207
+ description,
208
+ inputSchema
209
+ };
210
+ };
211
+ var convertMcpActionToTool = (action, description, primaryActionInputs) => {
212
+ const inputsToUse = primaryActionInputs || action.inputs || [];
213
+ const inputSchema = buildZodInputSchema(inputsToUse);
214
+ const toolName = action.destination.tool;
215
+ return {
216
+ name: sanitizeMcpName(toolName),
217
+ description,
218
+ inputSchema
219
+ };
220
+ };
221
+ var extractEnumValues = (options) => {
222
+ if (!options) return void 0;
223
+ if (Array.isArray(options)) return options;
224
+ if (typeof options === "object") return Object.keys(options);
225
+ return void 0;
226
+ };
227
+ var sanitizeMcpName = (name) => {
228
+ return name.replace(/\s+/g, "_").replace(/:/g, "_").replace(/[^A-Za-z0-9_.-]/g, "_").replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, "").replace(/_+/g, "_");
229
+ };
230
+ var convertJsonSchemaTypeToWarpType = (type, format) => {
231
+ if (format === "date-time" || format === "date") return "string";
232
+ if (type === "string") return "string";
233
+ if (type === "number") return "uint256";
234
+ if (type === "integer") return "uint256";
235
+ if (type === "boolean") return "bool";
236
+ if (type === "array") return "string";
237
+ if (type === "object") return "string";
238
+ return "string";
239
+ };
240
+
241
+ // src/server.ts
242
+ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp");
243
+ var import_zod_compat = require("@modelcontextprotocol/sdk/server/zod-compat");
244
+ var processInputSchema = (inputSchema) => {
245
+ if (!inputSchema) return void 0;
246
+ if (inputSchema._zod) return inputSchema._zod;
247
+ return (0, import_zod_compat.normalizeObjectSchema)(inputSchema) || inputSchema;
248
+ };
249
+ var createMcpServerFromWarps = (config, warps, capabilities, executor) => {
250
+ const server = new import_mcp.McpServer({ name: config.name, version: config.version || "1.0.0" });
251
+ const defaultExecutor = config.executor || executor;
252
+ for (let i = 0; i < capabilities.length; i++) {
253
+ const { tools, resources } = capabilities[i];
254
+ const warp = warps[i];
255
+ tools?.forEach((tool) => {
256
+ const inputSchema = processInputSchema(tool.inputSchema);
257
+ server.registerTool(tool.name, { description: tool.description || "", inputSchema }, async (args) => {
258
+ if (defaultExecutor) {
259
+ const inputs = convertMcpArgsToWarpInputs(warp, args || {});
260
+ const result = await defaultExecutor(warp, inputs);
261
+ return result;
262
+ }
263
+ return { content: [{ type: "text", text: `Tool ${tool.name} executed successfully` }] };
264
+ });
265
+ });
266
+ resources?.forEach((resource) => {
267
+ server.registerResource(
268
+ resource.name || resource.uri,
269
+ resource.uri,
270
+ { description: resource.description, mimeType: resource.mimeType },
271
+ async () => ({
272
+ contents: [{ uri: resource.uri, mimeType: resource.mimeType || "text/plain", text: "Resource content" }]
273
+ })
274
+ );
275
+ });
276
+ }
277
+ return server;
278
+ };
279
+
280
+ // src/WarpMcp.ts
281
+ var import_client = require("@modelcontextprotocol/sdk/client/index");
282
+ var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp");
283
+ var WarpMcp = class {
284
+ constructor(config) {
285
+ this.config = config;
286
+ }
287
+ async getWarpsFromTools(url, headers) {
288
+ const transport = new import_streamableHttp.StreamableHTTPClientTransport(new URL(url), {
289
+ requestInit: { headers: headers || {} }
290
+ });
291
+ const client = new import_client.Client({ name: "warps-mcp-client", version: "1.0.0" }, { capabilities: {} });
292
+ try {
293
+ await client.connect(transport);
294
+ const tools = await client.listTools();
295
+ await client.close();
296
+ return await Promise.all(tools.tools.map((tool) => convertMcpToolToWarp(this.config, tool, url, headers)));
297
+ } catch (error) {
298
+ await client.close().catch(() => {
299
+ });
300
+ throw error;
301
+ }
302
+ }
303
+ };
304
+ // Annotate the CommonJS export names for ESM import in node:
305
+ 0 && (module.exports = {
306
+ WarpMcp,
307
+ convertMcpArgsToWarpInputs,
308
+ convertMcpToolToWarp,
309
+ convertWarpToMcpCapabilities,
310
+ createMcpServerFromWarps
311
+ });
312
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/helpers/execution.ts","../src/helpers/warps.ts","../src/server.ts","../src/WarpMcp.ts"],"sourcesContent":["export * from './helpers/index'\nexport * from './server'\nexport * from './types'\nexport * from './WarpMcp'\n","import { getWarpPrimaryAction, Warp, WarpActionInput, WarpSerializer } from '@vleap/warps'\n\nexport const convertMcpArgsToWarpInputs = (warp: Warp, args: Record<string, any>): string[] => {\n const { action } = getWarpPrimaryAction(warp)\n if (!action.inputs) return []\n\n const serializer = new WarpSerializer()\n return action.inputs.map((input: WarpActionInput) => {\n const key = input.as || input.name\n const value = args[key] ?? input.default ?? null\n\n if (value === null && input.type === 'bool') {\n return serializer.nativeToString(input.type, false)\n }\n\n return serializer.nativeToString(input.type, value)\n })\n}\n","import {\n Warp,\n WarpActionInput,\n WarpActionInputType,\n WarpBuilder,\n WarpClientConfig,\n WarpCollectAction,\n WarpContractAction,\n WarpMcpAction,\n WarpQueryAction,\n WarpText,\n WarpTransferAction,\n getWarpPrimaryAction,\n} from '@vleap/warps'\nimport { z } from 'zod'\n\nexport const convertMcpToolToWarp = async (\n config: WarpClientConfig,\n tool: { name: string; description?: string; inputSchema?: any; outputSchema?: any },\n url: string,\n headers?: Record<string, string>\n): Promise<Warp> => {\n const inputs: WarpActionInput[] = []\n\n if (tool.inputSchema?.properties) {\n const properties = tool.inputSchema.properties\n const required = tool.inputSchema.required || []\n\n Object.entries(properties).forEach(([key, value]: [string, any]) => {\n const isRequired = required.includes(key)\n const inputType = convertJsonSchemaTypeToWarpType(value.type, value.format)\n\n const inputDef: WarpActionInput = {\n name: key,\n label: value.title || { en: key },\n description: value.description ? { en: value.description.trim() } : null,\n type: inputType,\n position: `payload:${key}`,\n source: 'field',\n required: isRequired,\n default: value.default,\n }\n\n inputs.push(inputDef)\n })\n }\n\n const output: Record<string, string> = {}\n if (tool.outputSchema?.properties) {\n Object.keys(tool.outputSchema.properties).forEach((key) => {\n output[key] = `out.${key}`\n })\n }\n\n const mcpAction: WarpMcpAction = {\n type: 'mcp',\n label: { en: tool.name },\n description: tool.description ? { en: tool.description.trim() } : null,\n destination: { url, tool: tool.name, headers },\n inputs,\n }\n\n return await new WarpBuilder(config)\n .setName(tool.name)\n .setTitle({ en: tool.name })\n .setDescription(tool.description ? { en: tool.description.trim() } : null)\n .addAction(mcpAction)\n .setOutput(Object.keys(output).length > 0 ? output : null)\n .build(false)\n}\n\nexport const convertWarpToMcpCapabilities = (warp: Warp): { tools: any[]; resources?: any[] } => {\n const tools: any[] = []\n const warpDescription = extractText(warp.description)\n\n let primaryActionInputs: WarpActionInput[] | undefined\n try {\n const { action: primaryAction } = getWarpPrimaryAction(warp)\n primaryActionInputs = primaryAction.inputs\n console.log(`[MCP] Warp ${warp.name} - primaryActionInputs:`, primaryActionInputs?.length || 0, primaryActionInputs?.map(i => ({ name: i.name, source: i.source, position: i.position })))\n } catch (error) {\n console.log(`[MCP] Warp ${warp.name} - failed to get primary action:`, error)\n primaryActionInputs = undefined\n }\n\n warp.actions.forEach((action, index) => {\n const actionDescription = extractText(action.description)\n const description = warpDescription || actionDescription\n\n if (action.type === 'mcp') {\n const mcpAction = action as WarpMcpAction\n if (mcpAction.destination) {\n const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs)\n tools.push(tool)\n }\n } else {\n const tool = convertActionToTool(warp, action, description, index, primaryActionInputs)\n tools.push(tool)\n }\n })\n\n console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${warp.name}, tools: ${tools.length}, tools with schema:`, tools.filter(t => t.inputSchema).length)\n return { tools, resources: [] }\n}\n\nconst extractText = (text: WarpText | null | undefined): string | undefined => {\n if (!text) return undefined\n if (typeof text === 'string') return text\n if (typeof text === 'object' && 'en' in text) return text.en\n return undefined\n}\n\nconst buildZodSchemaFromInput = (input: WarpActionInput): z.ZodTypeAny => {\n let schema: z.ZodTypeAny\n\n const inputType = input.type.toLowerCase()\n if (inputType === 'string' || inputType === 'address' || inputType === 'hex') {\n schema = z.string()\n } else if (\n inputType === 'number' ||\n inputType === 'uint8' ||\n inputType === 'uint16' ||\n inputType === 'uint32' ||\n inputType === 'uint64' ||\n inputType === 'uint128' ||\n inputType === 'uint256'\n ) {\n schema = z.number()\n } else if (inputType === 'bool' || inputType === 'boolean') {\n schema = z.boolean()\n } else if (inputType === 'biguint') {\n schema = z.string()\n } else {\n schema = z.string()\n }\n\n if (typeof input.min === 'number') {\n if (schema instanceof z.ZodNumber) {\n schema = schema.min(input.min)\n }\n }\n\n if (typeof input.max === 'number') {\n if (schema instanceof z.ZodNumber) {\n schema = schema.max(input.max)\n }\n }\n\n if (input.pattern) {\n if (schema instanceof z.ZodString) {\n schema = schema.regex(new RegExp(input.pattern))\n }\n }\n\n const enumValues = extractEnumValues(input.options)\n if (enumValues && enumValues.length > 0) {\n if (schema instanceof z.ZodString) {\n schema = z.enum(enumValues as [string, ...string[]])\n } else if (schema instanceof z.ZodNumber) {\n const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v))\n if (numberValues.length > 0) {\n schema = schema.refine((val) => numberValues.includes(val), {\n message: `Value must be one of: ${numberValues.join(', ')}`,\n })\n }\n }\n }\n\n const descriptionParts: string[] = []\n const inputDescription = extractText(input.description)\n if (inputDescription) {\n descriptionParts.push(inputDescription)\n }\n\n if (input.bot) {\n descriptionParts.push(input.bot)\n }\n\n descriptionParts.push(`Type: ${input.type}`)\n descriptionParts.push(input.required ? 'Required' : 'Optional')\n\n if (enumValues && enumValues.length > 0) {\n descriptionParts.push(`Options: ${enumValues.join(', ')}`)\n }\n\n const patternDesc = extractText(input.patternDescription)\n if (patternDesc) {\n descriptionParts.push(patternDesc)\n }\n\n const fullDescription = descriptionParts.join('. ')\n if (fullDescription) {\n schema = schema.describe(fullDescription)\n }\n\n if (input.required !== true) {\n schema = schema.optional()\n }\n\n return schema\n}\n\nconst buildZodInputSchema = (inputs: WarpActionInput[]): Record<string, z.ZodTypeAny> | undefined => {\n const shape: Record<string, z.ZodTypeAny> = {}\n\n for (const input of inputs) {\n if (input.source === 'hidden') continue\n if (input.source !== 'field') continue\n\n const key = input.as || input.name\n shape[key] = buildZodSchemaFromInput(input)\n }\n\n console.log('[MCP] buildZodInputSchema - inputs:', inputs.length, 'shape keys:', Object.keys(shape))\n return Object.keys(shape).length > 0 ? shape : undefined\n}\n\nconst convertActionToTool = (\n warp: Warp,\n action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction,\n description: string | undefined,\n index: number,\n primaryActionInputs?: WarpActionInput[]\n): any => {\n const inputsToUse = primaryActionInputs || action.inputs || []\n const inputSchema = buildZodInputSchema(inputsToUse)\n const name = sanitizeMcpName(`${warp.name}_${index}`)\n\n console.log(`[MCP] convertActionToTool - tool: ${name}, inputsToUse: ${inputsToUse.length}, inputSchema keys:`, inputSchema ? Object.keys(inputSchema) : 'undefined')\n\n return {\n name,\n description,\n inputSchema,\n }\n}\n\nconst convertMcpActionToTool = (action: WarpMcpAction, description: string | undefined, primaryActionInputs?: WarpActionInput[]): any => {\n const inputsToUse = primaryActionInputs || action.inputs || []\n const inputSchema = buildZodInputSchema(inputsToUse)\n const toolName = action.destination!.tool\n\n return {\n name: sanitizeMcpName(toolName),\n description,\n inputSchema,\n }\n}\n\n\nconst extractEnumValues = (options: string[] | { [key: string]: WarpText } | undefined): string[] | undefined => {\n if (!options) return undefined\n if (Array.isArray(options)) return options\n if (typeof options === 'object') return Object.keys(options)\n return undefined\n}\n\nconst sanitizeMcpName = (name: string): string => {\n return name\n .replace(/\\s+/g, '_')\n .replace(/:/g, '_')\n .replace(/[^A-Za-z0-9_.-]/g, '_')\n .replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, '')\n .replace(/_+/g, '_')\n}\n\nconst convertJsonSchemaTypeToWarpType = (type: string, format?: string): WarpActionInputType => {\n if (format === 'date-time' || format === 'date') return 'string'\n if (type === 'string') return 'string'\n if (type === 'number') return 'uint256'\n if (type === 'integer') return 'uint256'\n if (type === 'boolean') return 'bool'\n if (type === 'array') return 'string'\n if (type === 'object') return 'string'\n return 'string'\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp'\nimport { normalizeObjectSchema } from '@modelcontextprotocol/sdk/server/zod-compat'\nimport { Warp } from '@vleap/warps'\nimport { convertMcpArgsToWarpInputs } from './helpers/execution'\nimport { McpCapabilities, McpServerConfig, WarpExecutor } from './types'\n\nconst processInputSchema = (inputSchema: any): any => {\n if (!inputSchema) return undefined\n if (inputSchema._zod) return inputSchema._zod\n return normalizeObjectSchema(inputSchema) || inputSchema\n}\n\nexport const createMcpServerFromWarps = (\n config: McpServerConfig,\n warps: Warp[],\n capabilities: McpCapabilities[],\n executor?: WarpExecutor\n): McpServer => {\n const server = new McpServer({ name: config.name, version: config.version || '1.0.0' })\n const defaultExecutor = config.executor || executor\n\n for (let i = 0; i < capabilities.length; i++) {\n const { tools, resources } = capabilities[i]\n const warp = warps[i]\n\n tools?.forEach((tool) => {\n const inputSchema = processInputSchema(tool.inputSchema)\n server.registerTool(tool.name, { description: tool.description || '', inputSchema }, async (args: any) => {\n if (defaultExecutor) {\n const inputs = convertMcpArgsToWarpInputs(warp, args || {})\n const result = await defaultExecutor(warp, inputs)\n return result\n }\n return { content: [{ type: 'text' as const, text: `Tool ${tool.name} executed successfully` }] }\n })\n })\n\n resources?.forEach((resource) => {\n server.registerResource(\n resource.name || resource.uri,\n resource.uri,\n { description: resource.description, mimeType: resource.mimeType },\n async () => ({\n contents: [{ uri: resource.uri, mimeType: resource.mimeType || 'text/plain', text: 'Resource content' }],\n })\n )\n })\n }\n\n return server\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp'\nimport { Warp, WarpClientConfig } from '@vleap/warps'\nimport { convertMcpToolToWarp } from './helpers/warps'\n\nexport class WarpMcp {\n constructor(private readonly config: WarpClientConfig) {}\n\n async getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]> {\n const transport = new StreamableHTTPClientTransport(new URL(url), {\n requestInit: { headers: headers || {} },\n })\n\n const client = new Client({ name: 'warps-mcp-client', version: '1.0.0' }, { capabilities: {} })\n\n try {\n await client.connect(transport)\n\n const tools = await client.listTools()\n\n await client.close()\n\n return await Promise.all(tools.tools.map((tool) => convertMcpToolToWarp(this.config, tool, url, headers)))\n } catch (error) {\n await client.close().catch(() => {})\n throw error\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4E;AAErE,IAAM,6BAA6B,CAAC,MAAY,SAAwC;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2
+ import { getWarpPrimaryAction, WarpSerializer } from "@vleap/warps";
3
+ var convertMcpArgsToWarpInputs = (warp, args) => {
4
+ const { action } = getWarpPrimaryAction(warp);
5
+ if (!action.inputs) return [];
6
+ const serializer = new WarpSerializer();
7
+ return action.inputs.map((input) => {
8
+ const key = input.as || input.name;
9
+ const value = args[key] ?? input.default ?? null;
10
+ if (value === null && input.type === "bool") {
11
+ return serializer.nativeToString(input.type, false);
12
+ }
13
+ return serializer.nativeToString(input.type, value);
14
+ });
15
+ };
16
+
17
+ // src/helpers/warps.ts
18
+ import {
19
+ WarpBuilder,
20
+ getWarpPrimaryAction as getWarpPrimaryAction2
21
+ } from "@vleap/warps";
22
+ import { z } from "zod";
23
+ var convertMcpToolToWarp = async (config, tool, url, headers) => {
24
+ const inputs = [];
25
+ if (tool.inputSchema?.properties) {
26
+ const properties = tool.inputSchema.properties;
27
+ const required = tool.inputSchema.required || [];
28
+ Object.entries(properties).forEach(([key, value]) => {
29
+ const isRequired = required.includes(key);
30
+ const inputType = convertJsonSchemaTypeToWarpType(value.type, value.format);
31
+ const inputDef = {
32
+ name: key,
33
+ label: value.title || { en: key },
34
+ description: value.description ? { en: value.description.trim() } : null,
35
+ type: inputType,
36
+ position: `payload:${key}`,
37
+ source: "field",
38
+ required: isRequired,
39
+ default: value.default
40
+ };
41
+ inputs.push(inputDef);
42
+ });
43
+ }
44
+ const output = {};
45
+ if (tool.outputSchema?.properties) {
46
+ Object.keys(tool.outputSchema.properties).forEach((key) => {
47
+ output[key] = `out.${key}`;
48
+ });
49
+ }
50
+ const mcpAction = {
51
+ type: "mcp",
52
+ label: { en: tool.name },
53
+ description: tool.description ? { en: tool.description.trim() } : null,
54
+ destination: { url, tool: tool.name, headers },
55
+ inputs
56
+ };
57
+ return await new WarpBuilder(config).setName(tool.name).setTitle({ en: tool.name }).setDescription(tool.description ? { en: tool.description.trim() } : null).addAction(mcpAction).setOutput(Object.keys(output).length > 0 ? output : null).build(false);
58
+ };
59
+ var convertWarpToMcpCapabilities = (warp) => {
60
+ const tools = [];
61
+ const warpDescription = extractText(warp.description);
62
+ let primaryActionInputs;
63
+ try {
64
+ const { action: primaryAction } = getWarpPrimaryAction2(warp);
65
+ primaryActionInputs = primaryAction.inputs;
66
+ console.log(`[MCP] Warp ${warp.name} - primaryActionInputs:`, primaryActionInputs?.length || 0, primaryActionInputs?.map((i) => ({ name: i.name, source: i.source, position: i.position })));
67
+ } catch (error) {
68
+ console.log(`[MCP] Warp ${warp.name} - failed to get primary action:`, error);
69
+ primaryActionInputs = void 0;
70
+ }
71
+ warp.actions.forEach((action, index) => {
72
+ const actionDescription = extractText(action.description);
73
+ const description = warpDescription || actionDescription;
74
+ if (action.type === "mcp") {
75
+ const mcpAction = action;
76
+ if (mcpAction.destination) {
77
+ const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs);
78
+ tools.push(tool);
79
+ }
80
+ } else {
81
+ const tool = convertActionToTool(warp, action, description, index, primaryActionInputs);
82
+ tools.push(tool);
83
+ }
84
+ });
85
+ console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${warp.name}, tools: ${tools.length}, tools with schema:`, tools.filter((t) => t.inputSchema).length);
86
+ return { tools, resources: [] };
87
+ };
88
+ var extractText = (text) => {
89
+ if (!text) return void 0;
90
+ if (typeof text === "string") return text;
91
+ if (typeof text === "object" && "en" in text) return text.en;
92
+ return void 0;
93
+ };
94
+ var buildZodSchemaFromInput = (input) => {
95
+ let schema;
96
+ const inputType = input.type.toLowerCase();
97
+ if (inputType === "string" || inputType === "address" || inputType === "hex") {
98
+ schema = z.string();
99
+ } else if (inputType === "number" || inputType === "uint8" || inputType === "uint16" || inputType === "uint32" || inputType === "uint64" || inputType === "uint128" || inputType === "uint256") {
100
+ schema = z.number();
101
+ } else if (inputType === "bool" || inputType === "boolean") {
102
+ schema = z.boolean();
103
+ } else if (inputType === "biguint") {
104
+ schema = z.string();
105
+ } else {
106
+ schema = z.string();
107
+ }
108
+ if (typeof input.min === "number") {
109
+ if (schema instanceof z.ZodNumber) {
110
+ schema = schema.min(input.min);
111
+ }
112
+ }
113
+ if (typeof input.max === "number") {
114
+ if (schema instanceof z.ZodNumber) {
115
+ schema = schema.max(input.max);
116
+ }
117
+ }
118
+ if (input.pattern) {
119
+ if (schema instanceof z.ZodString) {
120
+ schema = schema.regex(new RegExp(input.pattern));
121
+ }
122
+ }
123
+ const enumValues = extractEnumValues(input.options);
124
+ if (enumValues && enumValues.length > 0) {
125
+ if (schema instanceof z.ZodString) {
126
+ schema = z.enum(enumValues);
127
+ } else if (schema instanceof z.ZodNumber) {
128
+ const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v));
129
+ if (numberValues.length > 0) {
130
+ schema = schema.refine((val) => numberValues.includes(val), {
131
+ message: `Value must be one of: ${numberValues.join(", ")}`
132
+ });
133
+ }
134
+ }
135
+ }
136
+ const descriptionParts = [];
137
+ const inputDescription = extractText(input.description);
138
+ if (inputDescription) {
139
+ descriptionParts.push(inputDescription);
140
+ }
141
+ if (input.bot) {
142
+ descriptionParts.push(input.bot);
143
+ }
144
+ descriptionParts.push(`Type: ${input.type}`);
145
+ descriptionParts.push(input.required ? "Required" : "Optional");
146
+ if (enumValues && enumValues.length > 0) {
147
+ descriptionParts.push(`Options: ${enumValues.join(", ")}`);
148
+ }
149
+ const patternDesc = extractText(input.patternDescription);
150
+ if (patternDesc) {
151
+ descriptionParts.push(patternDesc);
152
+ }
153
+ const fullDescription = descriptionParts.join(". ");
154
+ if (fullDescription) {
155
+ schema = schema.describe(fullDescription);
156
+ }
157
+ if (input.required !== true) {
158
+ schema = schema.optional();
159
+ }
160
+ return schema;
161
+ };
162
+ var buildZodInputSchema = (inputs) => {
163
+ const shape = {};
164
+ for (const input of inputs) {
165
+ if (input.source === "hidden") continue;
166
+ if (input.source !== "field") continue;
167
+ const key = input.as || input.name;
168
+ shape[key] = buildZodSchemaFromInput(input);
169
+ }
170
+ console.log("[MCP] buildZodInputSchema - inputs:", inputs.length, "shape keys:", Object.keys(shape));
171
+ return Object.keys(shape).length > 0 ? shape : void 0;
172
+ };
173
+ var convertActionToTool = (warp, action, description, index, primaryActionInputs) => {
174
+ const inputsToUse = primaryActionInputs || action.inputs || [];
175
+ const inputSchema = buildZodInputSchema(inputsToUse);
176
+ const name = sanitizeMcpName(`${warp.name}_${index}`);
177
+ console.log(`[MCP] convertActionToTool - tool: ${name}, inputsToUse: ${inputsToUse.length}, inputSchema keys:`, inputSchema ? Object.keys(inputSchema) : "undefined");
178
+ return {
179
+ name,
180
+ description,
181
+ inputSchema
182
+ };
183
+ };
184
+ var convertMcpActionToTool = (action, description, primaryActionInputs) => {
185
+ const inputsToUse = primaryActionInputs || action.inputs || [];
186
+ const inputSchema = buildZodInputSchema(inputsToUse);
187
+ const toolName = action.destination.tool;
188
+ return {
189
+ name: sanitizeMcpName(toolName),
190
+ description,
191
+ inputSchema
192
+ };
193
+ };
194
+ var extractEnumValues = (options) => {
195
+ if (!options) return void 0;
196
+ if (Array.isArray(options)) return options;
197
+ if (typeof options === "object") return Object.keys(options);
198
+ return void 0;
199
+ };
200
+ var sanitizeMcpName = (name) => {
201
+ return name.replace(/\s+/g, "_").replace(/:/g, "_").replace(/[^A-Za-z0-9_.-]/g, "_").replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, "").replace(/_+/g, "_");
202
+ };
203
+ var convertJsonSchemaTypeToWarpType = (type, format) => {
204
+ if (format === "date-time" || format === "date") return "string";
205
+ if (type === "string") return "string";
206
+ if (type === "number") return "uint256";
207
+ if (type === "integer") return "uint256";
208
+ if (type === "boolean") return "bool";
209
+ if (type === "array") return "string";
210
+ if (type === "object") return "string";
211
+ return "string";
212
+ };
213
+
214
+ // src/server.ts
215
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
216
+ import { normalizeObjectSchema } from "@modelcontextprotocol/sdk/server/zod-compat";
217
+ var processInputSchema = (inputSchema) => {
218
+ if (!inputSchema) return void 0;
219
+ if (inputSchema._zod) return inputSchema._zod;
220
+ return normalizeObjectSchema(inputSchema) || inputSchema;
221
+ };
222
+ var createMcpServerFromWarps = (config, warps, capabilities, executor) => {
223
+ const server = new McpServer({ name: config.name, version: config.version || "1.0.0" });
224
+ const defaultExecutor = config.executor || executor;
225
+ for (let i = 0; i < capabilities.length; i++) {
226
+ const { tools, resources } = capabilities[i];
227
+ const warp = warps[i];
228
+ tools?.forEach((tool) => {
229
+ const inputSchema = processInputSchema(tool.inputSchema);
230
+ server.registerTool(tool.name, { description: tool.description || "", inputSchema }, async (args) => {
231
+ if (defaultExecutor) {
232
+ const inputs = convertMcpArgsToWarpInputs(warp, args || {});
233
+ const result = await defaultExecutor(warp, inputs);
234
+ return result;
235
+ }
236
+ return { content: [{ type: "text", text: `Tool ${tool.name} executed successfully` }] };
237
+ });
238
+ });
239
+ resources?.forEach((resource) => {
240
+ server.registerResource(
241
+ resource.name || resource.uri,
242
+ resource.uri,
243
+ { description: resource.description, mimeType: resource.mimeType },
244
+ async () => ({
245
+ contents: [{ uri: resource.uri, mimeType: resource.mimeType || "text/plain", text: "Resource content" }]
246
+ })
247
+ );
248
+ });
249
+ }
250
+ return server;
251
+ };
252
+
253
+ // src/WarpMcp.ts
254
+ import { Client } from "@modelcontextprotocol/sdk/client/index";
255
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp";
256
+ var WarpMcp = class {
257
+ constructor(config) {
258
+ this.config = config;
259
+ }
260
+ async getWarpsFromTools(url, headers) {
261
+ const transport = new StreamableHTTPClientTransport(new URL(url), {
262
+ requestInit: { headers: headers || {} }
263
+ });
264
+ const client = new Client({ name: "warps-mcp-client", version: "1.0.0" }, { capabilities: {} });
265
+ try {
266
+ await client.connect(transport);
267
+ const tools = await client.listTools();
268
+ await client.close();
269
+ return await Promise.all(tools.tools.map((tool) => convertMcpToolToWarp(this.config, tool, url, headers)));
270
+ } catch (error) {
271
+ await client.close().catch(() => {
272
+ });
273
+ throw error;
274
+ }
275
+ }
276
+ };
277
+ export {
278
+ WarpMcp,
279
+ convertMcpArgsToWarpInputs,
280
+ convertMcpToolToWarp,
281
+ convertWarpToMcpCapabilities,
282
+ createMcpServerFromWarps
283
+ };
284
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/execution.ts","../src/helpers/warps.ts","../src/server.ts","../src/WarpMcp.ts"],"sourcesContent":["import { getWarpPrimaryAction, Warp, WarpActionInput, WarpSerializer } from '@vleap/warps'\n\nexport const convertMcpArgsToWarpInputs = (warp: Warp, args: Record<string, any>): string[] => {\n const { action } = getWarpPrimaryAction(warp)\n if (!action.inputs) return []\n\n const serializer = new WarpSerializer()\n return action.inputs.map((input: WarpActionInput) => {\n const key = input.as || input.name\n const value = args[key] ?? input.default ?? null\n\n if (value === null && input.type === 'bool') {\n return serializer.nativeToString(input.type, false)\n }\n\n return serializer.nativeToString(input.type, value)\n })\n}\n","import {\n Warp,\n WarpActionInput,\n WarpActionInputType,\n WarpBuilder,\n WarpClientConfig,\n WarpCollectAction,\n WarpContractAction,\n WarpMcpAction,\n WarpQueryAction,\n WarpText,\n WarpTransferAction,\n getWarpPrimaryAction,\n} from '@vleap/warps'\nimport { z } from 'zod'\n\nexport const convertMcpToolToWarp = async (\n config: WarpClientConfig,\n tool: { name: string; description?: string; inputSchema?: any; outputSchema?: any },\n url: string,\n headers?: Record<string, string>\n): Promise<Warp> => {\n const inputs: WarpActionInput[] = []\n\n if (tool.inputSchema?.properties) {\n const properties = tool.inputSchema.properties\n const required = tool.inputSchema.required || []\n\n Object.entries(properties).forEach(([key, value]: [string, any]) => {\n const isRequired = required.includes(key)\n const inputType = convertJsonSchemaTypeToWarpType(value.type, value.format)\n\n const inputDef: WarpActionInput = {\n name: key,\n label: value.title || { en: key },\n description: value.description ? { en: value.description.trim() } : null,\n type: inputType,\n position: `payload:${key}`,\n source: 'field',\n required: isRequired,\n default: value.default,\n }\n\n inputs.push(inputDef)\n })\n }\n\n const output: Record<string, string> = {}\n if (tool.outputSchema?.properties) {\n Object.keys(tool.outputSchema.properties).forEach((key) => {\n output[key] = `out.${key}`\n })\n }\n\n const mcpAction: WarpMcpAction = {\n type: 'mcp',\n label: { en: tool.name },\n description: tool.description ? { en: tool.description.trim() } : null,\n destination: { url, tool: tool.name, headers },\n inputs,\n }\n\n return await new WarpBuilder(config)\n .setName(tool.name)\n .setTitle({ en: tool.name })\n .setDescription(tool.description ? { en: tool.description.trim() } : null)\n .addAction(mcpAction)\n .setOutput(Object.keys(output).length > 0 ? output : null)\n .build(false)\n}\n\nexport const convertWarpToMcpCapabilities = (warp: Warp): { tools: any[]; resources?: any[] } => {\n const tools: any[] = []\n const warpDescription = extractText(warp.description)\n\n let primaryActionInputs: WarpActionInput[] | undefined\n try {\n const { action: primaryAction } = getWarpPrimaryAction(warp)\n primaryActionInputs = primaryAction.inputs\n console.log(`[MCP] Warp ${warp.name} - primaryActionInputs:`, primaryActionInputs?.length || 0, primaryActionInputs?.map(i => ({ name: i.name, source: i.source, position: i.position })))\n } catch (error) {\n console.log(`[MCP] Warp ${warp.name} - failed to get primary action:`, error)\n primaryActionInputs = undefined\n }\n\n warp.actions.forEach((action, index) => {\n const actionDescription = extractText(action.description)\n const description = warpDescription || actionDescription\n\n if (action.type === 'mcp') {\n const mcpAction = action as WarpMcpAction\n if (mcpAction.destination) {\n const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs)\n tools.push(tool)\n }\n } else {\n const tool = convertActionToTool(warp, action, description, index, primaryActionInputs)\n tools.push(tool)\n }\n })\n\n console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${warp.name}, tools: ${tools.length}, tools with schema:`, tools.filter(t => t.inputSchema).length)\n return { tools, resources: [] }\n}\n\nconst extractText = (text: WarpText | null | undefined): string | undefined => {\n if (!text) return undefined\n if (typeof text === 'string') return text\n if (typeof text === 'object' && 'en' in text) return text.en\n return undefined\n}\n\nconst buildZodSchemaFromInput = (input: WarpActionInput): z.ZodTypeAny => {\n let schema: z.ZodTypeAny\n\n const inputType = input.type.toLowerCase()\n if (inputType === 'string' || inputType === 'address' || inputType === 'hex') {\n schema = z.string()\n } else if (\n inputType === 'number' ||\n inputType === 'uint8' ||\n inputType === 'uint16' ||\n inputType === 'uint32' ||\n inputType === 'uint64' ||\n inputType === 'uint128' ||\n inputType === 'uint256'\n ) {\n schema = z.number()\n } else if (inputType === 'bool' || inputType === 'boolean') {\n schema = z.boolean()\n } else if (inputType === 'biguint') {\n schema = z.string()\n } else {\n schema = z.string()\n }\n\n if (typeof input.min === 'number') {\n if (schema instanceof z.ZodNumber) {\n schema = schema.min(input.min)\n }\n }\n\n if (typeof input.max === 'number') {\n if (schema instanceof z.ZodNumber) {\n schema = schema.max(input.max)\n }\n }\n\n if (input.pattern) {\n if (schema instanceof z.ZodString) {\n schema = schema.regex(new RegExp(input.pattern))\n }\n }\n\n const enumValues = extractEnumValues(input.options)\n if (enumValues && enumValues.length > 0) {\n if (schema instanceof z.ZodString) {\n schema = z.enum(enumValues as [string, ...string[]])\n } else if (schema instanceof z.ZodNumber) {\n const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v))\n if (numberValues.length > 0) {\n schema = schema.refine((val) => numberValues.includes(val), {\n message: `Value must be one of: ${numberValues.join(', ')}`,\n })\n }\n }\n }\n\n const descriptionParts: string[] = []\n const inputDescription = extractText(input.description)\n if (inputDescription) {\n descriptionParts.push(inputDescription)\n }\n\n if (input.bot) {\n descriptionParts.push(input.bot)\n }\n\n descriptionParts.push(`Type: ${input.type}`)\n descriptionParts.push(input.required ? 'Required' : 'Optional')\n\n if (enumValues && enumValues.length > 0) {\n descriptionParts.push(`Options: ${enumValues.join(', ')}`)\n }\n\n const patternDesc = extractText(input.patternDescription)\n if (patternDesc) {\n descriptionParts.push(patternDesc)\n }\n\n const fullDescription = descriptionParts.join('. ')\n if (fullDescription) {\n schema = schema.describe(fullDescription)\n }\n\n if (input.required !== true) {\n schema = schema.optional()\n }\n\n return schema\n}\n\nconst buildZodInputSchema = (inputs: WarpActionInput[]): Record<string, z.ZodTypeAny> | undefined => {\n const shape: Record<string, z.ZodTypeAny> = {}\n\n for (const input of inputs) {\n if (input.source === 'hidden') continue\n if (input.source !== 'field') continue\n\n const key = input.as || input.name\n shape[key] = buildZodSchemaFromInput(input)\n }\n\n console.log('[MCP] buildZodInputSchema - inputs:', inputs.length, 'shape keys:', Object.keys(shape))\n return Object.keys(shape).length > 0 ? shape : undefined\n}\n\nconst convertActionToTool = (\n warp: Warp,\n action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction,\n description: string | undefined,\n index: number,\n primaryActionInputs?: WarpActionInput[]\n): any => {\n const inputsToUse = primaryActionInputs || action.inputs || []\n const inputSchema = buildZodInputSchema(inputsToUse)\n const name = sanitizeMcpName(`${warp.name}_${index}`)\n\n console.log(`[MCP] convertActionToTool - tool: ${name}, inputsToUse: ${inputsToUse.length}, inputSchema keys:`, inputSchema ? Object.keys(inputSchema) : 'undefined')\n\n return {\n name,\n description,\n inputSchema,\n }\n}\n\nconst convertMcpActionToTool = (action: WarpMcpAction, description: string | undefined, primaryActionInputs?: WarpActionInput[]): any => {\n const inputsToUse = primaryActionInputs || action.inputs || []\n const inputSchema = buildZodInputSchema(inputsToUse)\n const toolName = action.destination!.tool\n\n return {\n name: sanitizeMcpName(toolName),\n description,\n inputSchema,\n }\n}\n\n\nconst extractEnumValues = (options: string[] | { [key: string]: WarpText } | undefined): string[] | undefined => {\n if (!options) return undefined\n if (Array.isArray(options)) return options\n if (typeof options === 'object') return Object.keys(options)\n return undefined\n}\n\nconst sanitizeMcpName = (name: string): string => {\n return name\n .replace(/\\s+/g, '_')\n .replace(/:/g, '_')\n .replace(/[^A-Za-z0-9_.-]/g, '_')\n .replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, '')\n .replace(/_+/g, '_')\n}\n\nconst convertJsonSchemaTypeToWarpType = (type: string, format?: string): WarpActionInputType => {\n if (format === 'date-time' || format === 'date') return 'string'\n if (type === 'string') return 'string'\n if (type === 'number') return 'uint256'\n if (type === 'integer') return 'uint256'\n if (type === 'boolean') return 'bool'\n if (type === 'array') return 'string'\n if (type === 'object') return 'string'\n return 'string'\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp'\nimport { normalizeObjectSchema } from '@modelcontextprotocol/sdk/server/zod-compat'\nimport { Warp } from '@vleap/warps'\nimport { convertMcpArgsToWarpInputs } from './helpers/execution'\nimport { McpCapabilities, McpServerConfig, WarpExecutor } from './types'\n\nconst processInputSchema = (inputSchema: any): any => {\n if (!inputSchema) return undefined\n if (inputSchema._zod) return inputSchema._zod\n return normalizeObjectSchema(inputSchema) || inputSchema\n}\n\nexport const createMcpServerFromWarps = (\n config: McpServerConfig,\n warps: Warp[],\n capabilities: McpCapabilities[],\n executor?: WarpExecutor\n): McpServer => {\n const server = new McpServer({ name: config.name, version: config.version || '1.0.0' })\n const defaultExecutor = config.executor || executor\n\n for (let i = 0; i < capabilities.length; i++) {\n const { tools, resources } = capabilities[i]\n const warp = warps[i]\n\n tools?.forEach((tool) => {\n const inputSchema = processInputSchema(tool.inputSchema)\n server.registerTool(tool.name, { description: tool.description || '', inputSchema }, async (args: any) => {\n if (defaultExecutor) {\n const inputs = convertMcpArgsToWarpInputs(warp, args || {})\n const result = await defaultExecutor(warp, inputs)\n return result\n }\n return { content: [{ type: 'text' as const, text: `Tool ${tool.name} executed successfully` }] }\n })\n })\n\n resources?.forEach((resource) => {\n server.registerResource(\n resource.name || resource.uri,\n resource.uri,\n { description: resource.description, mimeType: resource.mimeType },\n async () => ({\n contents: [{ uri: resource.uri, mimeType: resource.mimeType || 'text/plain', text: 'Resource content' }],\n })\n )\n })\n }\n\n return server\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp'\nimport { Warp, WarpClientConfig } from '@vleap/warps'\nimport { convertMcpToolToWarp } from './helpers/warps'\n\nexport class WarpMcp {\n constructor(private readonly config: WarpClientConfig) {}\n\n async getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]> {\n const transport = new StreamableHTTPClientTransport(new URL(url), {\n requestInit: { headers: headers || {} },\n })\n\n const client = new Client({ name: 'warps-mcp-client', version: '1.0.0' }, { capabilities: {} })\n\n try {\n await client.connect(transport)\n\n const tools = await client.listTools()\n\n await client.close()\n\n return await Promise.all(tools.tools.map((tool) => convertMcpToolToWarp(this.config, tool, url, headers)))\n } catch (error) {\n await client.close().catch(() => {})\n throw error\n }\n }\n}\n"],"mappings":";AAAA,SAAS,sBAA6C,sBAAsB;AAErE,IAAM,6BAA6B,CAAC,MAAY,SAAwC;AAC7F,QAAM,EAAE,OAAO,IAAI,qBAAqB,IAAI;AAC5C,MAAI,CAAC,OAAO,OAAQ,QAAO,CAAC;AAE5B,QAAM,aAAa,IAAI,eAAe;AACtC,SAAO,OAAO,OAAO,IAAI,CAAC,UAA2B;AACnD,UAAM,MAAM,MAAM,MAAM,MAAM;AAC9B,UAAM,QAAQ,KAAK,GAAG,KAAK,MAAM,WAAW;AAE5C,QAAI,UAAU,QAAQ,MAAM,SAAS,QAAQ;AAC3C,aAAO,WAAW,eAAe,MAAM,MAAM,KAAK;AAAA,IACpD;AAEA,WAAO,WAAW,eAAe,MAAM,MAAM,KAAK;AAAA,EACpD,CAAC;AACH;;;ACjBA;AAAA,EAIE;AAAA,EAQA,wBAAAA;AAAA,OACK;AACP,SAAS,SAAS;AAEX,IAAM,uBAAuB,OAClC,QACA,MACA,KACA,YACkB;AAClB,QAAM,SAA4B,CAAC;AAEnC,MAAI,KAAK,aAAa,YAAY;AAChC,UAAM,aAAa,KAAK,YAAY;AACpC,UAAM,WAAW,KAAK,YAAY,YAAY,CAAC;AAE/C,WAAO,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAqB;AAClE,YAAM,aAAa,SAAS,SAAS,GAAG;AACxC,YAAM,YAAY,gCAAgC,MAAM,MAAM,MAA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AAoB,SAAS,QAAQ,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC;AAE9F,QAAI;AACF,YAAM,OAAO,QAAQ,SAAS;AAE9B,YAAM,QAAQ,MAAM,OAAO,UAAU;AAErC,YAAM,OAAO,MAAM;AAEnB,aAAO,MAAM,QAAQ,IAAI,MAAM,MAAM,IAAI,CAAC,SAAS,qBAAqB,KAAK,QAAQ,MAAM,KAAK,OAAO,CAAC,CAAC;AAAA,IAC3G,SAAS,OAAO;AACd,YAAM,OAAO,MAAM,EAAE,MAAM,MAAM;AAAA,MAAC,CAAC;AACnC,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["getWarpPrimaryAction"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@vleap/warps-mcp",
3
+ "version": "1.0.0-beta.10",
4
+ "description": "MCP adapter for Warps SDK",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsup",
17
+ "test": "jest --config jest.config.mjs",
18
+ "lint": "tsc --noEmit",
19
+ "prepare": "npm run build",
20
+ "preversion": "npm run lint && npm run build"
21
+ },
22
+ "author": "",
23
+ "license": "MIT",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "devDependencies": {
28
+ "@types/jest": "^30.0.0",
29
+ "jest": "^30.2.0",
30
+ "jest-environment-jsdom": "^30.2.0",
31
+ "ts-jest": "^29.4.6",
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^5.9.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "@modelcontextprotocol/sdk": "^1.24.3",
40
+ "zod": "^4.1.13"
41
+ },
42
+ "peerDependencies": {
43
+ "@vleap/warps": "^3.0.0-beta.172"
44
+ }
45
+ }