@vleap/warps-mcp 1.0.0-beta.8 → 1.0.0-beta.9
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/index.js +96 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/helpers/warps.ts
|
|
30
30
|
var import_warps = require("@vleap/warps");
|
|
31
|
+
var import_zod = require("zod");
|
|
31
32
|
var convertMcpToolToWarp = async (config, tool, url, headers) => {
|
|
32
33
|
const inputs = [];
|
|
33
34
|
if (tool.inputSchema?.properties) {
|
|
@@ -67,17 +68,24 @@ var convertMcpToolToWarp = async (config, tool, url, headers) => {
|
|
|
67
68
|
var convertWarpToMcpCapabilities = (warp) => {
|
|
68
69
|
const tools = [];
|
|
69
70
|
const warpDescription = extractText(warp.description);
|
|
71
|
+
let primaryActionInputs;
|
|
72
|
+
try {
|
|
73
|
+
const { action: primaryAction } = (0, import_warps.getWarpPrimaryAction)(warp);
|
|
74
|
+
primaryActionInputs = primaryAction.inputs;
|
|
75
|
+
} catch {
|
|
76
|
+
primaryActionInputs = void 0;
|
|
77
|
+
}
|
|
70
78
|
warp.actions.forEach((action, index) => {
|
|
71
79
|
const actionDescription = extractText(action.description);
|
|
72
80
|
const description = warpDescription || actionDescription;
|
|
73
81
|
if (action.type === "mcp") {
|
|
74
82
|
const mcpAction = action;
|
|
75
83
|
if (mcpAction.destination) {
|
|
76
|
-
const tool = convertMcpActionToTool(mcpAction, description);
|
|
84
|
+
const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs);
|
|
77
85
|
tools.push(tool);
|
|
78
86
|
}
|
|
79
87
|
} else {
|
|
80
|
-
const tool = convertActionToTool(warp, action, description, index);
|
|
88
|
+
const tool = convertActionToTool(warp, action, description, index, primaryActionInputs);
|
|
81
89
|
tools.push(tool);
|
|
82
90
|
}
|
|
83
91
|
});
|
|
@@ -89,97 +97,113 @@ var extractText = (text) => {
|
|
|
89
97
|
if (typeof text === "object" && "en" in text) return text.en;
|
|
90
98
|
return void 0;
|
|
91
99
|
};
|
|
92
|
-
var
|
|
93
|
-
|
|
100
|
+
var buildZodSchemaFromInput = (input) => {
|
|
101
|
+
let schema;
|
|
102
|
+
const inputType = input.type.toLowerCase();
|
|
103
|
+
if (inputType === "string" || inputType === "address" || inputType === "hex") {
|
|
104
|
+
schema = import_zod.z.string();
|
|
105
|
+
} else if (inputType === "number" || inputType === "uint8" || inputType === "uint16" || inputType === "uint32" || inputType === "uint64" || inputType === "uint128" || inputType === "uint256") {
|
|
106
|
+
schema = import_zod.z.number();
|
|
107
|
+
} else if (inputType === "bool" || inputType === "boolean") {
|
|
108
|
+
schema = import_zod.z.boolean();
|
|
109
|
+
} else if (inputType === "biguint") {
|
|
110
|
+
schema = import_zod.z.string();
|
|
111
|
+
} else {
|
|
112
|
+
schema = import_zod.z.string();
|
|
113
|
+
}
|
|
114
|
+
if (typeof input.min === "number") {
|
|
115
|
+
if (schema instanceof import_zod.z.ZodNumber) {
|
|
116
|
+
schema = schema.min(input.min);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (typeof input.max === "number") {
|
|
120
|
+
if (schema instanceof import_zod.z.ZodNumber) {
|
|
121
|
+
schema = schema.max(input.max);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (input.pattern) {
|
|
125
|
+
if (schema instanceof import_zod.z.ZodString) {
|
|
126
|
+
schema = schema.regex(new RegExp(input.pattern));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const enumValues = extractEnumValues(input.options);
|
|
130
|
+
if (enumValues && enumValues.length > 0) {
|
|
131
|
+
if (schema instanceof import_zod.z.ZodString) {
|
|
132
|
+
schema = import_zod.z.enum(enumValues);
|
|
133
|
+
} else if (schema instanceof import_zod.z.ZodNumber) {
|
|
134
|
+
const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v));
|
|
135
|
+
if (numberValues.length > 0) {
|
|
136
|
+
schema = schema.refine((val) => numberValues.includes(val), {
|
|
137
|
+
message: `Value must be one of: ${numberValues.join(", ")}`
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const descriptionParts = [];
|
|
143
|
+
const inputDescription = extractText(input.description);
|
|
144
|
+
if (inputDescription) {
|
|
145
|
+
descriptionParts.push(inputDescription);
|
|
146
|
+
}
|
|
147
|
+
if (input.bot) {
|
|
148
|
+
descriptionParts.push(input.bot);
|
|
149
|
+
}
|
|
150
|
+
descriptionParts.push(`Type: ${input.type}`);
|
|
151
|
+
descriptionParts.push(input.required ? "Required" : "Optional");
|
|
152
|
+
if (enumValues && enumValues.length > 0) {
|
|
153
|
+
descriptionParts.push(`Options: ${enumValues.join(", ")}`);
|
|
154
|
+
}
|
|
155
|
+
const patternDesc = extractText(input.patternDescription);
|
|
156
|
+
if (patternDesc) {
|
|
157
|
+
descriptionParts.push(patternDesc);
|
|
158
|
+
}
|
|
159
|
+
const fullDescription = descriptionParts.join(". ");
|
|
160
|
+
if (fullDescription) {
|
|
161
|
+
schema = schema.describe(fullDescription);
|
|
162
|
+
}
|
|
163
|
+
if (input.required !== true) {
|
|
164
|
+
schema = schema.optional();
|
|
165
|
+
}
|
|
166
|
+
return schema;
|
|
167
|
+
};
|
|
168
|
+
var buildZodInputSchema = (inputs) => {
|
|
169
|
+
const shape = {};
|
|
170
|
+
for (const input of inputs) {
|
|
171
|
+
if (input.source === "hidden") continue;
|
|
172
|
+
if (!isPayloadInput(input)) continue;
|
|
173
|
+
const key = input.as || input.name;
|
|
174
|
+
shape[key] = buildZodSchemaFromInput(input);
|
|
175
|
+
}
|
|
176
|
+
return Object.keys(shape).length > 0 ? shape : void 0;
|
|
177
|
+
};
|
|
178
|
+
var convertActionToTool = (warp, action, description, index, primaryActionInputs) => {
|
|
179
|
+
const inputsToUse = primaryActionInputs || action.inputs || [];
|
|
180
|
+
const inputSchema = buildZodInputSchema(inputsToUse);
|
|
94
181
|
const name = sanitizeMcpName(`${warp.name}_${index}`);
|
|
95
182
|
return {
|
|
96
183
|
name,
|
|
97
184
|
description,
|
|
98
|
-
inputSchema
|
|
185
|
+
inputSchema
|
|
99
186
|
};
|
|
100
187
|
};
|
|
101
|
-
var convertMcpActionToTool = (action, description) => {
|
|
102
|
-
const
|
|
188
|
+
var convertMcpActionToTool = (action, description, primaryActionInputs) => {
|
|
189
|
+
const inputsToUse = primaryActionInputs || action.inputs || [];
|
|
190
|
+
const inputSchema = buildZodInputSchema(inputsToUse);
|
|
103
191
|
const toolName = action.destination.tool;
|
|
104
192
|
return {
|
|
105
193
|
name: sanitizeMcpName(toolName),
|
|
106
194
|
description,
|
|
107
|
-
inputSchema
|
|
195
|
+
inputSchema
|
|
108
196
|
};
|
|
109
197
|
};
|
|
110
|
-
var buildInputSchema = (inputs) => {
|
|
111
|
-
const schema = {
|
|
112
|
-
type: "object",
|
|
113
|
-
properties: {},
|
|
114
|
-
required: []
|
|
115
|
-
};
|
|
116
|
-
inputs.forEach((input) => {
|
|
117
|
-
if (!isPayloadInput(input)) return;
|
|
118
|
-
const key = extractPayloadKey(input.position);
|
|
119
|
-
const property = buildPropertySchema(input);
|
|
120
|
-
schema.properties[key] = property;
|
|
121
|
-
if (input.required) {
|
|
122
|
-
schema.required.push(key);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return schema;
|
|
126
|
-
};
|
|
127
198
|
var isPayloadInput = (input) => {
|
|
128
199
|
return typeof input.position === "string" && input.position.startsWith("payload:");
|
|
129
200
|
};
|
|
130
|
-
var extractPayloadKey = (position) => {
|
|
131
|
-
return position.replace("payload:", "");
|
|
132
|
-
};
|
|
133
|
-
var buildPropertySchema = (input) => {
|
|
134
|
-
const jsonSchemaType = convertWarpTypeToJsonSchemaType(input.type);
|
|
135
|
-
const property = {
|
|
136
|
-
type: jsonSchemaType.type
|
|
137
|
-
};
|
|
138
|
-
if (jsonSchemaType.format) {
|
|
139
|
-
property.format = jsonSchemaType.format;
|
|
140
|
-
}
|
|
141
|
-
const title = extractText(input.label) || input.name;
|
|
142
|
-
if (title) {
|
|
143
|
-
property.title = title;
|
|
144
|
-
}
|
|
145
|
-
const description = buildDescription(input);
|
|
146
|
-
if (description) {
|
|
147
|
-
property.description = description;
|
|
148
|
-
}
|
|
149
|
-
if (input.default !== void 0) {
|
|
150
|
-
property.default = input.default;
|
|
151
|
-
}
|
|
152
|
-
if (typeof input.min === "number") {
|
|
153
|
-
property.minimum = input.min;
|
|
154
|
-
}
|
|
155
|
-
if (typeof input.max === "number") {
|
|
156
|
-
property.maximum = input.max;
|
|
157
|
-
}
|
|
158
|
-
if (input.pattern) {
|
|
159
|
-
property.pattern = input.pattern;
|
|
160
|
-
}
|
|
161
|
-
const enumValues = extractEnumValues(input.options);
|
|
162
|
-
if (enumValues) {
|
|
163
|
-
property.enum = enumValues;
|
|
164
|
-
}
|
|
165
|
-
return property;
|
|
166
|
-
};
|
|
167
|
-
var buildDescription = (input) => {
|
|
168
|
-
const description = extractText(input.description);
|
|
169
|
-
const patternDesc = extractText(input.patternDescription);
|
|
170
|
-
if (!description && !patternDesc) return void 0;
|
|
171
|
-
if (description && patternDesc) return `${description}. ${patternDesc}`;
|
|
172
|
-
return description || patternDesc;
|
|
173
|
-
};
|
|
174
201
|
var extractEnumValues = (options) => {
|
|
175
202
|
if (!options) return void 0;
|
|
176
203
|
if (Array.isArray(options)) return options;
|
|
177
204
|
if (typeof options === "object") return Object.keys(options);
|
|
178
205
|
return void 0;
|
|
179
206
|
};
|
|
180
|
-
var hasProperties = (schema) => {
|
|
181
|
-
return schema && schema.properties && Object.keys(schema.properties).length > 0;
|
|
182
|
-
};
|
|
183
207
|
var sanitizeMcpName = (name) => {
|
|
184
208
|
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, "_");
|
|
185
209
|
};
|
|
@@ -193,15 +217,6 @@ var convertJsonSchemaTypeToWarpType = (type, format) => {
|
|
|
193
217
|
if (type === "object") return "string";
|
|
194
218
|
return "string";
|
|
195
219
|
};
|
|
196
|
-
var convertWarpTypeToJsonSchemaType = (warpType) => {
|
|
197
|
-
if (warpType === "string") return { type: "string" };
|
|
198
|
-
if (warpType === "bool") return { type: "boolean" };
|
|
199
|
-
if (warpType === "uint8" || warpType === "uint16" || warpType === "uint32" || warpType === "uint64" || warpType === "uint128" || warpType === "uint256" || warpType === "biguint") {
|
|
200
|
-
return { type: "integer" };
|
|
201
|
-
}
|
|
202
|
-
if (warpType === "number") return { type: "number" };
|
|
203
|
-
return { type: "string" };
|
|
204
|
-
};
|
|
205
220
|
|
|
206
221
|
// src/WarpMcp.ts
|
|
207
222
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/helpers/warps.ts","../src/WarpMcp.ts"],"sourcesContent":["export * from './helpers'\nexport * from './WarpMcp'\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} from '@vleap/warps'\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[] } => {\n const tools: any[] = []\n const warpDescription = extractText(warp.description)\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)\n tools.push(tool)\n }\n } else {\n const tool = convertActionToTool(warp, action, description, index)\n tools.push(tool)\n }\n })\n\n return { tools }\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 convertActionToTool = (\n warp: Warp,\n action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction,\n description: string | undefined,\n index: number\n): any => {\n const inputSchema = buildInputSchema(action.inputs || [])\n const name = sanitizeMcpName(`${warp.name}_${index}`)\n\n return {\n name,\n description,\n inputSchema: hasProperties(inputSchema) ? inputSchema : undefined,\n }\n}\n\nconst convertMcpActionToTool = (action: WarpMcpAction, description: string | undefined): any => {\n const inputSchema = buildInputSchema(action.inputs || [])\n const toolName = action.destination!.tool\n\n return {\n name: sanitizeMcpName(toolName),\n description,\n inputSchema: hasProperties(inputSchema) ? inputSchema : undefined,\n }\n}\n\nconst buildInputSchema = (inputs: WarpActionInput[]): any => {\n const schema: any = {\n type: 'object',\n properties: {},\n required: [],\n }\n\n inputs.forEach((input) => {\n if (!isPayloadInput(input)) return\n\n const key = extractPayloadKey(input.position as string)\n const property = buildPropertySchema(input)\n\n schema.properties[key] = property\n\n if (input.required) {\n schema.required.push(key)\n }\n })\n\n return schema\n}\n\nconst isPayloadInput = (input: WarpActionInput): boolean => {\n return typeof input.position === 'string' && input.position.startsWith('payload:')\n}\n\nconst extractPayloadKey = (position: string): string => {\n return position.replace('payload:', '')\n}\n\nconst buildPropertySchema = (input: WarpActionInput): any => {\n const jsonSchemaType = convertWarpTypeToJsonSchemaType(input.type)\n const property: any = {\n type: jsonSchemaType.type,\n }\n\n if (jsonSchemaType.format) {\n property.format = jsonSchemaType.format\n }\n\n const title = extractText(input.label) || input.name\n if (title) {\n property.title = title\n }\n\n const description = buildDescription(input)\n if (description) {\n property.description = description\n }\n\n if (input.default !== undefined) {\n property.default = input.default\n }\n\n if (typeof input.min === 'number') {\n property.minimum = input.min\n }\n\n if (typeof input.max === 'number') {\n property.maximum = input.max\n }\n\n if (input.pattern) {\n property.pattern = input.pattern\n }\n\n const enumValues = extractEnumValues(input.options)\n if (enumValues) {\n property.enum = enumValues\n }\n\n return property\n}\n\nconst buildDescription = (input: WarpActionInput): string | undefined => {\n const description = extractText(input.description)\n const patternDesc = extractText(input.patternDescription)\n\n if (!description && !patternDesc) return undefined\n if (description && patternDesc) return `${description}. ${patternDesc}`\n return description || patternDesc\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 hasProperties = (schema: any): boolean => {\n return schema && schema.properties && Object.keys(schema.properties).length > 0\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\nconst convertWarpTypeToJsonSchemaType = (warpType: string): { type: string; format?: string } => {\n if (warpType === 'string') return { type: 'string' }\n if (warpType === 'bool') return { type: 'boolean' }\n if (\n warpType === 'uint8' ||\n warpType === 'uint16' ||\n warpType === 'uint32' ||\n warpType === 'uint64' ||\n warpType === 'uint128' ||\n warpType === 'uint256' ||\n warpType === 'biguint'\n ) {\n return { type: 'integer' }\n }\n if (warpType === 'number') return { type: 'number' }\n return { type: 'string' }\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\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":";;;;;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T;AAEA,IAAM,kCAAkC,CAAC,aAAwD;AAC/F,MAAI,aAAa,SAAU,QAAO,EAAE,MAAM,SAAS;AACnD,MAAI,aAAa,OAAQ,QAAO,EAAE,MAAM,UAAU;AAClD,MACE,aAAa,WACb,aAAa,YACb,aAAa,YACb,aAAa,YACb,aAAa,aACb,aAAa,aACb,aAAa,WACb;AACA,WAAO,EAAE,MAAM,UAAU;AAAA,EAC3B;AACA,MAAI,aAAa,SAAU,QAAO,EAAE,MAAM,SAAS;AACnD,SAAO,EAAE,MAAM,SAAS;AAC1B;;;ACjQA,oBAAuB;AACvB,4BAA8C;AAIvC,IAAM,UAAN,MAAc;AAAA,EACnB,YAA6B,QAA0B;AAA1B;AAAA,EAA2B;AAAA,EAExD,MAAM,kBAAkB,KAAa,SAAmD;AACtF,UAAM,YAAY,IAAI,oDAA8B,IAAI,IAAI,GAAG,GAAG;AAAA,MAChE,aAAa,EAAE,SAAS,WAAW,CAAC,EAAE;AAAA,IACxC,CAAC;AAED,UAAM,SAAS,IAAI,qBAAO,EAAE,MAAM,oBAAoB,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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/helpers/warps.ts","../src/WarpMcp.ts"],"sourcesContent":["export * from './helpers'\nexport * from './WarpMcp'\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[] } => {\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 } catch {\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 return { tools }\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 (!isPayloadInput(input)) continue\n\n const key = input.as || input.name\n shape[key] = buildZodSchemaFromInput(input)\n }\n\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 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\nconst isPayloadInput = (input: WarpActionInput): boolean => {\n return typeof input.position === 'string' && input.position.startsWith('payload:')\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 { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\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;;;ACAA,mBAaO;AACP,iBAAkB;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,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,MAAM,EAAE,MAAM,MAAM;AAAA,MAAC,CAAC;AACnC,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/helpers/warps.ts
|
|
2
2
|
import {
|
|
3
|
-
WarpBuilder
|
|
3
|
+
WarpBuilder,
|
|
4
|
+
getWarpPrimaryAction
|
|
4
5
|
} from "@vleap/warps";
|
|
6
|
+
import { z } from "zod";
|
|
5
7
|
var convertMcpToolToWarp = async (config, tool, url, headers) => {
|
|
6
8
|
const inputs = [];
|
|
7
9
|
if (tool.inputSchema?.properties) {
|
|
@@ -41,17 +43,24 @@ var convertMcpToolToWarp = async (config, tool, url, headers) => {
|
|
|
41
43
|
var convertWarpToMcpCapabilities = (warp) => {
|
|
42
44
|
const tools = [];
|
|
43
45
|
const warpDescription = extractText(warp.description);
|
|
46
|
+
let primaryActionInputs;
|
|
47
|
+
try {
|
|
48
|
+
const { action: primaryAction } = getWarpPrimaryAction(warp);
|
|
49
|
+
primaryActionInputs = primaryAction.inputs;
|
|
50
|
+
} catch {
|
|
51
|
+
primaryActionInputs = void 0;
|
|
52
|
+
}
|
|
44
53
|
warp.actions.forEach((action, index) => {
|
|
45
54
|
const actionDescription = extractText(action.description);
|
|
46
55
|
const description = warpDescription || actionDescription;
|
|
47
56
|
if (action.type === "mcp") {
|
|
48
57
|
const mcpAction = action;
|
|
49
58
|
if (mcpAction.destination) {
|
|
50
|
-
const tool = convertMcpActionToTool(mcpAction, description);
|
|
59
|
+
const tool = convertMcpActionToTool(mcpAction, description, primaryActionInputs);
|
|
51
60
|
tools.push(tool);
|
|
52
61
|
}
|
|
53
62
|
} else {
|
|
54
|
-
const tool = convertActionToTool(warp, action, description, index);
|
|
63
|
+
const tool = convertActionToTool(warp, action, description, index, primaryActionInputs);
|
|
55
64
|
tools.push(tool);
|
|
56
65
|
}
|
|
57
66
|
});
|
|
@@ -63,97 +72,113 @@ var extractText = (text) => {
|
|
|
63
72
|
if (typeof text === "object" && "en" in text) return text.en;
|
|
64
73
|
return void 0;
|
|
65
74
|
};
|
|
66
|
-
var
|
|
67
|
-
|
|
75
|
+
var buildZodSchemaFromInput = (input) => {
|
|
76
|
+
let schema;
|
|
77
|
+
const inputType = input.type.toLowerCase();
|
|
78
|
+
if (inputType === "string" || inputType === "address" || inputType === "hex") {
|
|
79
|
+
schema = z.string();
|
|
80
|
+
} else if (inputType === "number" || inputType === "uint8" || inputType === "uint16" || inputType === "uint32" || inputType === "uint64" || inputType === "uint128" || inputType === "uint256") {
|
|
81
|
+
schema = z.number();
|
|
82
|
+
} else if (inputType === "bool" || inputType === "boolean") {
|
|
83
|
+
schema = z.boolean();
|
|
84
|
+
} else if (inputType === "biguint") {
|
|
85
|
+
schema = z.string();
|
|
86
|
+
} else {
|
|
87
|
+
schema = z.string();
|
|
88
|
+
}
|
|
89
|
+
if (typeof input.min === "number") {
|
|
90
|
+
if (schema instanceof z.ZodNumber) {
|
|
91
|
+
schema = schema.min(input.min);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (typeof input.max === "number") {
|
|
95
|
+
if (schema instanceof z.ZodNumber) {
|
|
96
|
+
schema = schema.max(input.max);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (input.pattern) {
|
|
100
|
+
if (schema instanceof z.ZodString) {
|
|
101
|
+
schema = schema.regex(new RegExp(input.pattern));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const enumValues = extractEnumValues(input.options);
|
|
105
|
+
if (enumValues && enumValues.length > 0) {
|
|
106
|
+
if (schema instanceof z.ZodString) {
|
|
107
|
+
schema = z.enum(enumValues);
|
|
108
|
+
} else if (schema instanceof z.ZodNumber) {
|
|
109
|
+
const numberValues = enumValues.map((v) => Number(v)).filter((v) => !isNaN(v));
|
|
110
|
+
if (numberValues.length > 0) {
|
|
111
|
+
schema = schema.refine((val) => numberValues.includes(val), {
|
|
112
|
+
message: `Value must be one of: ${numberValues.join(", ")}`
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const descriptionParts = [];
|
|
118
|
+
const inputDescription = extractText(input.description);
|
|
119
|
+
if (inputDescription) {
|
|
120
|
+
descriptionParts.push(inputDescription);
|
|
121
|
+
}
|
|
122
|
+
if (input.bot) {
|
|
123
|
+
descriptionParts.push(input.bot);
|
|
124
|
+
}
|
|
125
|
+
descriptionParts.push(`Type: ${input.type}`);
|
|
126
|
+
descriptionParts.push(input.required ? "Required" : "Optional");
|
|
127
|
+
if (enumValues && enumValues.length > 0) {
|
|
128
|
+
descriptionParts.push(`Options: ${enumValues.join(", ")}`);
|
|
129
|
+
}
|
|
130
|
+
const patternDesc = extractText(input.patternDescription);
|
|
131
|
+
if (patternDesc) {
|
|
132
|
+
descriptionParts.push(patternDesc);
|
|
133
|
+
}
|
|
134
|
+
const fullDescription = descriptionParts.join(". ");
|
|
135
|
+
if (fullDescription) {
|
|
136
|
+
schema = schema.describe(fullDescription);
|
|
137
|
+
}
|
|
138
|
+
if (input.required !== true) {
|
|
139
|
+
schema = schema.optional();
|
|
140
|
+
}
|
|
141
|
+
return schema;
|
|
142
|
+
};
|
|
143
|
+
var buildZodInputSchema = (inputs) => {
|
|
144
|
+
const shape = {};
|
|
145
|
+
for (const input of inputs) {
|
|
146
|
+
if (input.source === "hidden") continue;
|
|
147
|
+
if (!isPayloadInput(input)) continue;
|
|
148
|
+
const key = input.as || input.name;
|
|
149
|
+
shape[key] = buildZodSchemaFromInput(input);
|
|
150
|
+
}
|
|
151
|
+
return Object.keys(shape).length > 0 ? shape : void 0;
|
|
152
|
+
};
|
|
153
|
+
var convertActionToTool = (warp, action, description, index, primaryActionInputs) => {
|
|
154
|
+
const inputsToUse = primaryActionInputs || action.inputs || [];
|
|
155
|
+
const inputSchema = buildZodInputSchema(inputsToUse);
|
|
68
156
|
const name = sanitizeMcpName(`${warp.name}_${index}`);
|
|
69
157
|
return {
|
|
70
158
|
name,
|
|
71
159
|
description,
|
|
72
|
-
inputSchema
|
|
160
|
+
inputSchema
|
|
73
161
|
};
|
|
74
162
|
};
|
|
75
|
-
var convertMcpActionToTool = (action, description) => {
|
|
76
|
-
const
|
|
163
|
+
var convertMcpActionToTool = (action, description, primaryActionInputs) => {
|
|
164
|
+
const inputsToUse = primaryActionInputs || action.inputs || [];
|
|
165
|
+
const inputSchema = buildZodInputSchema(inputsToUse);
|
|
77
166
|
const toolName = action.destination.tool;
|
|
78
167
|
return {
|
|
79
168
|
name: sanitizeMcpName(toolName),
|
|
80
169
|
description,
|
|
81
|
-
inputSchema
|
|
170
|
+
inputSchema
|
|
82
171
|
};
|
|
83
172
|
};
|
|
84
|
-
var buildInputSchema = (inputs) => {
|
|
85
|
-
const schema = {
|
|
86
|
-
type: "object",
|
|
87
|
-
properties: {},
|
|
88
|
-
required: []
|
|
89
|
-
};
|
|
90
|
-
inputs.forEach((input) => {
|
|
91
|
-
if (!isPayloadInput(input)) return;
|
|
92
|
-
const key = extractPayloadKey(input.position);
|
|
93
|
-
const property = buildPropertySchema(input);
|
|
94
|
-
schema.properties[key] = property;
|
|
95
|
-
if (input.required) {
|
|
96
|
-
schema.required.push(key);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return schema;
|
|
100
|
-
};
|
|
101
173
|
var isPayloadInput = (input) => {
|
|
102
174
|
return typeof input.position === "string" && input.position.startsWith("payload:");
|
|
103
175
|
};
|
|
104
|
-
var extractPayloadKey = (position) => {
|
|
105
|
-
return position.replace("payload:", "");
|
|
106
|
-
};
|
|
107
|
-
var buildPropertySchema = (input) => {
|
|
108
|
-
const jsonSchemaType = convertWarpTypeToJsonSchemaType(input.type);
|
|
109
|
-
const property = {
|
|
110
|
-
type: jsonSchemaType.type
|
|
111
|
-
};
|
|
112
|
-
if (jsonSchemaType.format) {
|
|
113
|
-
property.format = jsonSchemaType.format;
|
|
114
|
-
}
|
|
115
|
-
const title = extractText(input.label) || input.name;
|
|
116
|
-
if (title) {
|
|
117
|
-
property.title = title;
|
|
118
|
-
}
|
|
119
|
-
const description = buildDescription(input);
|
|
120
|
-
if (description) {
|
|
121
|
-
property.description = description;
|
|
122
|
-
}
|
|
123
|
-
if (input.default !== void 0) {
|
|
124
|
-
property.default = input.default;
|
|
125
|
-
}
|
|
126
|
-
if (typeof input.min === "number") {
|
|
127
|
-
property.minimum = input.min;
|
|
128
|
-
}
|
|
129
|
-
if (typeof input.max === "number") {
|
|
130
|
-
property.maximum = input.max;
|
|
131
|
-
}
|
|
132
|
-
if (input.pattern) {
|
|
133
|
-
property.pattern = input.pattern;
|
|
134
|
-
}
|
|
135
|
-
const enumValues = extractEnumValues(input.options);
|
|
136
|
-
if (enumValues) {
|
|
137
|
-
property.enum = enumValues;
|
|
138
|
-
}
|
|
139
|
-
return property;
|
|
140
|
-
};
|
|
141
|
-
var buildDescription = (input) => {
|
|
142
|
-
const description = extractText(input.description);
|
|
143
|
-
const patternDesc = extractText(input.patternDescription);
|
|
144
|
-
if (!description && !patternDesc) return void 0;
|
|
145
|
-
if (description && patternDesc) return `${description}. ${patternDesc}`;
|
|
146
|
-
return description || patternDesc;
|
|
147
|
-
};
|
|
148
176
|
var extractEnumValues = (options) => {
|
|
149
177
|
if (!options) return void 0;
|
|
150
178
|
if (Array.isArray(options)) return options;
|
|
151
179
|
if (typeof options === "object") return Object.keys(options);
|
|
152
180
|
return void 0;
|
|
153
181
|
};
|
|
154
|
-
var hasProperties = (schema) => {
|
|
155
|
-
return schema && schema.properties && Object.keys(schema.properties).length > 0;
|
|
156
|
-
};
|
|
157
182
|
var sanitizeMcpName = (name) => {
|
|
158
183
|
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, "_");
|
|
159
184
|
};
|
|
@@ -167,15 +192,6 @@ var convertJsonSchemaTypeToWarpType = (type, format) => {
|
|
|
167
192
|
if (type === "object") return "string";
|
|
168
193
|
return "string";
|
|
169
194
|
};
|
|
170
|
-
var convertWarpTypeToJsonSchemaType = (warpType) => {
|
|
171
|
-
if (warpType === "string") return { type: "string" };
|
|
172
|
-
if (warpType === "bool") return { type: "boolean" };
|
|
173
|
-
if (warpType === "uint8" || warpType === "uint16" || warpType === "uint32" || warpType === "uint64" || warpType === "uint128" || warpType === "uint256" || warpType === "biguint") {
|
|
174
|
-
return { type: "integer" };
|
|
175
|
-
}
|
|
176
|
-
if (warpType === "number") return { type: "number" };
|
|
177
|
-
return { type: "string" };
|
|
178
|
-
};
|
|
179
195
|
|
|
180
196
|
// src/WarpMcp.ts
|
|
181
197
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/warps.ts","../src/WarpMcp.ts"],"sourcesContent":["import {\n Warp,\n WarpActionInput,\n WarpActionInputType,\n WarpBuilder,\n WarpClientConfig,\n WarpCollectAction,\n WarpContractAction,\n WarpMcpAction,\n WarpQueryAction,\n WarpText,\n WarpTransferAction,\n} from '@vleap/warps'\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[] } => {\n const tools: any[] = []\n const warpDescription = extractText(warp.description)\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)\n tools.push(tool)\n }\n } else {\n const tool = convertActionToTool(warp, action, description, index)\n tools.push(tool)\n }\n })\n\n return { tools }\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 convertActionToTool = (\n warp: Warp,\n action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction,\n description: string | undefined,\n index: number\n): any => {\n const inputSchema = buildInputSchema(action.inputs || [])\n const name = sanitizeMcpName(`${warp.name}_${index}`)\n\n return {\n name,\n description,\n inputSchema: hasProperties(inputSchema) ? inputSchema : undefined,\n }\n}\n\nconst convertMcpActionToTool = (action: WarpMcpAction, description: string | undefined): any => {\n const inputSchema = buildInputSchema(action.inputs || [])\n const toolName = action.destination!.tool\n\n return {\n name: sanitizeMcpName(toolName),\n description,\n inputSchema: hasProperties(inputSchema) ? inputSchema : undefined,\n }\n}\n\nconst buildInputSchema = (inputs: WarpActionInput[]): any => {\n const schema: any = {\n type: 'object',\n properties: {},\n required: [],\n }\n\n inputs.forEach((input) => {\n if (!isPayloadInput(input)) return\n\n const key = extractPayloadKey(input.position as string)\n const property = buildPropertySchema(input)\n\n schema.properties[key] = property\n\n if (input.required) {\n schema.required.push(key)\n }\n })\n\n return schema\n}\n\nconst isPayloadInput = (input: WarpActionInput): boolean => {\n return typeof input.position === 'string' && input.position.startsWith('payload:')\n}\n\nconst extractPayloadKey = (position: string): string => {\n return position.replace('payload:', '')\n}\n\nconst buildPropertySchema = (input: WarpActionInput): any => {\n const jsonSchemaType = convertWarpTypeToJsonSchemaType(input.type)\n const property: any = {\n type: jsonSchemaType.type,\n }\n\n if (jsonSchemaType.format) {\n property.format = jsonSchemaType.format\n }\n\n const title = extractText(input.label) || input.name\n if (title) {\n property.title = title\n }\n\n const description = buildDescription(input)\n if (description) {\n property.description = description\n }\n\n if (input.default !== undefined) {\n property.default = input.default\n }\n\n if (typeof input.min === 'number') {\n property.minimum = input.min\n }\n\n if (typeof input.max === 'number') {\n property.maximum = input.max\n }\n\n if (input.pattern) {\n property.pattern = input.pattern\n }\n\n const enumValues = extractEnumValues(input.options)\n if (enumValues) {\n property.enum = enumValues\n }\n\n return property\n}\n\nconst buildDescription = (input: WarpActionInput): string | undefined => {\n const description = extractText(input.description)\n const patternDesc = extractText(input.patternDescription)\n\n if (!description && !patternDesc) return undefined\n if (description && patternDesc) return `${description}. ${patternDesc}`\n return description || patternDesc\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 hasProperties = (schema: any): boolean => {\n return schema && schema.properties && Object.keys(schema.properties).length > 0\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\nconst convertWarpTypeToJsonSchemaType = (warpType: string): { type: string; format?: string } => {\n if (warpType === 'string') return { type: 'string' }\n if (warpType === 'bool') return { type: 'boolean' }\n if (\n warpType === 'uint8' ||\n warpType === 'uint16' ||\n warpType === 'uint32' ||\n warpType === 'uint64' ||\n warpType === 'uint128' ||\n warpType === 'uint256' ||\n warpType === 'biguint'\n ) {\n return { type: 'integer' }\n }\n if (warpType === 'number') return { type: 'number' }\n return { type: 'string' }\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\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,EAIE;AAAA,OAQK;AAEA,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,CAA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AAAA,EAC3B;AACA,MAAI,aAAa,SAAU,QAAO,EAAE,MAAM,SAAS;AACnD,SAAO,EAAE,MAAM,SAAS;AAC1B;;;ACjQA,SAAS,cAAc;AACvB,SAAS,qCAAqC;AAIvC,IAAM,UAAN,MAAc;AAAA,EACnB,YAA6B,QAA0B;AAA1B;AAAA,EAA2B;AAAA,EAExD,MAAM,kBAAkB,KAAa,SAAmD;AACtF,UAAM,YAAY,IAAI,8BAA8B,IAAI,IAAI,GAAG,GAAG;AAAA,MAChE,aAAa,EAAE,SAAS,WAAW,CAAC,EAAE;AAAA,IACxC,CAAC;AAED,UAAM,SAAS,IAAI,OAAO,EAAE,MAAM,oBAAoB,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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/warps.ts","../src/WarpMcp.ts"],"sourcesContent":["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[] } => {\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 } catch {\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 return { tools }\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 (!isPayloadInput(input)) continue\n\n const key = input.as || input.name\n shape[key] = buildZodSchemaFromInput(input)\n }\n\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 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\nconst isPayloadInput = (input: WarpActionInput): boolean => {\n return typeof input.position === 'string' && input.position.startsWith('payload:')\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 { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\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,EAIE;AAAA,EAQA;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,MAAM,MAAM;AAE1E,YAAM,WAA4B;AAAA,QAChC,MAAM;AAAA,QACN,OAAO,MAAM,SAAS,EAAE,IAAI,IAAI;AAAA,QAChC,aAAa,MAAM,cAAc,EAAE,IAAI,MAAM,YAAY,KAAK,EAAE,IAAI;AAAA,QACpE,MAAM;AAAA,QACN,UAAU,WAAW,GAAG;A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