@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 +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Warp, WarpActionInput, WarpTransferAction, WarpContractAction, WarpCollectAction, WarpQueryAction, WarpMcpAction, WarpText
|
|
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
|
|
9
|
-
declare const convertMcpActionToTool: (action: WarpMcpAction, description: string | undefined, primaryActionInputs
|
|
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
|
|
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
|
|
9
|
-
declare const convertMcpActionToTool: (action: WarpMcpAction, description: string | undefined, primaryActionInputs
|
|
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
|
|
2
|
-
${
|
|
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
|
|
2
|
-
${
|
|
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};
|