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

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