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

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,5 +1,5 @@
1
1
  import { Warp, WarpClientConfig } from '@vleap/warps';
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
 
4
4
  declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Warp, WarpClientConfig } from '@vleap/warps';
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
 
4
4
  declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
5
5
 
package/dist/index.js CHANGED
@@ -1 +1 @@
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},x=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=x(o),a=C(`${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=x(i),o=e.destination.tool;return{name:C(o),description:n,inputSchema:t}},_=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},C=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 S=require("@modelcontextprotocol/sdk/server/mcp"),M=require("@modelcontextprotocol/sdk/server/zod-compat");var D=e=>{if(e)return e._zod?e._zod:(0,M.normalizeObjectSchema)(e)||e},k=(e,n,r,i)=>{let t=new S.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"),v=require("@modelcontextprotocol/sdk/client/streamableHttp");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 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});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{getWarpPrimaryAction as b,WarpSerializer as x}from"@vleap/warps";var y=(e,n)=>{let{action:r}=b(e);if(!r.inputs)return[];let i=new x;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 C,getWarpPrimaryAction as S}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 C(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}=S(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";import{normalizeObjectSchema as j}from"@modelcontextprotocol/sdk/server/zod-compat";var z=e=>{if(e)return e._zod?e._zod:j(e)||e},se=(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";import{StreamableHTTPClientTransport as R}from"@modelcontextprotocol/sdk/client/streamableHttp";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,se as createMcpServerFromWarps};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps-mcp",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "MCP adapter for Warps SDK",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -12,6 +12,7 @@
12
12
  "default": "./dist/index.mjs"
13
13
  }
14
14
  },
15
+ "sideEffects": false,
15
16
  "scripts": {
16
17
  "build": "tsup",
17
18
  "test": "jest --config jest.config.mjs",