@joai/warps-mcp 4.0.0 → 5.1.0
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 +50 -5
- package/dist/index.d.ts +50 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,44 @@ import { Warp, WarpPromptAction, WarpClientConfig, WarpActionInput, WarpTransfer
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
4
|
|
|
5
|
+
declare const resolveMcpAppInputsPayload: (params: {
|
|
6
|
+
query?: unknown;
|
|
7
|
+
contentInputs?: unknown;
|
|
8
|
+
metaInputs?: string[] | null;
|
|
9
|
+
}) => Record<string, unknown> | null;
|
|
10
|
+
declare const resolveMcpAppOutputPayload: (params: {
|
|
11
|
+
metaOutput?: unknown;
|
|
12
|
+
contentOutput?: unknown;
|
|
13
|
+
}) => Record<string, unknown> | null;
|
|
14
|
+
type McpAppWarpEmbedModel = {
|
|
15
|
+
isMcpApp: boolean;
|
|
16
|
+
inputsPayload: Record<string, unknown> | null;
|
|
17
|
+
outputPayload: Record<string, unknown> | null;
|
|
18
|
+
};
|
|
19
|
+
declare const resolveMcpAppWarpEmbedModel: (params: {
|
|
20
|
+
ui?: unknown;
|
|
21
|
+
query?: unknown;
|
|
22
|
+
contentInputs?: unknown;
|
|
23
|
+
metaInputs?: string[] | null;
|
|
24
|
+
metaOutput?: unknown;
|
|
25
|
+
contentOutput?: unknown;
|
|
26
|
+
}) => McpAppWarpEmbedModel;
|
|
27
|
+
declare const hasMcpAppUi: (ui: unknown) => ui is string;
|
|
28
|
+
declare const normalizeMcpToolNameToWarpIdentifier: (toolName: string) => string;
|
|
29
|
+
declare const isMcpToolCallAllowedForWarp: (params: {
|
|
30
|
+
requestedToolName: string;
|
|
31
|
+
activeWarpIdentifier?: string | null;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
declare const buildWarpDirectIdentifierFromMcpToolCall: (toolName: string, args?: Record<string, unknown>) => string;
|
|
34
|
+
declare const resolveMcpToolCallToWarpDirect: (params: {
|
|
35
|
+
requestedToolName: string;
|
|
36
|
+
args?: Record<string, unknown>;
|
|
37
|
+
activeWarpIdentifier?: string | null;
|
|
38
|
+
}) => {
|
|
39
|
+
allowed: boolean;
|
|
40
|
+
warpIdentifier: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
5
43
|
declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
|
|
6
44
|
|
|
7
45
|
type WarpMcpServerConfig = {
|
|
@@ -11,9 +49,10 @@ type WarpMcpServerConfig = {
|
|
|
11
49
|
type JsonSchema$1 = Record<string, unknown>;
|
|
12
50
|
type ToolInputSchema = Record<string, z.ZodTypeAny> | JsonSchema$1 | undefined;
|
|
13
51
|
type ToolOutputSchema = JsonSchema$1 | undefined;
|
|
52
|
+
type WarpAppToolVisibility = 'model' | 'app';
|
|
14
53
|
type WarpAppUiMeta = {
|
|
15
54
|
resourceUri?: string;
|
|
16
|
-
visibility?:
|
|
55
|
+
visibility?: WarpAppToolVisibility[];
|
|
17
56
|
};
|
|
18
57
|
type WarpAppResourceUiMeta = {
|
|
19
58
|
csp?: {
|
|
@@ -22,13 +61,18 @@ type WarpAppResourceUiMeta = {
|
|
|
22
61
|
frameDomains?: string[];
|
|
23
62
|
baseUriDomains?: string[];
|
|
24
63
|
};
|
|
25
|
-
permissions?:
|
|
64
|
+
permissions?: {
|
|
65
|
+
camera?: Record<string, never>;
|
|
66
|
+
microphone?: Record<string, never>;
|
|
67
|
+
geolocation?: Record<string, never>;
|
|
68
|
+
clipboardWrite?: Record<string, never>;
|
|
69
|
+
};
|
|
26
70
|
domain?: string;
|
|
27
71
|
prefersBorder?: boolean;
|
|
28
72
|
};
|
|
29
73
|
type ToolMeta = {
|
|
30
74
|
ui?: WarpAppUiMeta;
|
|
31
|
-
[key: string]:
|
|
75
|
+
[key: string]: unknown;
|
|
32
76
|
};
|
|
33
77
|
type ResourceMeta = {
|
|
34
78
|
ui?: WarpAppResourceUiMeta;
|
|
@@ -67,11 +111,12 @@ type WarpMcpCapabilities = {
|
|
|
67
111
|
};
|
|
68
112
|
type WarpMcpToolArgs = Record<string, unknown>;
|
|
69
113
|
type WarpMcpToolResult = {
|
|
70
|
-
structuredContent?:
|
|
114
|
+
structuredContent?: Record<string, unknown>;
|
|
71
115
|
content: Array<{
|
|
72
116
|
type: 'text';
|
|
73
117
|
text: string;
|
|
74
118
|
}>;
|
|
119
|
+
isError?: boolean;
|
|
75
120
|
_meta?: ToolMeta;
|
|
76
121
|
};
|
|
77
122
|
type WarpMcpExecutor = (warp: Warp, inputs: string[]) => Promise<WarpMcpToolResult>;
|
|
@@ -114,4 +159,4 @@ declare class WarpMcp {
|
|
|
114
159
|
getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
|
|
115
160
|
}
|
|
116
161
|
|
|
117
|
-
export { type JsonSchema$1 as JsonSchema, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, interpolatePromptWithArgs };
|
|
162
|
+
export { type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,44 @@ import { Warp, WarpPromptAction, WarpClientConfig, WarpActionInput, WarpTransfer
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
4
|
|
|
5
|
+
declare const resolveMcpAppInputsPayload: (params: {
|
|
6
|
+
query?: unknown;
|
|
7
|
+
contentInputs?: unknown;
|
|
8
|
+
metaInputs?: string[] | null;
|
|
9
|
+
}) => Record<string, unknown> | null;
|
|
10
|
+
declare const resolveMcpAppOutputPayload: (params: {
|
|
11
|
+
metaOutput?: unknown;
|
|
12
|
+
contentOutput?: unknown;
|
|
13
|
+
}) => Record<string, unknown> | null;
|
|
14
|
+
type McpAppWarpEmbedModel = {
|
|
15
|
+
isMcpApp: boolean;
|
|
16
|
+
inputsPayload: Record<string, unknown> | null;
|
|
17
|
+
outputPayload: Record<string, unknown> | null;
|
|
18
|
+
};
|
|
19
|
+
declare const resolveMcpAppWarpEmbedModel: (params: {
|
|
20
|
+
ui?: unknown;
|
|
21
|
+
query?: unknown;
|
|
22
|
+
contentInputs?: unknown;
|
|
23
|
+
metaInputs?: string[] | null;
|
|
24
|
+
metaOutput?: unknown;
|
|
25
|
+
contentOutput?: unknown;
|
|
26
|
+
}) => McpAppWarpEmbedModel;
|
|
27
|
+
declare const hasMcpAppUi: (ui: unknown) => ui is string;
|
|
28
|
+
declare const normalizeMcpToolNameToWarpIdentifier: (toolName: string) => string;
|
|
29
|
+
declare const isMcpToolCallAllowedForWarp: (params: {
|
|
30
|
+
requestedToolName: string;
|
|
31
|
+
activeWarpIdentifier?: string | null;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
declare const buildWarpDirectIdentifierFromMcpToolCall: (toolName: string, args?: Record<string, unknown>) => string;
|
|
34
|
+
declare const resolveMcpToolCallToWarpDirect: (params: {
|
|
35
|
+
requestedToolName: string;
|
|
36
|
+
args?: Record<string, unknown>;
|
|
37
|
+
activeWarpIdentifier?: string | null;
|
|
38
|
+
}) => {
|
|
39
|
+
allowed: boolean;
|
|
40
|
+
warpIdentifier: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
5
43
|
declare const convertMcpArgsToWarpInputs: (warp: Warp, args: Record<string, any>) => string[];
|
|
6
44
|
|
|
7
45
|
type WarpMcpServerConfig = {
|
|
@@ -11,9 +49,10 @@ type WarpMcpServerConfig = {
|
|
|
11
49
|
type JsonSchema$1 = Record<string, unknown>;
|
|
12
50
|
type ToolInputSchema = Record<string, z.ZodTypeAny> | JsonSchema$1 | undefined;
|
|
13
51
|
type ToolOutputSchema = JsonSchema$1 | undefined;
|
|
52
|
+
type WarpAppToolVisibility = 'model' | 'app';
|
|
14
53
|
type WarpAppUiMeta = {
|
|
15
54
|
resourceUri?: string;
|
|
16
|
-
visibility?:
|
|
55
|
+
visibility?: WarpAppToolVisibility[];
|
|
17
56
|
};
|
|
18
57
|
type WarpAppResourceUiMeta = {
|
|
19
58
|
csp?: {
|
|
@@ -22,13 +61,18 @@ type WarpAppResourceUiMeta = {
|
|
|
22
61
|
frameDomains?: string[];
|
|
23
62
|
baseUriDomains?: string[];
|
|
24
63
|
};
|
|
25
|
-
permissions?:
|
|
64
|
+
permissions?: {
|
|
65
|
+
camera?: Record<string, never>;
|
|
66
|
+
microphone?: Record<string, never>;
|
|
67
|
+
geolocation?: Record<string, never>;
|
|
68
|
+
clipboardWrite?: Record<string, never>;
|
|
69
|
+
};
|
|
26
70
|
domain?: string;
|
|
27
71
|
prefersBorder?: boolean;
|
|
28
72
|
};
|
|
29
73
|
type ToolMeta = {
|
|
30
74
|
ui?: WarpAppUiMeta;
|
|
31
|
-
[key: string]:
|
|
75
|
+
[key: string]: unknown;
|
|
32
76
|
};
|
|
33
77
|
type ResourceMeta = {
|
|
34
78
|
ui?: WarpAppResourceUiMeta;
|
|
@@ -67,11 +111,12 @@ type WarpMcpCapabilities = {
|
|
|
67
111
|
};
|
|
68
112
|
type WarpMcpToolArgs = Record<string, unknown>;
|
|
69
113
|
type WarpMcpToolResult = {
|
|
70
|
-
structuredContent?:
|
|
114
|
+
structuredContent?: Record<string, unknown>;
|
|
71
115
|
content: Array<{
|
|
72
116
|
type: 'text';
|
|
73
117
|
text: string;
|
|
74
118
|
}>;
|
|
119
|
+
isError?: boolean;
|
|
75
120
|
_meta?: ToolMeta;
|
|
76
121
|
};
|
|
77
122
|
type WarpMcpExecutor = (warp: Warp, inputs: string[]) => Promise<WarpMcpToolResult>;
|
|
@@ -114,4 +159,4 @@ declare class WarpMcp {
|
|
|
114
159
|
getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
|
|
115
160
|
}
|
|
116
161
|
|
|
117
|
-
export { type JsonSchema$1 as JsonSchema, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, interpolatePromptWithArgs };
|
|
162
|
+
export { type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var D=(r,e)=>{for(var n in e)T(r,n,{get:e[n],enumerable:!0})},J=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of N(e))!U.call(r,i)&&i!==n&&T(r,i,{get:()=>e[i],enumerable:!(t=k(e,i))||t.enumerable});return r};var F=r=>J(T({},"__esModule",{value:!0}),r);var nr={};D(nr,{WarpMcp:()=>w,buildZodInputSchema:()=>M,convertActionToTool:()=>h,convertMcpActionToTool:()=>C,convertMcpArgsToWarpInputs:()=>A,convertMcpToolToWarp:()=>P,convertPromptActionToPrompt:()=>R,convertWarpToMcpCapabilities:()=>Z,convertWarpsToMcpCapabilities:()=>Y,createAppResource:()=>x,createMcpServerFromWarps:()=>tr,extractTextOrUndefined:()=>l,interpolatePromptWithArgs:()=>S});module.exports=F(nr);var z=require("@joai/warps"),A=(r,e)=>{let{action:n}=(0,z.getWarpPrimaryAction)(r);return n.inputs?n.inputs.map(t=>{let i=t.as||t.name,o=e[i]??t.default??null;return o===null&&t.type==="bool"?"false":o==null?"":String(o)}):[]};var d=require("@joai/warps");var I=require("@joai/warps"),m=require("zod");var L=r=>{if(r){if(Array.isArray(r))return r;if(typeof r=="object")return Object.keys(r)}},V=(r,e)=>{let n,t=r.type.toLowerCase();t==="string"||t==="address"||t==="hex"?n=m.z.string():t==="number"||t==="uint8"||t==="uint16"||t==="uint32"||t==="uint64"||t==="uint128"||t==="uint256"?n=m.z.number():t==="bool"||t==="boolean"?n=m.z.boolean():t==="biguint"?n=m.z.string():n=m.z.string(),typeof r.min=="number"&&n instanceof m.z.ZodNumber&&(n=n.min(r.min)),typeof r.max=="number"&&n instanceof m.z.ZodNumber&&(n=n.max(r.max)),r.pattern&&n instanceof m.z.ZodString&&(n=n.regex(new RegExp(r.pattern)));let i=L(r.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(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(n=n.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],a=l(r.description,e);a&&o.push(a),r.bot&&o.push(r.bot),o.push(`Type: ${r.type}`),o.push(r.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let p=l(r.patternDescription,e);p&&o.push(p);let c=o.join(". ");return c&&(n=n.describe(c)),r.required!==!0&&(n=n.optional()),n},M=(r,e)=>{let n={};for(let t of r){if(t.source==="hidden"||t.source!=="field")continue;let i=t.as||t.name;n[i]=V(t,e)}return Object.keys(n).length>0?n:void 0},h=(r,e,n,t,i,o)=>{let a=H(r),p=t||e.inputs||[],c=M(p,o);return{name:a,description:n,inputSchema:c,meta:v(r,i,o)}},C=(r,e,n,t,i,o)=>{let a=t||e.inputs||[],p=M(a,o),c=e.destination?.tool;if(!c)throw new Error(`Tool name is required for MCP action ${e.type}`);return{name:c,description:n,inputSchema:p,meta:v(r,i,o)}},v=(r,e,n)=>{let t={visibility:["model","app"]};return e&&(t.resourceUri=e.uri),{ui:t}},H=r=>{let e=r.meta?.identifier;if(!e)throw new Error(`Warp identifier for warp ${r.name} is required`);return(0,I.removeWarpChainPrefix)(e)};var b=require("@joai/warps"),Q="text/html;profile=mcp-app",B=async r=>{if(r.startsWith("http://")||r.startsWith("https://")){let e=await fetch(r);if(!e.ok)throw new Error(`Failed to download component from ${r}: HTTP ${e.status} ${e.statusText}`);return e.text()}throw new Error(`Unsupported component path: ${r}`)},x=async(r,e,n)=>{if(!r.meta?.identifier)return null;try{let t=await B(e);return{name:r.name,uri:`ui://widget/${r.meta.identifier}`,description:`MCP app for ${r.name}`,mimeType:Q,content:t}}catch(t){let i=t instanceof Error?t.message:String(t),o=t instanceof Error?t.stack:void 0;return b.WarpLogger.error(`[MCP] Failed to create app resource for warp "${r.name}" (path: ${e}):`,i),o&&b.WarpLogger.error("[MCP] Error stack:",o),null}};var Z=async(r,e)=>{let n=null,t=null,i=null;if(r.ui&&r.ui!=="table"&&(t=await x(r,r.ui,e)),r.actions.length===0)return{tool:null,resource:t,prompt:null};try{let{action:o}=(0,d.getWarpPrimaryAction)(r),a=l(r.description,e)||l(o.description,e);if(o.type==="prompt")i=R(r,o,a,e);else if(o.type==="mcp"){let p=o;p.destination&&(n=C(r,p,a,o.inputs,t,e))}else n=h(r,o,a,o.inputs,t,e)}catch{return{tool:null,resource:t,prompt:null}}return{tool:n,resource:t,prompt:i}},Y=async(r,e)=>Promise.all(r.map(n=>Z(n,e))),G=(r,e)=>e==="date-time"||e==="date"||r==="string"?"string":r==="number"||r==="integer"?"uint256":r==="boolean"?"bool":"string",P=async(r,e,n,t)=>{let i=[];if(e.inputSchema?.properties){let p=e.inputSchema.properties,c=e.inputSchema.required||[];Object.entries(p).forEach(([u,s])=>{let f=c.includes(u),g=G(s.type||"string",s.format),y={name:u,label:typeof s.title=="string"?{en:s.title}:s.title||{en:u},description:s.description?{en:s.description.trim()}:null,type:g,position:`payload:${u}`,source:"field",required:f,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(y)})}let o={};e.outputSchema?.properties&&Object.keys(e.outputSchema.properties).forEach(p=>{o[p]=`out.${p}`});let a={type:"mcp",label:{en:e.name},description:e.description?{en:e.description.trim()}:null,destination:{url:n,tool:e.name,headers:t},inputs:i};return await new d.WarpBuilder(r).setName(e.name||"unnamed_tool").setTitle({en:e.name||"Unnamed Tool"}).setDescription(e.description?{en:e.description.trim()}:null).addAction(a).setOutput(Object.keys(o).length>0?o:null).build(!1)},l=(r,e)=>r&&(0,d.resolveWarpText)(r,e)||void 0;var S=(r,e)=>{let n=r;for(let[t,i]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${t}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},K=r=>(r.includes(":")?r.split(":").slice(1).join(":"):r).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,e=>e.includes("_")?"_":e).replace(/_+/g,"_"),X=(r,e)=>{let n=[];for(let t of r){if(t.source==="hidden"||t.source!=="field")continue;let i=t.as||t.name,o=l(t.description,e);n.push({name:i,description:o,required:t.required===!0})}return n},R=(r,e,n,t)=>{let i=K(r.name),o=e.inputs||[],a=X(o,t);return{name:i,description:n,arguments:a.length>0?a:void 0,prompt:e.prompt}};var _=require("@modelcontextprotocol/sdk/server/mcp.js"),E=require("@modelcontextprotocol/sdk/server/zod-compat.js"),W=require("@modelcontextprotocol/ext-apps/server"),$=require("zod");var rr=r=>{if(r)return typeof r=="object"&&"_zod"in r?r._zod:typeof r=="object"&&!Array.isArray(r)&&(0,E.normalizeObjectSchema)(r)||r},er=r=>{if(!r.arguments||r.arguments.length===0)return;let e={};for(let n of r.arguments){let t=$.z.string();n.description&&(t=t.describe(n.description)),n.required||(t=t.optional()),e[n.name]=t}return e},tr=(r,e,n,t)=>{let i=new _.McpServer({name:r.name,version:r.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:a,resource:p,prompt:c}=n[o],u=e[o];if(a){let s=rr(a.inputSchema),f={description:a.description||"",inputSchema:s,...a.meta&&{_meta:a.meta}},g=async y=>{let q=A(u,y||{});return await t(u,q)};a.meta?.ui?.resourceUri?(0,W.registerAppTool)(i,a.name,f,g):i.registerTool(a.name,f,g)}if(p&&(p.mimeType?.includes("profile=mcp-app")?(0,W.registerAppResource)(i,p.name||p.uri,p.uri,{description:p.description},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}}):i.registerResource(p.name||p.uri,p.uri,{description:p.description,mimeType:p.mimeType},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}})),c){let s=er(c);i.registerPrompt(c.name,{description:c.description||"",argsSchema:s},f=>({messages:[{role:"user",content:{type:"text",text:S(c.prompt,f)}}]}))}}return i};var j=require("@modelcontextprotocol/sdk/client/index.js"),O=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var w=class{constructor(e){this.config=e}async getWarpsFromTools(e,n){let t=new O.StreamableHTTPClientTransport(new URL(e),{requestInit:{headers:n||{}}}),i=new j.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(t);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(a=>P(this.config,a,e,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};0&&(module.exports={WarpMcp,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertPromptActionToPrompt,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractTextOrUndefined,interpolatePromptWithArgs});
|
|
1
|
+
"use strict";var M=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Y=(t,e)=>{for(var r in e)M(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of H(e))!Q.call(t,i)&&i!==r&&M(t,i,{get:()=>e[i],enumerable:!(n=V(e,i))||n.enumerable});return t};var G=t=>B(M({},"__esModule",{value:!0}),t);var ft={};Y(ft,{WarpMcp:()=>k,buildWarpDirectIdentifierFromMcpToolCall:()=>E,buildZodInputSchema:()=>b,convertActionToTool:()=>C,convertMcpActionToTool:()=>P,convertMcpArgsToWarpInputs:()=>h,convertMcpToolToWarp:()=>R,convertPromptActionToPrompt:()=>I,convertWarpToMcpCapabilities:()=>j,convertWarpsToMcpCapabilities:()=>pt,createAppResource:()=>w,createMcpServerFromWarps:()=>dt,extractTextOrUndefined:()=>f,hasMcpAppUi:()=>q,interpolatePromptWithArgs:()=>S,isMcpToolCallAllowedForWarp:()=>v,normalizeMcpToolNameToWarpIdentifier:()=>T,resolveMcpAppInputsPayload:()=>z,resolveMcpAppOutputPayload:()=>O,resolveMcpAppWarpEmbedModel:()=>X,resolveMcpToolCallToWarpDirect:()=>tt});module.exports=G(ft);var y=t=>!t||typeof t!="object"||Array.isArray(t)?null:t,K=t=>t==null?null:typeof t=="string"?t:JSON.stringify(t),z=t=>{let e=y(t.query);if(e)return e;let r=y(t.contentInputs);if(r)return r;let n=t.metaInputs||[];return n.length>0?{inputs:n}:null},O=t=>y(t.metaOutput)||y(t.contentOutput),X=t=>({isMcpApp:q(t.ui),inputsPayload:z({query:t.query,contentInputs:t.contentInputs,metaInputs:t.metaInputs}),outputPayload:O({metaOutput:t.metaOutput,contentOutput:t.contentOutput})}),q=t=>typeof t=="string"&&t!=="table",T=t=>!t||t.startsWith("@")?t:t.includes(":")?`@${t.replace(/^@/,"")}`:t,v=t=>t.activeWarpIdentifier?T(t.requestedToolName)===T(t.activeWarpIdentifier):!0,E=(t,e={})=>{let r=T(t),n=new URLSearchParams;return Object.entries(e).forEach(([i,o])=>{let c=K(o);c!=null&&n.set(i,c)}),n.size>0?`${r}?${n.toString()}`:r},tt=t=>{let e=v({requestedToolName:t.requestedToolName,activeWarpIdentifier:t.activeWarpIdentifier}),r=E(t.requestedToolName,t.args||{});return{allowed:e,warpIdentifier:r}};var _=require("@joai/warps"),h=(t,e)=>{let{action:r}=(0,_.getWarpPrimaryAction)(t);return r.inputs?r.inputs.map(n=>{let i=n.as||n.name,o=e[i]??n.default??null;return o===null&&n.type==="bool"?"false":o==null?"":String(o)}):[]};var g=require("@joai/warps");var Z=require("@joai/warps"),l=require("zod");var et=t=>{if(t){if(Array.isArray(t))return t;if(typeof t=="object")return Object.keys(t)}},rt=(t,e)=>{let r,n=t.type.toLowerCase();n==="string"||n==="address"||n==="hex"?r=l.z.string():n==="number"||n==="uint8"||n==="uint16"||n==="uint32"||n==="uint64"||n==="uint128"||n==="uint256"?r=l.z.number():n==="bool"||n==="boolean"?r=l.z.boolean():n==="biguint"?r=l.z.string():r=l.z.string(),typeof t.min=="number"&&r instanceof l.z.ZodNumber&&(r=r.min(t.min)),typeof t.max=="number"&&r instanceof l.z.ZodNumber&&(r=r.max(t.max)),t.pattern&&r instanceof l.z.ZodString&&(r=r.regex(new RegExp(t.pattern)));let i=et(t.options);if(i&&i.length>0){if(r instanceof l.z.ZodString)r=l.z.enum(i);else if(r instanceof l.z.ZodNumber){let u=i.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(r=r.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],c=f(t.description,e);c&&o.push(c),t.bot&&o.push(t.bot),o.push(`Type: ${t.type}`),o.push(t.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let p=f(t.patternDescription,e);p&&o.push(p);let a=o.join(". ");return a&&(r=r.describe(a)),t.required!==!0&&(r=r.optional()),r},b=(t,e)=>{let r={};for(let n of t){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name;r[i]=rt(n,e)}return Object.keys(r).length>0?r:void 0},C=(t,e,r,n,i,o)=>{let c=nt(t),p=n||e.inputs||[],a=b(p,o);return{name:c,description:r,inputSchema:a,meta:$(t,i,o)}},P=(t,e,r,n,i,o)=>{let c=n||e.inputs||[],p=b(c,o),a=e.destination?.tool;if(!a)throw new Error(`Tool name is required for MCP action ${e.type}`);return{name:a,description:r,inputSchema:p,meta:$(t,i,o)}},$=(t,e,r)=>{let n={visibility:["model","app"]};return e&&(n.resourceUri=e.uri),{ui:n}},nt=t=>{let e=t.meta?.identifier;if(!e)throw new Error(`Warp identifier for warp ${t.name} is required`);return(0,Z.removeWarpChainPrefix)(e)};var x=require("@joai/warps"),ot="text/html;profile=mcp-app",it=async t=>{if(t.startsWith("http://")||t.startsWith("https://")){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to download component from ${t}: HTTP ${e.status} ${e.statusText}`);return e.text()}throw new Error(`Unsupported component path: ${t}`)},w=async(t,e,r)=>{if(!t.meta?.identifier)return null;try{let n=await it(e);return{name:t.name,uri:`ui://widget/${t.meta.identifier}`,description:`MCP app for ${t.name}`,mimeType:ot,content:n}}catch(n){let i=n instanceof Error?n.message:String(n),o=n instanceof Error?n.stack:void 0;return x.WarpLogger.error(`[MCP] Failed to create app resource for warp "${t.name}" (path: ${e}):`,i),o&&x.WarpLogger.error("[MCP] Error stack:",o),null}};var j=async(t,e)=>{let r=null,n=null,i=null;if(t.ui&&t.ui!=="table"&&(n=await w(t,t.ui,e)),t.actions.length===0)return{tool:null,resource:n,prompt:null};try{let{action:o}=(0,g.getWarpPrimaryAction)(t),c=f(t.description,e)||f(o.description,e);if(o.type==="prompt")i=I(t,o,c,e);else if(o.type==="mcp"){let p=o;p.destination&&(r=P(t,p,c,o.inputs,n,e))}else r=C(t,o,c,o.inputs,n,e)}catch{return{tool:null,resource:n,prompt:null}}return{tool:r,resource:n,prompt:i}},pt=async(t,e)=>Promise.all(t.map(r=>j(r,e))),st=(t,e)=>e==="date-time"||e==="date"||t==="string"?"string":t==="number"||t==="integer"?"uint256":t==="boolean"?"bool":"string",R=async(t,e,r,n)=>{let i=[];if(e.inputSchema?.properties){let p=e.inputSchema.properties,a=e.inputSchema.required||[];Object.entries(p).forEach(([u,s])=>{let m=a.includes(u),d=st(s.type||"string",s.format),A={name:u,label:typeof s.title=="string"?{en:s.title}:s.title||{en:u},description:s.description?{en:s.description.trim()}:null,type:d,position:`payload:${u}`,source:"field",required:m,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(A)})}let o={};e.outputSchema?.properties&&Object.keys(e.outputSchema.properties).forEach(p=>{o[p]=`out.${p}`});let c={type:"mcp",label:{en:e.name},description:e.description?{en:e.description.trim()}:null,destination:{url:r,tool:e.name,headers:n},inputs:i};return await new g.WarpBuilder(t).setName(e.name||"unnamed_tool").setTitle({en:e.name||"Unnamed Tool"}).setDescription(e.description?{en:e.description.trim()}:null).addAction(c).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(t,e)=>t&&(0,g.resolveWarpText)(t,e)||void 0;var S=(t,e)=>{let r=t;for(let[n,i]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${n}\\s*\\}\\}`,"g");r=r.replace(o,i??"")}return r},ct=t=>(t.includes(":")?t.split(":").slice(1).join(":"):t).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,e=>e.includes("_")?"_":e).replace(/_+/g,"_"),at=(t,e)=>{let r=[];for(let n of t){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name,o=f(n.description,e);r.push({name:i,description:o,required:n.required===!0})}return r},I=(t,e,r,n)=>{let i=ct(t.name),o=e.inputs||[],c=at(o,n);return{name:i,description:r,arguments:c.length>0?c:void 0,prompt:e.prompt}};var U=require("@modelcontextprotocol/sdk/server/mcp.js"),N=require("@modelcontextprotocol/sdk/server/zod-compat.js"),W=require("@modelcontextprotocol/ext-apps/server"),D=require("zod");var ut=t=>{if(t)return typeof t=="object"&&"_zod"in t?t._zod:typeof t=="object"&&!Array.isArray(t)&&(0,N.normalizeObjectSchema)(t)||t},lt=t=>{if(!t.arguments||t.arguments.length===0)return;let e={};for(let r of t.arguments){let n=D.z.string();r.description&&(n=n.describe(r.description)),r.required||(n=n.optional()),e[r.name]=n}return e},mt=(t,e)=>t.startsWith("ui://")?!0:e?.includes("profile=mcp-app")??!1,dt=(t,e,r,n)=>{let i=new U.McpServer({name:t.name,version:t.version||"1.0.0"});for(let o=0;o<r.length;o++){let{tool:c,resource:p,prompt:a}=r[o],u=e[o];if(c){let s=ut(c.inputSchema),m={description:c.description||"",inputSchema:s,...c.meta&&{_meta:c.meta}},d=async A=>{let L=h(u,A||{});return await n(u,L)};c.meta?.ui?.resourceUri?(0,W.registerAppTool)(i,c.name,m,d):i.registerTool(c.name,m,d)}if(p)if(mt(p.uri,p.mimeType)){let s=p.meta,m=p.mimeType||W.RESOURCE_MIME_TYPE;(0,W.registerAppResource)(i,p.name||p.uri,p.uri,{description:p.description,mimeType:m,...s&&{_meta:s}},async()=>{let d={uri:p.uri,text:p.content||"",mimeType:m};return s&&(d._meta=s),{contents:[d]}})}else i.registerResource(p.name||p.uri,p.uri,{description:p.description,mimeType:p.mimeType},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}});if(a){let s=lt(a);i.registerPrompt(a.name,{description:a.description||"",argsSchema:s},m=>({messages:[{role:"user",content:{type:"text",text:S(a.prompt,m)}}]}))}}return i};var F=require("@modelcontextprotocol/sdk/client/index.js"),J=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var k=class{constructor(e){this.config=e}async getWarpsFromTools(e,r){let n=new J.StreamableHTTPClientTransport(new URL(e),{requestInit:{headers:r||{}}}),i=new F.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(n);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(c=>R(this.config,c,e,r)))}catch(o){throw await i.close().catch(()=>{}),o}}};0&&(module.exports={WarpMcp,buildWarpDirectIdentifierFromMcpToolCall,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertPromptActionToPrompt,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractTextOrUndefined,hasMcpAppUi,interpolatePromptWithArgs,isMcpToolCallAllowedForWarp,normalizeMcpToolNameToWarpIdentifier,resolveMcpAppInputsPayload,resolveMcpAppOutputPayload,resolveMcpAppWarpEmbedModel,resolveMcpToolCallToWarpDirect});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWarpPrimaryAction as
|
|
1
|
+
var g=t=>!t||typeof t!="object"||Array.isArray(t)?null:t,k=t=>t==null?null:typeof t=="string"?t:JSON.stringify(t),z=t=>{let e=g(t.query);if(e)return e;let n=g(t.contentInputs);if(n)return n;let r=t.metaInputs||[];return r.length>0?{inputs:r}:null},O=t=>g(t.metaOutput)||g(t.contentOutput),ct=t=>({isMcpApp:q(t.ui),inputsPayload:z({query:t.query,contentInputs:t.contentInputs,metaInputs:t.metaInputs}),outputPayload:O({metaOutput:t.metaOutput,contentOutput:t.contentOutput})}),q=t=>typeof t=="string"&&t!=="table",y=t=>!t||t.startsWith("@")?t:t.includes(":")?`@${t.replace(/^@/,"")}`:t,v=t=>t.activeWarpIdentifier?y(t.requestedToolName)===y(t.activeWarpIdentifier):!0,E=(t,e={})=>{let n=y(t),r=new URLSearchParams;return Object.entries(e).forEach(([i,o])=>{let c=k(o);c!=null&&r.set(i,c)}),r.size>0?`${n}?${r.toString()}`:n},at=t=>{let e=v({requestedToolName:t.requestedToolName,activeWarpIdentifier:t.activeWarpIdentifier}),n=E(t.requestedToolName,t.args||{});return{allowed:e,warpIdentifier:n}};import{getWarpPrimaryAction as _}from"@joai/warps";var T=(t,e)=>{let{action:n}=_(t);return n.inputs?n.inputs.map(r=>{let i=r.as||r.name,o=e[i]??r.default??null;return o===null&&r.type==="bool"?"false":o==null?"":String(o)}):[]};import{WarpBuilder as F,getWarpPrimaryAction as J,resolveWarpText as L}from"@joai/warps";import{removeWarpChainPrefix as Z}from"@joai/warps";import{z as l}from"zod";var $=t=>{if(t){if(Array.isArray(t))return t;if(typeof t=="object")return Object.keys(t)}},j=(t,e)=>{let n,r=t.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=l.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=l.number():r==="bool"||r==="boolean"?n=l.boolean():r==="biguint"?n=l.string():n=l.string(),typeof t.min=="number"&&n instanceof l.ZodNumber&&(n=n.min(t.min)),typeof t.max=="number"&&n instanceof l.ZodNumber&&(n=n.max(t.max)),t.pattern&&n instanceof l.ZodString&&(n=n.regex(new RegExp(t.pattern)));let i=$(t.options);if(i&&i.length>0){if(n instanceof l.ZodString)n=l.enum(i);else if(n instanceof l.ZodNumber){let u=i.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(n=n.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],c=f(t.description,e);c&&o.push(c),t.bot&&o.push(t.bot),o.push(`Type: ${t.type}`),o.push(t.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let p=f(t.patternDescription,e);p&&o.push(p);let a=o.join(". ");return a&&(n=n.describe(a)),t.required!==!0&&(n=n.optional()),n},A=(t,e)=>{let n={};for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=j(r,e)}return Object.keys(n).length>0?n:void 0},M=(t,e,n,r,i,o)=>{let c=U(t),p=r||e.inputs||[],a=A(p,o);return{name:c,description:n,inputSchema:a,meta:b(t,i,o)}},h=(t,e,n,r,i,o)=>{let c=r||e.inputs||[],p=A(c,o),a=e.destination?.tool;if(!a)throw new Error(`Tool name is required for MCP action ${e.type}`);return{name:a,description:n,inputSchema:p,meta:b(t,i,o)}},b=(t,e,n)=>{let r={visibility:["model","app"]};return e&&(r.resourceUri=e.uri),{ui:r}},U=t=>{let e=t.meta?.identifier;if(!e)throw new Error(`Warp identifier for warp ${t.name} is required`);return Z(e)};import{WarpLogger as C}from"@joai/warps";var N="text/html;profile=mcp-app",D=async t=>{if(t.startsWith("http://")||t.startsWith("https://")){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to download component from ${t}: HTTP ${e.status} ${e.statusText}`);return e.text()}throw new Error(`Unsupported component path: ${t}`)},P=async(t,e,n)=>{if(!t.meta?.identifier)return null;try{let r=await D(e);return{name:t.name,uri:`ui://widget/${t.meta.identifier}`,description:`MCP app for ${t.name}`,mimeType:N,content:r}}catch(r){let i=r instanceof Error?r.message:String(r),o=r instanceof Error?r.stack:void 0;return C.error(`[MCP] Failed to create app resource for warp "${t.name}" (path: ${e}):`,i),o&&C.error("[MCP] Error stack:",o),null}};var V=async(t,e)=>{let n=null,r=null,i=null;if(t.ui&&t.ui!=="table"&&(r=await P(t,t.ui,e)),t.actions.length===0)return{tool:null,resource:r,prompt:null};try{let{action:o}=J(t),c=f(t.description,e)||f(o.description,e);if(o.type==="prompt")i=w(t,o,c,e);else if(o.type==="mcp"){let p=o;p.destination&&(n=h(t,p,c,o.inputs,r,e))}else n=M(t,o,c,o.inputs,r,e)}catch{return{tool:null,resource:r,prompt:null}}return{tool:n,resource:r,prompt:i}},Ft=async(t,e)=>Promise.all(t.map(n=>V(n,e))),H=(t,e)=>e==="date-time"||e==="date"||t==="string"?"string":t==="number"||t==="integer"?"uint256":t==="boolean"?"bool":"string",x=async(t,e,n,r)=>{let i=[];if(e.inputSchema?.properties){let p=e.inputSchema.properties,a=e.inputSchema.required||[];Object.entries(p).forEach(([u,s])=>{let m=a.includes(u),d=H(s.type||"string",s.format),W={name:u,label:typeof s.title=="string"?{en:s.title}:s.title||{en:u},description:s.description?{en:s.description.trim()}:null,type:d,position:`payload:${u}`,source:"field",required:m,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(W)})}let o={};e.outputSchema?.properties&&Object.keys(e.outputSchema.properties).forEach(p=>{o[p]=`out.${p}`});let c={type:"mcp",label:{en:e.name},description:e.description?{en:e.description.trim()}:null,destination:{url:n,tool:e.name,headers:r},inputs:i};return await new F(t).setName(e.name||"unnamed_tool").setTitle({en:e.name||"Unnamed Tool"}).setDescription(e.description?{en:e.description.trim()}:null).addAction(c).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(t,e)=>t&&L(t,e)||void 0;var R=(t,e)=>{let n=t;for(let[r,i]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},Q=t=>(t.includes(":")?t.split(":").slice(1).join(":"):t).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,e=>e.includes("_")?"_":e).replace(/_+/g,"_"),Y=(t,e)=>{let n=[];for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name,o=f(r.description,e);n.push({name:i,description:o,required:r.required===!0})}return n},w=(t,e,n,r)=>{let i=Q(t.name),o=e.inputs||[],c=Y(o,r);return{name:i,description:n,arguments:c.length>0?c:void 0,prompt:e.prompt}};import{McpServer as B}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as G}from"@modelcontextprotocol/sdk/server/zod-compat.js";import{RESOURCE_MIME_TYPE as K,registerAppTool as X,registerAppResource as tt}from"@modelcontextprotocol/ext-apps/server";import{z as et}from"zod";var rt=t=>{if(t)return typeof t=="object"&&"_zod"in t?t._zod:typeof t=="object"&&!Array.isArray(t)&&G(t)||t},nt=t=>{if(!t.arguments||t.arguments.length===0)return;let e={};for(let n of t.arguments){let r=et.string();n.description&&(r=r.describe(n.description)),n.required||(r=r.optional()),e[n.name]=r}return e},ot=(t,e)=>t.startsWith("ui://")?!0:e?.includes("profile=mcp-app")??!1,Xt=(t,e,n,r)=>{let i=new B({name:t.name,version:t.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:c,resource:p,prompt:a}=n[o],u=e[o];if(c){let s=rt(c.inputSchema),m={description:c.description||"",inputSchema:s,...c.meta&&{_meta:c.meta}},d=async W=>{let S=T(u,W||{});return await r(u,S)};c.meta?.ui?.resourceUri?X(i,c.name,m,d):i.registerTool(c.name,m,d)}if(p)if(ot(p.uri,p.mimeType)){let s=p.meta,m=p.mimeType||K;tt(i,p.name||p.uri,p.uri,{description:p.description,mimeType:m,...s&&{_meta:s}},async()=>{let d={uri:p.uri,text:p.content||"",mimeType:m};return s&&(d._meta=s),{contents:[d]}})}else i.registerResource(p.name||p.uri,p.uri,{description:p.description,mimeType:p.mimeType},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}});if(a){let s=nt(a);i.registerPrompt(a.name,{description:a.description||"",argsSchema:s},m=>({messages:[{role:"user",content:{type:"text",text:R(a.prompt,m)}}]}))}}return i};import{Client as it}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as pt}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var I=class{constructor(e){this.config=e}async getWarpsFromTools(e,n){let r=new pt(new URL(e),{requestInit:{headers:n||{}}}),i=new it({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(r);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(c=>x(this.config,c,e,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};export{I as WarpMcp,E as buildWarpDirectIdentifierFromMcpToolCall,A as buildZodInputSchema,M as convertActionToTool,h as convertMcpActionToTool,T as convertMcpArgsToWarpInputs,x as convertMcpToolToWarp,w as convertPromptActionToPrompt,V as convertWarpToMcpCapabilities,Ft as convertWarpsToMcpCapabilities,P as createAppResource,Xt as createMcpServerFromWarps,f as extractTextOrUndefined,q as hasMcpAppUi,R as interpolatePromptWithArgs,v as isMcpToolCallAllowedForWarp,y as normalizeMcpToolNameToWarpIdentifier,z as resolveMcpAppInputsPayload,O as resolveMcpAppOutputPayload,ct as resolveMcpAppWarpEmbedModel,at as resolveMcpToolCallToWarpDirect};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joai/warps-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "MCP adapter for Warps SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@modelcontextprotocol/ext-apps": "^1.
|
|
41
|
+
"@modelcontextprotocol/ext-apps": "^1.1.2",
|
|
42
42
|
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
43
43
|
"zod": "^4.3.5"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@joai/warps": "^3.
|
|
46
|
+
"@joai/warps": "^3.4.0"
|
|
47
47
|
}
|
|
48
48
|
}
|