@vleap/warps-mcp 1.0.0-beta.12 → 1.0.0-beta.14

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.d.cts CHANGED
@@ -1,30 +1,26 @@
1
- import { Warp, WarpClientConfig } from '@vleap/warps';
1
+ import { Warp, WarpActionInput, WarpTransferAction, WarpContractAction, WarpCollectAction, WarpQueryAction, WarpMcpAction, WarpText, WarpClientConfig } from '@vleap/warps';
2
+ import { z } from 'zod';
2
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
4
 
4
5
  declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
6
 
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
- };
7
+ declare const buildZodInputSchema: (inputs: WarpActionInput[]) => Record<string, z.ZodTypeAny> | undefined;
8
+ declare const convertActionToTool: (warp: Warp, action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction, description: string | undefined, primaryActionInputs?: WarpActionInput[], outputTemplateUri?: string) => any;
9
+ declare const convertMcpActionToTool: (action: WarpMcpAction, description: string | undefined, primaryActionInputs?: WarpActionInput[], outputTemplateUri?: string) => any;
16
10
 
17
11
  type McpTool = {
18
12
  name: string;
19
13
  description?: string;
20
14
  inputSchema?: any;
21
15
  outputSchema?: any;
16
+ _meta?: Record<string, any>;
22
17
  };
23
18
  type McpResource = {
24
19
  name?: string;
25
20
  uri: string;
26
21
  description?: string;
27
22
  mimeType?: string;
23
+ content?: string;
28
24
  };
29
25
  type McpCapabilities = {
30
26
  tools?: McpTool[];
@@ -37,6 +33,24 @@ type McpServerConfig = {
37
33
  executor?: WarpExecutor;
38
34
  };
39
35
 
36
+ declare const createAppResource: (warp: Warp, appUrl: string) => Promise<McpResource | null>;
37
+
38
+ declare const extractText: (text: WarpText | null | undefined) => string | undefined;
39
+ declare const convertWarpToMcpCapabilities: (warp: Warp) => Promise<{
40
+ tools: any[];
41
+ resources?: McpResource[];
42
+ }>;
43
+ declare const convertWarpsToMcpCapabilities: (warps: Warp[]) => Promise<{
44
+ tools: any[];
45
+ resources?: McpResource[];
46
+ }[]>;
47
+ declare const convertMcpToolToWarp: (config: WarpClientConfig, tool: {
48
+ name: string;
49
+ description?: string;
50
+ inputSchema?: any;
51
+ outputSchema?: any;
52
+ }, url: string, headers?: Record<string, string>) => Promise<Warp>;
53
+
40
54
  declare const createMcpServerFromWarps: (config: McpServerConfig, warps: Warp[], capabilities: McpCapabilities[], executor?: WarpExecutor) => McpServer;
41
55
 
42
56
  declare class WarpMcp {
@@ -45,4 +59,4 @@ declare class WarpMcp {
45
59
  getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
46
60
  }
47
61
 
48
- export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, createMcpServerFromWarps };
62
+ export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractText };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,26 @@
1
- import { Warp, WarpClientConfig } from '@vleap/warps';
1
+ import { Warp, WarpActionInput, WarpTransferAction, WarpContractAction, WarpCollectAction, WarpQueryAction, WarpMcpAction, WarpText, WarpClientConfig } from '@vleap/warps';
2
+ import { z } from 'zod';
2
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
4
 
4
5
  declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
6
 
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
- };
7
+ declare const buildZodInputSchema: (inputs: WarpActionInput[]) => Record<string, z.ZodTypeAny> | undefined;
8
+ declare const convertActionToTool: (warp: Warp, action: WarpTransferAction | WarpContractAction | WarpCollectAction | WarpQueryAction, description: string | undefined, primaryActionInputs?: WarpActionInput[], outputTemplateUri?: string) => any;
9
+ declare const convertMcpActionToTool: (action: WarpMcpAction, description: string | undefined, primaryActionInputs?: WarpActionInput[], outputTemplateUri?: string) => any;
16
10
 
17
11
  type McpTool = {
18
12
  name: string;
19
13
  description?: string;
20
14
  inputSchema?: any;
21
15
  outputSchema?: any;
16
+ _meta?: Record<string, any>;
22
17
  };
