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

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 w=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var n in t)W(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of z(t))!O.call(e,r)&&r!==n&&W(e,r,{get:()=>t[r],enumerable:!(i=w(t,r))||i.enumerable});return e};var Z=e=>N(W({},"__esModule",{value:!0}),e);var G={};E(G,{WarpMcp:()=>R,buildZodInputSchema:()=>M,convertActionToTool:()=>C,convertMcpActionToTool:()=>b,convertMcpArgsToWarpInputs:()=>T,convertMcpToolToWarp:()=>A,convertWarpToMcpCapabilities:()=>k,convertWarpsToMcpCapabilities:()=>J,createAppResource:()=>x,createMcpServerFromWarps:()=>B,extractText:()=>u});module.exports=Z(G);var y=require("@vleap/warps"),T=(e,t)=>{let{action:n}=(0,y.getWarpPrimaryAction)(e);if(!n.inputs)return[];let i=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"?i.nativeToString(r.type,!1):i.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()},S=(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,i=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,r=[],s;for(;(s=n.exec(e))!==null;){let l=s[0],a=S(t,s[1]);r.push(fetch(a).then(o=>o.ok?o.text():"").then(o=>({match:l,content:o?`<style>${o}</style>`:""})).catch(()=>({match:l,content:""})))}for(;(s=i.exec(e))!==null;){let l=s[0],a=S(t,s[1]);r.push(fetch(a).then(o=>o.ok?o.text():"").then(o=>({match:l,content:o?`<script>${o}</script>`:""})).catch(()=>({match:l,content:""})))}if(r.length===0)return e;let c=await Promise.all(r),p=e;for(let{match:l,content:a}of c)p=p.replace(l,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>`,i=F(e);return`${n}
2
+ ${i}`},x=async(e,t,n)=>{try{let i=await q(t);i=await D(i,t);let r={warp:{name:e.name,title:u(e.title,n),description:u(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(i,r)}}catch(i){return console.error(`[MCP] Failed to create app resource for ${e.name}:`,i),null}};var u=(e,t)=>e&&(0,g.resolveWarpText)(e,t)||void 0,k=async(e,t)=>{let n=[],i=null;e.ui&&e.ui!=="table"&&(i=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=u(e.description,t)||u(r.description,t),p=b(e,s,c,r.inputs,i?.uri,t);n.push(p)}}else{let s=u(e.description,t)||u(r.description,t),c=C(e,r,s,r.inputs,i?.uri,t);n.push(c)}}catch(r){console.log(`[MCP] ${e.name} - failed to get primary action:`,r)}return{tools:n,...i&&{resources:[i]}}},J=async(e,t)=>Promise.all(e.map(n=>k(n,t))),U=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",A=async(e,t,n,i)=>{let r=[];if(t.inputSchema?.properties){let p=t.inputSchema.properties,l=t.inputSchema.required||[];Object.entries(p).forEach(([a,o])=>{let d=l.includes(a),f=U(o.type,o.format),h={name:a,label:o.title||{en:a},description:o.description?{en:o.description.trim()}:null,type:f,position:`payload:${a}`,source:"field",required:d,default:o.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: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 V=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,"_").replace(/-_-/g,"_").replace(/_+/g,"_"),H=(e,t)=>{let n,i=e.type.toLowerCase();i==="string"||i==="address"||i==="hex"?n=m.z.string():i==="number"||i==="uint8"||i==="uint16"||i==="uint32"||i==="uint64"||i==="uint128"||i==="uint256"?n=m.z.number():i==="bool"||i==="boolean"?n=m.z.boolean():i==="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=V(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(o=>Number(o)).filter(o=>!isNaN(o));a.length>0&&(n=n.refine(o=>a.includes(o),{message:`Value must be one of: ${a.join(", ")}`}))}}let s=[],c=u(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=u(e.patternDescription,t);p&&s.push(p);let l=s.join(". ");return l&&(n=n.describe(l)),e.required!==!0&&(n=n.optional()),n},M=(e,t)=>{let n={};for(let i of e){if(i.source==="hidden"||i.source!=="field")continue;let r=i.as||i.name;n[r]=H(i,t)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},C=(e,t,n,i,r,s)=>{let c=i||t.inputs||[],p=M(c,s),l=v(e.name);console.log(`[MCP] convertActionToTool - tool: ${l}, inputsToUse: ${c.length}, inputSchema keys:`,p?Object.keys(p):"undefined");let a={name:l,description:n,inputSchema:p},o={"openai/widgetAccessible":!0};if(r&&(o["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(o["openai/toolInvocation/invoking"]=d),f&&(o["openai/toolInvocation/invoked"]=f)}return a._meta=o,console.log(`[MCP] convertActionToTool - tool: ${l}, meta:`,JSON.stringify(o,null,2)),a},b=(e,t,n,i,r,s)=>{let c=i||t.inputs||[],p=M(c,s),l=t.destination.tool,a={name:v(l),description:n,inputSchema:p},o={"openai/widgetAccessible":!0};if(r&&(o["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(o["openai/toolInvocation/invoking"]=d),f&&(o["openai/toolInvocation/invoked"]=f)}return a._meta=o,console.log(`[MCP] convertMcpActionToTool - tool: ${v(l)}, meta:`,JSON.stringify(o,null,2)),a};var P=require("@modelcontextprotocol/sdk/server/mcp.js"),$=require("@modelcontextprotocol/sdk/server/zod-compat.js");var Q=e=>{if(e)return e._zod?e._zod:(0,$.normalizeObjectSchema)(e)||e},B=(e,t,n,i)=>{let r=new P.McpServer({name:e.name,version:e.version||"1.0.0"}),s=e.executor||i;for(let c=0;c<n.length;c++){let{tools:p,resources:l}=n[c],a=t[c];p?.forEach(o=>{let d=Q(o.inputSchema),f={description:o.description||"",inputSchema:d};o._meta&&(f._meta=o._meta),r.registerTool(o.name,f,async h=>{if(s){let j=T(a,h||{});return await s(a,j)}return{content:[{type:"text",text:`Tool ${o.name} executed successfully`}]}})}),l?.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 I=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 I.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=>A(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 h=(e,t)=>{let{action:n}=R(e);if(!n.inputs)return[];let i=new S;return n.inputs.map(o=>{let s=o.as||o.name,c=t[s]??o.default??null;return c===null&&o.type==="bool"?i.nativeToString(o.type,!1):i.nativeToString(o.type,c)})};import{z as m}from"zod";import{WarpBuilder as _,getWarpPrimaryAction as j,resolveWarpText as w}from"@vleap/warps";var k=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Failed: ${t.status}`);return t.text()},W=(e,t)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;let n=new URL(e);return new URL(t,n).href},P=async(e,t)=>{let n=/<link[^>]+rel=["']stylesheet["'][^>]+href=["']([^"']+)["'][^>]*>/gi,i=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,o=[],s;for(;(s=n.exec(e))!==null;){let l=s[0],a=W(t,s[1]);o.push(fetch(a).then(r=>r.ok?r.text():"").then(r=>({match:l,content:r?`<style>${r}</style>`:""})).catch(()=>({match:l,content:""})))}for(;(s=i.exec(e))!==null;){let l=s[0],a=W(t,s[1]);o.push(fetch(a).then(r=>r.ok?r.text():"").then(r=>({match:l,content:r?`<script>${r}</script>`:""})).catch(()=>({match:l,content:""})))}if(o.length===0)return e;let c=await Promise.all(o),p=e;for(let{match:l,content:a}of c)p=p.replace(l,a||"");return 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()},I=(e,t)=>{let n=`<script type="application/json" id="warp-app-data">${JSON.stringify(t)}</script>`,i=$(e);return`${n}
2
+ ${i}`},T=async(e,t,n)=>{try{let i=await k(t);i=await P(i,t);let o={warp:{name:e.name,title:u(e.title,n),description:u(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:I(i,o)}}catch(i){return console.error(`[MCP] Failed to create app resource for ${e.name}:`,i),null}};var u=(e,t)=>e&&w(e,t)||void 0,z=async(e,t)=>{let n=[],i=null;e.ui&&e.ui!=="table"&&(i=await T(e,e.ui,t));try{let{action:o}=j(e);if(o.type==="mcp"){let s=o;if(s.destination){let c=u(e.description,t)||u(o.description,t),p=C(e,s,c,o.inputs,i?.uri,t);n.push(p)}}else{let s=u(e.description,t)||u(o.description,t),c=A(e,o,s,o.inputs,i?.uri,t);n.push(c)}}catch(o){console.log(`[MCP] ${e.name} - failed to get primary action:`,o)}return{tools:n,...i&&{resources:[i]}}},ie=async(e,t)=>Promise.all(e.map(n=>z(n,t))),O=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",x=async(e,t,n,i)=>{let o=[];if(t.inputSchema?.properties){let p=t.inputSchema.properties,l=t.inputSchema.required||[];Object.entries(p).forEach(([a,r])=>{let d=l.includes(a),f=O(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};o.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:i},inputs:o};return await new _(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)}},y=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,"_").replace(/-_-/g,"_").replace(/_+/g,"_"),N=(e,t)=>{let n,i=e.type.toLowerCase();i==="string"||i==="address"||i==="hex"?n=m.string():i==="number"||i==="uint8"||i==="uint16"||i==="uint32"||i==="uint64"||i==="uint128"||i==="uint256"?n=m.number():i==="bool"||i==="boolean"?n=m.boolean():i==="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 o=E(e.options);if(o&&o.length>0){if(n instanceof m.ZodString)n=m.enum(o);else if(n instanceof m.ZodNumber){let a=o.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=u(e.description,t);c&&s.push(c),e.bot&&s.push(e.bot),s.push(`Type: ${e.type}`),s.push(e.required?"Required":"Optional"),o&&o.length>0&&s.push(`Options: ${o.join(", ")}`);let p=u(e.patternDescription,t);p&&s.push(p);let l=s.join(". ");return l&&(n=n.describe(l)),e.required!==!0&&(n=n.optional()),n},b=(e,t)=>{let n={};for(let i of e){if(i.source==="hidden"||i.source!=="field")continue;let o=i.as||i.name;n[o]=N(i,t)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},A=(e,t,n,i,o,s)=>{let c=i||t.inputs||[],p=b(c,s),l=y(e.name);console.log(`[MCP] convertActionToTool - tool: ${l}, inputsToUse: ${c.length}, inputSchema keys:`,p?Object.keys(p):"undefined");let a={name:l,description:n,inputSchema:p},r={"openai/widgetAccessible":!0};if(o&&(r["openai/outputTemplate"]=o),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(r["openai/toolInvocation/invoking"]=d),f&&(r["openai/toolInvocation/invoked"]=f)}return a._meta=r,console.log(`[MCP] convertActionToTool - tool: ${l}, meta:`,JSON.stringify(r,null,2)),a},C=(e,t,n,i,o,s)=>{let c=i||t.inputs||[],p=b(c,s),l=t.destination.tool,a={name:y(l),description:n,inputSchema:p},r={"openai/widgetAccessible":!0};if(o&&(r["openai/outputTemplate"]=o),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(r["openai/toolInvocation/invoking"]=d),f&&(r["openai/toolInvocation/invoked"]=f)}return a._meta=r,console.log(`[MCP] convertMcpActionToTool - tool: ${y(l)}, meta:`,JSON.stringify(r,null,2)),a};import{McpServer as Z}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,i)=>{let o=new Z({name:e.name,version:e.version||"1.0.0"}),s=e.executor||i;for(let c=0;c<n.length;c++){let{tools:p,resources:l}=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),o.registerTool(r.name,f,async g=>{if(s){let M=h(a,g||{});return await s(a,M)}return{content:[{type:"text",text:`Tool ${r.name} executed successfully`}]}})}),l?.forEach(r=>{o.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 o};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 i=new L(new URL(t),{requestInit:{headers:n||{}}}),o=new F({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await o.connect(i);let s=await o.listTools();return await o.close(),await Promise.all(s.tools.map(c=>x(this.config,c,t,n)))}catch(s){throw await o.close().catch(()=>{}),s}}};export{v as WarpMcp,b as buildZodInputSchema,A as convertActionToTool,C as convertMcpActionToTool,h as convertMcpArgsToWarpInputs,x as convertMcpToolToWarp,z as convertWarpToMcpCapabilities,ie as convertWarpsToMcpCapabilities,T as createAppResource,fe as createMcpServerFromWarps,u 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.16",
4
4
  "description": "MCP adapter for Warps SDK",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",