23
18
  type McpResource = {
24
19
  name?: string;
25
20
  uri: string;
26
21
  description?: string;
27
22
  mimeType?: string;
23
+ content?: string;
28
24
  };
29
25
  type McpCapabilities = {
30
26
  tools?: McpTool[];
@@ -37,6 +33,24 @@ type McpServerConfig = {
37
33
  executor?: WarpExecutor;
38
34
  };
39
35
 
36
+ declare const createAppResource: (warp: Warp, appUrl: string) => Promise<McpResource | null>;
37
+
38
+ declare const extractText: (text: WarpText | null | undefined) => string | undefined;
39
+ declare const convertWarpToMcpCapabilities: (warp: Warp) => Promise<{
40
+ tools: any[];
41
+ resources?: McpResource[];
42
+ }>;
43
+ declare const convertWarpsToMcpCapabilities: (warps: Warp[]) => Promise<{
44
+ tools: any[];
45
+ resources?: McpResource[];
46
+ }[]>;
47
+ declare const convertMcpToolToWarp: (config: WarpClientConfig, tool: {
48
+ name: string;
49
+ description?: string;
50
+ inputSchema?: any;
51
+ outputSchema?: any;
52
+ }, url: string, headers?: Record<string, string>) => Promise<Warp>;
53
+
40
54
  declare const createMcpServerFromWarps: (config: McpServerConfig, warps: Warp[], capabilities: McpCapabilities[], executor?: WarpExecutor) => McpServer;
41
55
 
42
56
  declare class WarpMcp {
@@ -45,4 +59,4 @@ declare class WarpMcp {
45
59
  getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
46
60
  }
47
61
 
48
- export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, createMcpServerFromWarps };
62
+ export { type McpCapabilities, type McpResource, type McpServerConfig, type McpTool, type WarpExecutor, WarpMcp, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractText };
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";var h=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var j=(e,n)=>{for(var r in n)h(e,r,{get:n[r],enumerable:!0})},z=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of Z(n))!$.call(e,t)&&t!==r&&h(e,t,{get:()=>n[t],enumerable:!(i=w(n,t))||i.enumerable});return e};var P=e=>z(h({},"__esModule",{value:!0}),e);var U={};j(U,{WarpMcp:()=>b,convertMcpArgsToWarpInputs:()=>T,convertMcpToolToWarp:()=>A,convertWarpToMcpCapabilities:()=>R,createMcpServerFromWarps:()=>k});module.exports=P(U);var l=require("@vleap/warps"),T=(e,n)=>{let{action:r}=(0,l.getWarpPrimaryAction)(e);if(!r.inputs)return[];let i=new l.WarpSerializer;return r.inputs.map(t=>{let o=t.as||t.name,s=n[o]??t.default??null;return s===null&&t.type==="bool"?i.nativeToString(t.type,!1):i.nativeToString(t.type,s)})};var d=require("@vleap/warps"),m=require("zod"),A=async(e,n,r,i)=>{let t=[];if(n.inputSchema?.properties){let a=n.inputSchema.properties,u=n.inputSchema.required||[];Object.entries(a).forEach(([p,c])=>{let g=u.includes(p),y=q(c.type,c.format),W={name:p,label:c.title||{en:p},description:c.description?{en:c.description.trim()}:null,type:y,position:`payload:${p}`,source:"field",required:g,default:c.default};t.push(W)})}let o={};n.outputSchema?.properties&&Object.keys(n.outputSchema.properties).forEach(a=>{o[a]=`out.${a}`});let s={type:"mcp",label:{en:n.name},description:n.description?{en:n.description.trim()}:null,destination:{url:r,tool:n.name,headers:i},inputs:t};return await new d.WarpBuilder(e).setName(n.name).setTitle({en:n.name}).setDescription(n.description?{en:n.description.trim()}:null).addAction(s).setOutput(Object.keys(o).length>0?o:null).build(!1)},R=e=>{let n=[],r=f(e.description),i;try{let{action:t}=(0,d.getWarpPrimaryAction)(e);i=t.inputs,console.log(`[MCP] Warp ${e.name} - primaryActionInputs:`,i?.length||0,i?.map(o=>({name:o.name,source:o.source,position:o.position})))}catch(t){console.log(`[MCP] Warp ${e.name} - failed to get primary action:`,t),i=void 0}return e.actions.forEach((t,o)=>{let s=f(t.description),a=r||s;if(t.type==="mcp"){let u=t;if(u.destination){let p=N(u,a,i);n.push(p)}}else{let u=E(e,t,a,o,i);n.push(u)}}),console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${e.name}, tools: ${n.length}, tools with schema:`,n.filter(t=>t.inputSchema).length),{tools:n,resources:[]}},f=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},O=e=>{let n,r=e.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=m.z.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=m.z.number():r==="bool"||r==="boolean"?n=m.z.boolean():r==="biguint"?n=m.z.string():n=m.z.string(),typeof e.min=="number"&&n instanceof m.z.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof m.z.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof m.z.ZodString&&(n=n.regex(new RegExp(e.pattern)));let i=_(e.options);if(i&&i.length>0){if(n instanceof m.z.ZodString)n=m.z.enum(i);else if(n instanceof m.z.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(n=n.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let t=[],o=f(e.description);o&&t.push(o),e.bot&&t.push(e.bot),t.push(`Type: ${e.type}`),t.push(e.required?"Required":"Optional"),i&&i.length>0&&t.push(`Options: ${i.join(", ")}`);let s=f(e.patternDescription);s&&t.push(s);let a=t.join(". ");return a&&(n=n.describe(a)),e.required!==!0&&(n=n.optional()),n},C=e=>{let n={};for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=O(r)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},E=(e,n,r,i,t)=>{let o=t||n.inputs||[],s=C(o),a=S(`${e.name}_${i}`);return console.log(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${o.length}, inputSchema keys:`,s?Object.keys(s):"undefined"),{name:a,description:r,inputSchema:s}},N=(e,n,r)=>{let i=r||e.inputs||[],t=C(i),o=e.destination.tool;return{name:S(o),description:n,inputSchema:t}},_=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},S=e=>e.replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_").replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g,"").replace(/_+/g,"_"),q=(e,n)=>n==="date-time"||n==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string";var x=require("@modelcontextprotocol/sdk/server/mcp.js"),M=require("@modelcontextprotocol/sdk/server/zod-compat.js");var D=e=>{if(e)return e._zod?e._zod:(0,M.normalizeObjectSchema)(e)||e},k=(e,n,r,i)=>{let t=new x.McpServer({name:e.name,version:e.version||"1.0.0"}),o=e.executor||i;for(let s=0;s<r.length;s++){let{tools:a,resources:u}=r[s],p=n[s];a?.forEach(c=>{let g=D(c.inputSchema);t.registerTool(c.name,{description:c.description||"",inputSchema:g},async y=>{if(o){let W=T(p,y||{});return await o(p,W)}return{content:[{type:"text",text:`Tool ${c.name} executed successfully`}]}})}),u?.forEach(c=>{t.registerResource(c.name||c.uri,c.uri,{description:c.description,mimeType:c.mimeType},async()=>({contents:[{uri:c.uri,mimeType:c.mimeType||"text/plain",text:"Resource content"}]}))})}return t};var I=require("@modelcontextprotocol/sdk/client/index.js"),v=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var b=class{constructor(n){this.config=n}async getWarpsFromTools(n,r){let i=new v.StreamableHTTPClientTransport(new URL(n),{requestInit:{headers:r||{}}}),t=new I.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await t.connect(i);let o=await t.listTools();return await t.close(),await Promise.all(o.tools.map(s=>A(this.config,s,n,r)))}catch(o){throw await t.close().catch(()=>{}),o}}};0&&(module.exports={WarpMcp,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertWarpToMcpCapabilities,createMcpServerFromWarps});
1
+ "use strict";var W=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var N=(e,t)=>{for(var n in t)W(e,n,{get:t[n],enumerable:!0})},q=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of O(t))!Z.call(e,r)&&r!==n&&W(e,r,{get:()=>t[r],enumerable:!(i=E(t,r))||i.enumerable});return e};var D=e=>q(W({},"__esModule",{value:!0}),e);var X={};N(X,{WarpMcp:()=>R,buildZodInputSchema:()=>b,convertActionToTool:()=>A,convertMcpActionToTool:()=>x,convertMcpArgsToWarpInputs:()=>T,convertMcpToolToWarp:()=>C,convertWarpToMcpCapabilities:()=>P,convertWarpsToMcpCapabilities:()=>Q,createAppResource:()=>M,createMcpServerFromWarps:()=>K,extractText:()=>m});module.exports=D(X);var d=require("@vleap/warps"),T=(e,t)=>{let{action:n}=(0,d.getWarpPrimaryAction)(e);if(!n.inputs)return[];let i=new d.WarpSerializer;return n.inputs.map(r=>{let s=r.as||r.name,c=t[s]??r.default??null;return c===null&&r.type==="bool"?i.nativeToString(r.type,!1):i.nativeToString(r.type,c)})};var l=require("zod"),S=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},F=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},v=e=>(e.includes(":")?e.split(":").slice(1).join(":").trim():e).toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/_+/g,"_"),L=e=>{let t,n=e.type.toLowerCase();n==="string"||n==="address"||n==="hex"?t=l.z.string():n==="number"||n==="uint8"||n==="uint16"||n==="uint32"||n==="uint64"||n==="uint128"||n==="uint256"?t=l.z.number():n==="bool"||n==="boolean"?t=l.z.boolean():n==="biguint"?t=l.z.string():t=l.z.string(),typeof e.min=="number"&&t instanceof l.z.ZodNumber&&(t=t.min(e.min)),typeof e.max=="number"&&t instanceof l.z.ZodNumber&&(t=t.max(e.max)),e.pattern&&t instanceof l.z.ZodString&&(t=t.regex(new RegExp(e.pattern)));let i=F(e.options);if(i&&i.length>0){if(t instanceof l.z.ZodString)t=l.z.enum(i);else if(t instanceof l.z.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(t=t.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let r=[],s=S(e.description);s&&r.push(s),e.bot&&r.push(e.bot),r.push(`Type: ${e.type}`),r.push(e.required?"Required":"Optional"),i&&i.length>0&&r.push(`Options: ${i.join(", ")}`);let c=S(e.patternDescription);c&&r.push(c);let a=r.join(". ");return a&&(t=t.describe(a)),e.required!==!0&&(t=t.optional()),t},b=e=>{let t={};for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name;t[i]=L(n)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(t)),Object.keys(t).length>0?t:void 0},A=(e,t,n,i,r)=>{let s=i||t.inputs||[],c=b(s),a=v(e.name);console.log(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${s.length}, inputSchema keys:`,c?Object.keys(c):"undefined");let u={name:a,description:n,inputSchema:c};return r&&(u._meta={"openai/outputTemplate":r}),u},x=(e,t,n,i)=>{let r=n||e.inputs||[],s=b(r),c=e.destination.tool,a={name:v(c),description:t,inputSchema:s};return i&&(a._meta={"openai/outputTemplate":i}),a};var w=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},U=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Failed: ${t.status}`);return t.text()},j=(e,t)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;let n=new URL(e);return new URL(t,n).href},V=async(e,t)=>{let n=/<link[^>]+rel=["']stylesheet["'][^>]+href=["']([^"']+)["'][^>]*>/gi,i=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,r=[],s;for(;(s=n.exec(e))!==null;){let u=s[0],p=j(t,s[1]);r.push(fetch(p).then(o=>o.ok?o.text():"").then(o=>({match:u,content:o?`<style>${o}</style>`:""})).catch(()=>({match:u,content:""})))}for(;(s=i.exec(e))!==null;){let u=s[0],p=j(t,s[1]);r.push(fetch(p).then(o=>o.ok?o.text():"").then(o=>({match:u,content:o?`<script>${o}</script>`:""})).catch(()=>({match:u,content:""})))}if(r.length===0)return e;let c=await Promise.all(r),a=e;for(let{match:u,content:p}of c)a=a.replace(u,p||"");return a},H=e=>{let t=e;return t=t.replace(/<html[^>]*>/gi,"").replace(/<\/html>/gi,""),t=t.replace(/<head[^>]*>/gi,"").replace(/<\/head>/gi,""),t=t.replace(/<body[^>]*>/gi,"").replace(/<\/body>/gi,""),t.trim()},J=(e,t)=>{let n=`<script type="application/json" id="warp-app-data">${JSON.stringify(t)}</script>`,i=H(e);return`${n}
2
+ ${i}`},M=async(e,t)=>{try{let n=await U(t);n=await V(n,t);let i={warp:{name:e.name,title:w(e.title),description:w(e.description)}};return{name:`ui://widget/${e.name}`,uri:`ui://widget/${e.name}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:J(n,i)}}catch(n){return console.error(`[MCP] Failed to create app resource for ${e.name}:`,n),null}};var g=require("@vleap/warps");var m=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},P=async e=>{let t=[],n=null;e.ui&&e.ui!=="table"&&(n=await M(e,e.ui));try{let{action:i}=(0,g.getWarpPrimaryAction)(e);if(i.type==="mcp"){let r=i;if(r.destination){let s=m(e.description)||m(i.description),c=x(r,s,i.inputs,n?.uri);t.push(c)}}else{let r=m(e.description)||m(i.description),s=A(e,i,r,i.inputs,n?.uri);t.push(s)}}catch(i){console.log(`[MCP] ${e.name} - failed to get primary action:`,i)}return{tools:t,...n&&{resources:[n]}}},Q=async e=>Promise.all(e.map(P)),B=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",C=async(e,t,n,i)=>{let r=[];if(t.inputSchema?.properties){let a=t.inputSchema.properties,u=t.inputSchema.required||[];Object.entries(a).forEach(([p,o])=>{let y=u.includes(p),f=B(o.type,o.format),h={name:p,label:o.title||{en:p},description:o.description?{en:o.description.trim()}:null,type:f,position:`payload:${p}`,source:"field",required:y,default:o.default};r.push(h)})}let s={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(a=>{s[a]=`out.${a}`});let c={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:i},inputs:r};return await new g.WarpBuilder(e).setName(t.name).setTitle({en:t.name}).setDescription(t.description?{en:t.description.trim()}:null).addAction(c).setOutput(Object.keys(s).length>0?s:null).build(!1)};var $=require("@modelcontextprotocol/sdk/server/mcp.js"),I=require("@modelcontextprotocol/sdk/server/zod-compat.js");var G=e=>{if(e)return e._zod?e._zod:(0,I.normalizeObjectSchema)(e)||e},K=(e,t,n,i)=>{let r=new $.McpServer({name:e.name,version:e.version||"1.0.0"}),s=e.executor||i;for(let c=0;c<n.length;c++){let{tools:a,resources:u}=n[c],p=t[c];a?.forEach(o=>{let y=G(o.inputSchema),f={description:o.description||"",inputSchema:y};o._meta&&(f._meta=o._meta),r.registerTool(o.name,f,async h=>{if(s){let k=T(p,h||{});return await s(p,k)}return{content:[{type:"text",text:`Tool ${o.name} executed successfully`}]}})}),u?.forEach(o=>{r.registerResource(o.name||o.uri,o.uri,{description:o.description,mimeType:o.mimeType},async()=>({contents:[{uri:o.uri,mimeType:o.mimeType||"text/plain",text:o.content||"Resource content"}]}))})}return r};var z=require("@modelcontextprotocol/sdk/client/index.js"),_=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var R=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let i=new _.StreamableHTTPClientTransport(new URL(t),{requestInit:{headers:n||{}}}),r=new z.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await r.connect(i);let s=await r.listTools();return await r.close(),await Promise.all(s.tools.map(c=>C(this.config,c,t,n)))}catch(s){throw await r.close().catch(()=>{}),s}}};0&&(module.exports={WarpMcp,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractText});
package/dist/index.mjs CHANGED
@@ -1 +1,2 @@
1
- import{getWarpPrimaryAction as b,WarpSerializer as C}from"@vleap/warps";var y=(e,n)=>{let{action:r}=b(e);if(!r.inputs)return[];let i=new C;return r.inputs.map(t=>{let o=t.as||t.name,s=n[o]??t.default??null;return s===null&&t.type==="bool"?i.nativeToString(t.type,!1):i.nativeToString(t.type,s)})};import{WarpBuilder as S,getWarpPrimaryAction as x}from"@vleap/warps";import{z as m}from"zod";var W=async(e,n,r,i)=>{let t=[];if(n.inputSchema?.properties){let a=n.inputSchema.properties,u=n.inputSchema.required||[];Object.entries(a).forEach(([p,c])=>{let f=u.includes(p),d=Z(c.type,c.format),g={name:p,label:c.title||{en:p},description:c.description?{en:c.description.trim()}:null,type:d,position:`payload:${p}`,source:"field",required:f,default:c.default};t.push(g)})}let o={};n.outputSchema?.properties&&Object.keys(n.outputSchema.properties).forEach(a=>{o[a]=`out.${a}`});let s={type:"mcp",label:{en:n.name},description:n.description?{en:n.description.trim()}:null,destination:{url:r,tool:n.name,headers:i},inputs:t};return await new S(e).setName(n.name).setTitle({en:n.name}).setDescription(n.description?{en:n.description.trim()}:null).addAction(s).setOutput(Object.keys(o).length>0?o:null).build(!1)},X=e=>{let n=[],r=l(e.description),i;try{let{action:t}=x(e);i=t.inputs,console.log(`[MCP] Warp ${e.name} - primaryActionInputs:`,i?.length||0,i?.map(o=>({name:o.name,source:o.source,position:o.position})))}catch(t){console.log(`[MCP] Warp ${e.name} - failed to get primary action:`,t),i=void 0}return e.actions.forEach((t,o)=>{let s=l(t.description),a=r||s;if(t.type==="mcp"){let u=t;if(u.destination){let p=v(u,a,i);n.push(p)}}else{let u=I(e,t,a,o,i);n.push(u)}}),console.log(`[MCP] convertWarpToMcpCapabilities - warp: ${e.name}, tools: ${n.length}, tools with schema:`,n.filter(t=>t.inputSchema).length),{tools:n,resources:[]}},l=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},M=e=>{let n,r=e.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=m.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=m.number():r==="bool"||r==="boolean"?n=m.boolean():r==="biguint"?n=m.string():n=m.string(),typeof e.min=="number"&&n instanceof m.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof m.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof m.ZodString&&(n=n.regex(new RegExp(e.pattern)));let i=w(e.options);if(i&&i.length>0){if(n instanceof m.ZodString)n=m.enum(i);else if(n instanceof m.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(n=n.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let t=[],o=l(e.description);o&&t.push(o),e.bot&&t.push(e.bot),t.push(`Type: ${e.type}`),t.push(e.required?"Required":"Optional"),i&&i.length>0&&t.push(`Options: ${i.join(", ")}`);let s=l(e.patternDescription);s&&t.push(s);let a=t.join(". ");return a&&(n=n.describe(a)),e.required!==!0&&(n=n.optional()),n},h=e=>{let n={};for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=M(r)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},I=(e,n,r,i,t)=>{let o=t||n.inputs||[],s=h(o),a=T(`${e.name}_${i}`);return console.log(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${o.length}, inputSchema keys:`,s?Object.keys(s):"undefined"),{name:a,description:r,inputSchema:s}},v=(e,n,r)=>{let i=r||e.inputs||[],t=h(i),o=e.destination.tool;return{name:T(o),description:n,inputSchema:t}},w=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},T=e=>e.replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^A-Za-z0-9_.-]/g,"_").replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g,"").replace(/_+/g,"_"),Z=(e,n)=>n==="date-time"||n==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string";import{McpServer as $}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as j}from"@modelcontextprotocol/sdk/server/zod-compat.js";var z=e=>{if(e)return e._zod?e._zod:j(e)||e},re=(e,n,r,i)=>{let t=new $({name:e.name,version:e.version||"1.0.0"}),o=e.executor||i;for(let s=0;s<r.length;s++){let{tools:a,resources:u}=r[s],p=n[s];a?.forEach(c=>{let f=z(c.inputSchema);t.registerTool(c.name,{description:c.description||"",inputSchema:f},async d=>{if(o){let g=y(p,d||{});return await o(p,g)}return{content:[{type:"text",text:`Tool ${c.name} executed successfully`}]}})}),u?.forEach(c=>{t.registerResource(c.name||c.uri,c.uri,{description:c.description,mimeType:c.mimeType},async()=>({contents:[{uri:c.uri,mimeType:c.mimeType||"text/plain",text:"Resource content"}]}))})}return t};import{Client as P}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as R}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var A=class{constructor(n){this.config=n}async getWarpsFromTools(n,r){let i=new R(new URL(n),{requestInit:{headers:r||{}}}),t=new P({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await t.connect(i);let o=await t.listTools();return await t.close(),await Promise.all(o.tools.map(s=>W(this.config,s,n,r)))}catch(o){throw await t.close().catch(()=>{}),o}}};export{A as WarpMcp,y as convertMcpArgsToWarpInputs,W as convertMcpToolToWarp,X as convertWarpToMcpCapabilities,re as createMcpServerFromWarps};
1
+ import{getWarpPrimaryAction as w,WarpSerializer as j}from"@vleap/warps";var y=(e,t)=>{let{action:n}=w(e);if(!n.inputs)return[];let i=new j;return n.inputs.map(r=>{let s=r.as||r.name,c=t[s]??r.default??null;return c===null&&r.type==="bool"?i.nativeToString(r.type,!1):i.nativeToString(r.type,c)})};import{z as l}from"zod";var h=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},P=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},W=e=>(e.includes(":")?e.split(":").slice(1).join(":").trim():e).toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/_+/g,"_"),$=e=>{let t,n=e.type.toLowerCase();n==="string"||n==="address"||n==="hex"?t=l.string():n==="number"||n==="uint8"||n==="uint16"||n==="uint32"||n==="uint64"||n==="uint128"||n==="uint256"?t=l.number():n==="bool"||n==="boolean"?t=l.boolean():n==="biguint"?t=l.string():t=l.string(),typeof e.min=="number"&&t instanceof l.ZodNumber&&(t=t.min(e.min)),typeof e.max=="number"&&t instanceof l.ZodNumber&&(t=t.max(e.max)),e.pattern&&t instanceof l.ZodString&&(t=t.regex(new RegExp(e.pattern)));let i=P(e.options);if(i&&i.length>0){if(t instanceof l.ZodString)t=l.enum(i);else if(t instanceof l.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(t=t.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let r=[],s=h(e.description);s&&r.push(s),e.bot&&r.push(e.bot),r.push(`Type: ${e.type}`),r.push(e.required?"Required":"Optional"),i&&i.length>0&&r.push(`Options: ${i.join(", ")}`);let c=h(e.patternDescription);c&&r.push(c);let a=r.join(". ");return a&&(t=t.describe(a)),e.required!==!0&&(t=t.optional()),t},T=e=>{let t={};for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name;t[i]=$(n)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(t)),Object.keys(t).length>0?t:void 0},b=(e,t,n,i,r)=>{let s=i||t.inputs||[],c=T(s),a=W(e.name);console.log(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${s.length}, inputSchema keys:`,c?Object.keys(c):"undefined");let u={name:a,description:n,inputSchema:c};return r&&(u._meta={"openai/outputTemplate":r}),u},A=(e,t,n,i)=>{let r=n||e.inputs||[],s=T(r),c=e.destination.tool,a={name:W(c),description:t,inputSchema:s};return i&&(a._meta={"openai/outputTemplate":i}),a};var x=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},I=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Failed: ${t.status}`);return t.text()},M=(e,t)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;let n=new URL(e);return new URL(t,n).href},z=async(e,t)=>{let n=/<link[^>]+rel=["']stylesheet["'][^>]+href=["']([^"']+)["'][^>]*>/gi,i=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,r=[],s;for(;(s=n.exec(e))!==null;){let u=s[0],p=M(t,s[1]);r.push(fetch(p).then(o=>o.ok?o.text():"").then(o=>({match:u,content:o?`<style>${o}</style>`:""})).catch(()=>({match:u,content:""})))}for(;(s=i.exec(e))!==null;){let u=s[0],p=M(t,s[1]);r.push(fetch(p).then(o=>o.ok?o.text():"").then(o=>({match:u,content:o?`<script>${o}</script>`:""})).catch(()=>({match:u,content:""})))}if(r.length===0)return e;let c=await Promise.all(r),a=e;for(let{match:u,content:p}of c)a=a.replace(u,p||"");return a},_=e=>{let t=e;return t=t.replace(/<html[^>]*>/gi,"").replace(/<\/html>/gi,""),t=t.replace(/<head[^>]*>/gi,"").replace(/<\/head>/gi,""),t=t.replace(/<body[^>]*>/gi,"").replace(/<\/body>/gi,""),t.trim()},k=(e,t)=>{let n=`<script type="application/json" id="warp-app-data">${JSON.stringify(t)}</script>`,i=_(e);return`${n}
2
+ ${i}`},C=async(e,t)=>{try{let n=await I(t);n=await z(n,t);let i={warp:{name:e.name,title:x(e.title),description:x(e.description)}};return{name:`ui://widget/${e.name}`,uri:`ui://widget/${e.name}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:k(n,i)}}catch(n){return console.error(`[MCP] Failed to create app resource for ${e.name}:`,n),null}};import{WarpBuilder as E,getWarpPrimaryAction as O}from"@vleap/warps";var f=e=>{if(e){if(typeof e=="string")return e;if(typeof e=="object"&&"en"in e)return e.en}},Z=async e=>{let t=[],n=null;e.ui&&e.ui!=="table"&&(n=await C(e,e.ui));try{let{action:i}=O(e);if(i.type==="mcp"){let r=i;if(r.destination){let s=f(e.description)||f(i.description),c=A(r,s,i.inputs,n?.uri);t.push(c)}}else{let r=f(e.description)||f(i.description),s=b(e,i,r,i.inputs,n?.uri);t.push(s)}}catch(i){console.log(`[MCP] ${e.name} - failed to get primary action:`,i)}return{tools:t,...n&&{resources:[n]}}},ce=async e=>Promise.all(e.map(Z)),N=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",R=async(e,t,n,i)=>{let r=[];if(t.inputSchema?.properties){let a=t.inputSchema.properties,u=t.inputSchema.required||[];Object.entries(a).forEach(([p,o])=>{let d=u.includes(p),m=N(o.type,o.format),g={name:p,label:o.title||{en:p},description:o.description?{en:o.description.trim()}:null,type:m,position:`payload:${p}`,source:"field",required:d,default:o.default};r.push(g)})}let s={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(a=>{s[a]=`out.${a}`});let c={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:i},inputs:r};return await new E(e).setName(t.name).setTitle({en:t.name}).setDescription(t.description?{en:t.description.trim()}:null).addAction(c).setOutput(Object.keys(s).length>0?s:null).build(!1)};import{McpServer as q}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as D}from"@modelcontextprotocol/sdk/server/zod-compat.js";var F=e=>{if(e)return e._zod?e._zod:D(e)||e},me=(e,t,n,i)=>{let r=new q({name:e.name,version:e.version||"1.0.0"}),s=e.executor||i;for(let c=0;c<n.length;c++){let{tools:a,resources:u}=n[c],p=t[c];a?.forEach(o=>{let d=F(o.inputSchema),m={description:o.description||"",inputSchema:d};o._meta&&(m._meta=o._meta),r.registerTool(o.name,m,async g=>{if(s){let v=y(p,g||{});return await s(p,v)}return{content:[{type:"text",text:`Tool ${o.name} executed successfully`}]}})}),u?.forEach(o=>{r.registerResource(o.name||o.uri,o.uri,{description:o.description,mimeType:o.mimeType},async()=>({contents:[{uri:o.uri,mimeType:o.mimeType||"text/plain",text:o.content||"Resource content"}]}))})}return r};import{Client as L}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as U}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var S=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let i=new U(new URL(t),{requestInit:{headers:n||{}}}),r=new L({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await r.connect(i);let s=await r.listTools();return await r.close(),await Promise.all(s.tools.map(c=>R(this.config,c,t,n)))}catch(s){throw await r.close().catch(()=>{}),s}}};export{S as WarpMcp,T as buildZodInputSchema,b as convertActionToTool,A as convertMcpActionToTool,y as convertMcpArgsToWarpInputs,R as convertMcpToolToWarp,Z as convertWarpToMcpCapabilities,ce as convertWarpsToMcpCapabilities,C as createAppResource,me as createMcpServerFromWarps,f as extractText};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps-mcp",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.14",
4
4
  "description": "MCP adapter for Warps SDK",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -29,6 +29,7 @@
29
29
  "@types/jest": "^30.0.0",
30
30
  "jest": "^30.2.0",
31
31
  "jest-environment-jsdom": "^30.2.0",
32
+ "jest-fetch-mock": "^3.0.3",
32
33
  "ts-jest": "^29.4.6",
33
34
  "tsup": "^8.5.1",
34
35
  "typescript": "^5.9.3"
@@ -41,6 +42,6 @@
41
42
  "zod": "^4.1.13"
42
43
  },
43
44
  "peerDependencies": {
44
- "@vleap/warps": "^3.0.0-beta.172"
45
+ "@vleap/warps": "^3.0.0-beta.173"
45
46
  }
46
47
  }