@sequenzy/mcp 0.0.41 → 0.0.42

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.js CHANGED
@@ -27,7 +27,7 @@ var w5=Object.create;var{getPrototypeOf:b5,defineProperty:BQ,getOwnPropertyNames
27
27
 
28
28
  `)}L.write("payload.value = newResult;"),L.write("return payload;");let S=L.compile();return(E,x)=>S(B,E,x)},$,J=B1,z=!l4.jitless,U=z&&FQ.value,A=X.catchall,K;Q._zod.parse=(B,L)=>{K??(K=W.value);let F=B.value;if(!J(F))return B.issues.push({expected:"object",code:"invalid_type",input:F,inst:Q}),B;if(z&&U&&L?.async===!1&&L.jitless!==!0){if(!$)$=G(X.shape);if(B=$(B,L),!A)return B;return RY([],F,B,L,K,Q)}return Y(B,L)}});function n8(Q,X,Y,W){for(let $ of Q)if($.issues.length===0)return X.value=$.value,X;let G=Q.filter(($)=>!Q1($));if(G.length===1)return X.value=G[0].value,G[0];return X.issues.push({code:"invalid_union",input:X.value,inst:Y,errors:Q.map(($)=>$.issues.map((J)=>T0(J,W,w0())))}),X}var TQ=q("$ZodUnion",(Q,X)=>{i.init(Q,X),m(Q._zod,"optin",()=>X.options.some((G)=>G._zod.optin==="optional")?"optional":void 0),m(Q._zod,"optout",()=>X.options.some((G)=>G._zod.optout==="optional")?"optional":void 0),m(Q._zod,"values",()=>{if(X.options.every((G)=>G._zod.values))return new Set(X.options.flatMap((G)=>Array.from(G._zod.values)));return}),m(Q._zod,"pattern",()=>{if(X.options.every((G)=>G._zod.pattern)){let G=X.options.map(($)=>$._zod.pattern);return new RegExp(`^(${G.map(($)=>r1($.source)).join("|")})$`)}return});let Y=X.options.length===1,W=X.options[0]._zod.run;Q._zod.parse=(G,$)=>{if(Y)return W(G,$);let J=!1,z=[];for(let H of X.options){let U=H._zod.run({value:G.value,issues:[]},$);if(U instanceof Promise)z.push(U),J=!0;else{if(U.issues.length===0)return U;z.push(U)}}if(!J)return n8(z,G,Q,$);return Promise.all(z).then((H)=>{return n8(H,G,Q,$)})}}),kY=q("$ZodDiscriminatedUnion",(Q,X)=>{TQ.init(Q,X);let Y=Q._zod.parse;m(Q._zod,"propValues",()=>{let G={};for(let $ of X.options){let J=$._zod.propValues;if(!J||Object.keys(J).length===0)throw Error(`Invalid discriminated union option at index "${X.options.indexOf($)}"`);for(let[z,H]of Object.entries(J)){if(!G[z])G[z]=new Set;for(let U of H)G[z].add(U)}}return G});let W=b1(()=>{let G=X.options,$=new Map;for(let J of G){let z=J._zod.propValues?.[X.discriminator];if(!z||z.size===0)throw Error(`Invalid discriminated union option at index "${X.options.indexOf(J)}"`);for(let H of z){if($.has(H))throw Error(`Duplicate discriminator value "${String(H)}"`);$.set(H,J)}}return $});Q._zod.parse=(G,$)=>{let J=G.value;if(!B1(J))return G.issues.push({code:"invalid_type",expected:"object",input:J,inst:Q}),G;let z=W.value.get(J?.[X.discriminator]);if(z)return z._zod.run(G,$);if(X.unionFallback)return Y(G,$);return G.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:X.discriminator,input:J,path:[X.discriminator],inst:Q}),G}}),vY=q("$ZodIntersection",(Q,X)=>{i.init(Q,X),Q._zod.parse=(Y,W)=>{let G=Y.value,$=X.left._zod.run({value:G,issues:[]},W),J=X.right._zod.run({value:G,issues:[]},W);if($ instanceof Promise||J instanceof Promise)return Promise.all([$,J]).then(([H,U])=>{return r8(Y,H,U)});return r8(Y,$,J)}});function IQ(Q,X){if(Q===X)return{valid:!0,data:Q};if(Q instanceof Date&&X instanceof Date&&+Q===+X)return{valid:!0,data:Q};if(e0(Q)&&e0(X)){let Y=Object.keys(X),W=Object.keys(Q).filter(($)=>Y.indexOf($)!==-1),G={...Q,...X};for(let $ of W){let J=IQ(Q[$],X[$]);if(!J.valid)return{valid:!1,mergeErrorPath:[$,...J.mergeErrorPath]};G[$]=J.data}return{valid:!0,data:G}}if(Array.isArray(Q)&&Array.isArray(X)){if(Q.length!==X.length)return{valid:!1,mergeErrorPath:[]};let Y=[];for(let W=0;W<Q.length;W++){let G=Q[W],$=X[W],J=IQ(G,$);if(!J.valid)return{valid:!1,mergeErrorPath:[W,...J.mergeErrorPath]};Y.push(J.data)}return{valid:!0,data:Y}}return{valid:!1,mergeErrorPath:[]}}function r8(Q,X,Y){if(X.issues.length)Q.issues.push(...X.issues);if(Y.issues.length)Q.issues.push(...Y.issues);if(Q1(Q))return Q;let W=IQ(X.value,Y.value);if(!W.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(W.mergeErrorPath)}`);return Q.value=W.data,Q}var xY=q("$ZodRecord",(Q,X)=>{i.init(Q,X),Q._zod.parse=(Y,W)=>{let G=Y.value;if(!e0(G))return Y.issues.push({expected:"record",code:"invalid_type",input:G,inst:Q}),Y;let $=[];if(X.keyType._zod.values){let J=X.keyType._zod.values;Y.value={};for(let H of J)if(typeof H==="string"||typeof H==="number"||typeof H==="symbol"){let U=X.valueType._zod.run({value:G[H],issues:[]},W);if(U instanceof Promise)$.push(U.then((A)=>{if(A.issues.length)Y.issues.push(...c0(H,A.issues));Y.value[H]=A.value}));else{if(U.issues.length)Y.issues.push(...c0(H,U.issues));Y.value[H]=U.value}}let z;for(let H in G)if(!J.has(H))z=z??[],z.push(H);if(z&&z.length>0)Y.issues.push({code:"unrecognized_keys",input:G,inst:Q,keys:z})}else{Y.value={};for(let J of Reflect.ownKeys(G)){if(J==="__proto__")continue;let z=X.keyType._zod.run({value:J,issues:[]},W);if(z instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(z.issues.length){Y.issues.push({code:"invalid_key",origin:"record",issues:z.issues.map((U)=>T0(U,W,w0())),input:J,path:[J],inst:Q}),Y.value[z.value]=z.value;continue}let H=X.valueType._zod.run({value:G[J],issues:[]},W);if(H instanceof Promise)$.push(H.then((U)=>{if(U.issues.length)Y.issues.push(...c0(J,U.issues));Y.value[z.value]=U.value}));else{if(H.issues.length)Y.issues.push(...c0(J,H.issues));Y.value[z.value]=H.value}}}if($.length)return Promise.all($).then(()=>Y);return Y}});var _Y=q("$ZodEnum",(Q,X)=>{i.init(Q,X);let Y=LQ(X.entries),W=new Set(Y);Q._zod.values=W,Q._zod.pattern=new RegExp(`^(${Y.filter((G)=>OQ.has(typeof G)).map((G)=>typeof G==="string"?m0(G):G.toString()).join("|")})$`),Q._zod.parse=(G,$)=>{let J=G.value;if(W.has(J))return G;return G.issues.push({code:"invalid_value",values:Y,input:J,inst:Q}),G}}),yY=q("$ZodLiteral",(Q,X)=>{if(i.init(Q,X),X.values.length===0)throw Error("Cannot create literal schema with no valid values");Q._zod.values=new Set(X.values),Q._zod.pattern=new RegExp(`^(${X.values.map((Y)=>typeof Y==="string"?m0(Y):Y?m0(Y.toString()):String(Y)).join("|")})$`),Q._zod.parse=(Y,W)=>{let G=Y.value;if(Q._zod.values.has(G))return Y;return Y.issues.push({code:"invalid_value",values:X.values,input:G,inst:Q}),Y}});var gY=q("$ZodTransform",(Q,X)=>{i.init(Q,X),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")throw new p1(Q.constructor.name);let G=X.transform(Y.value,Y);if(W.async)return(G instanceof Promise?G:Promise.resolve(G)).then((J)=>{return Y.value=J,Y});if(G instanceof Promise)throw new l0;return Y.value=G,Y}});function d8(Q,X){if(Q.issues.length&&X===void 0)return{issues:[],value:void 0};return Q}var uY=q("$ZodOptional",(Q,X)=>{i.init(Q,X),Q._zod.optin="optional",Q._zod.optout="optional",m(Q._zod,"values",()=>{return X.innerType._zod.values?new Set([...X.innerType._zod.values,void 0]):void 0}),m(Q._zod,"pattern",()=>{let Y=X.innerType._zod.pattern;return Y?new RegExp(`^(${r1(Y.source)})?$`):void 0}),Q._zod.parse=(Y,W)=>{if(X.innerType._zod.optin==="optional"){let G=X.innerType._zod.run(Y,W);if(G instanceof Promise)return G.then(($)=>d8($,Y.value));return d8(G,Y.value)}if(Y.value===void 0)return Y;return X.innerType._zod.run(Y,W)}}),hY=q("$ZodNullable",(Q,X)=>{i.init(Q,X),m(Q._zod,"optin",()=>X.innerType._zod.optin),m(Q._zod,"optout",()=>X.innerType._zod.optout),m(Q._zod,"pattern",()=>{let Y=X.innerType._zod.pattern;return Y?new RegExp(`^(${r1(Y.source)}|null)$`):void 0}),m(Q._zod,"values",()=>{return X.innerType._zod.values?new Set([...X.innerType._zod.values,null]):void 0}),Q._zod.parse=(Y,W)=>{if(Y.value===null)return Y;return X.innerType._zod.run(Y,W)}}),fY=q("$ZodDefault",(Q,X)=>{i.init(Q,X),Q._zod.optin="optional",m(Q._zod,"values",()=>X.innerType._zod.values),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")return X.innerType._zod.run(Y,W);if(Y.value===void 0)return Y.value=X.defaultValue,Y;let G=X.innerType._zod.run(Y,W);if(G instanceof Promise)return G.then(($)=>o8($,X));return o8(G,X)}});function o8(Q,X){if(Q.value===void 0)Q.value=X.defaultValue;return Q}var lY=q("$ZodPrefault",(Q,X)=>{i.init(Q,X),Q._zod.optin="optional",m(Q._zod,"values",()=>X.innerType._zod.values),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")return X.innerType._zod.run(Y,W);if(Y.value===void 0)Y.value=X.defaultValue;return X.innerType._zod.run(Y,W)}}),mY=q("$ZodNonOptional",(Q,X)=>{i.init(Q,X),m(Q._zod,"values",()=>{let Y=X.innerType._zod.values;return Y?new Set([...Y].filter((W)=>W!==void 0)):void 0}),Q._zod.parse=(Y,W)=>{let G=X.innerType._zod.run(Y,W);if(G instanceof Promise)return G.then(($)=>t8($,Q));return t8(G,Q)}});function t8(Q,X){if(!Q.issues.length&&Q.value===void 0)Q.issues.push({code:"invalid_type",expected:"nonoptional",input:Q.value,inst:X});return Q}var cY=q("$ZodCatch",(Q,X)=>{i.init(Q,X),m(Q._zod,"optin",()=>X.innerType._zod.optin),m(Q._zod,"optout",()=>X.innerType._zod.optout),m(Q._zod,"values",()=>X.innerType._zod.values),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")return X.innerType._zod.run(Y,W);let G=X.innerType._zod.run(Y,W);if(G instanceof Promise)return G.then(($)=>{if(Y.value=$.value,$.issues.length)Y.value=X.catchValue({...Y,error:{issues:$.issues.map((J)=>T0(J,W,w0()))},input:Y.value}),Y.issues=[];return Y});if(Y.value=G.value,G.issues.length)Y.value=X.catchValue({...Y,error:{issues:G.issues.map(($)=>T0($,W,w0()))},input:Y.value}),Y.issues=[];return Y}});var pY=q("$ZodPipe",(Q,X)=>{i.init(Q,X),m(Q._zod,"values",()=>X.in._zod.values),m(Q._zod,"optin",()=>X.in._zod.optin),m(Q._zod,"optout",()=>X.out._zod.optout),m(Q._zod,"propValues",()=>X.in._zod.propValues),Q._zod.parse=(Y,W)=>{if(W.direction==="backward"){let $=X.out._zod.run(Y,W);if($ instanceof Promise)return $.then((J)=>a4(J,X.in,W));return a4($,X.in,W)}let G=X.in._zod.run(Y,W);if(G instanceof Promise)return G.then(($)=>a4($,X.out,W));return a4(G,X.out,W)}});function a4(Q,X,Y){if(Q.issues.length)return Q.aborted=!0,Q;return X._zod.run({value:Q.value,issues:Q.issues},Y)}var iY=q("$ZodReadonly",(Q,X)=>{i.init(Q,X),m(Q._zod,"propValues",()=>X.innerType._zod.propValues),m(Q._zod,"values",()=>X.innerType._zod.values),m(Q._zod,"optin",()=>X.innerType._zod.optin),m(Q._zod,"optout",()=>X.innerType._zod.optout),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")return X.innerType._zod.run(Y,W);let G=X.innerType._zod.run(Y,W);if(G instanceof Promise)return G.then(a8);return a8(G)}});function a8(Q){return Q.value=Object.freeze(Q.value),Q}var nY=q("$ZodCustom",(Q,X)=>{W0.init(Q,X),i.init(Q,X),Q._zod.parse=(Y,W)=>{return Y},Q._zod.check=(Y)=>{let W=Y.value,G=X.fn(W);if(G instanceof Promise)return G.then(($)=>s8($,Y,W,Q));s8(G,Y,W,Q);return}});function s8(Q,X,Y,W){if(!Q){let G={code:"custom",input:Y,inst:W,path:[...W._zod.def.path??[]],continue:!W._zod.def.abort};if(W._zod.def.params)G.params=W._zod.def.params;X.issues.push(P1(G))}}var HH=(Q)=>{let X=typeof Q;switch(X){case"number":return Number.isNaN(Q)?"NaN":"number";case"object":{if(Array.isArray(Q))return"array";if(Q===null)return"null";if(Object.getPrototypeOf(Q)!==Object.prototype&&Q.constructor)return Q.constructor.name}}return X},UH=()=>{let Q={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"}};function X(W){return Q[W]??null}let Y={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"};return(W)=>{switch(W.code){case"invalid_type":return`Invalid input: expected ${W.expected}, received ${HH(W.input)}`;case"invalid_value":if(W.values.length===1)return`Invalid input: expected ${i4(W.values[0])}`;return`Invalid option: expected one of ${m4(W.values,"|")}`;case"too_big":{let G=W.inclusive?"<=":"<",$=X(W.origin);if($)return`Too big: expected ${W.origin??"value"} to have ${G}${W.maximum.toString()} ${$.unit??"elements"}`;return`Too big: expected ${W.origin??"value"} to be ${G}${W.maximum.toString()}`}case"too_small":{let G=W.inclusive?">=":">",$=X(W.origin);if($)return`Too small: expected ${W.origin} to have ${G}${W.minimum.toString()} ${$.unit}`;return`Too small: expected ${W.origin} to be ${G}${W.minimum.toString()}`}case"invalid_format":{let G=W;if(G.format==="starts_with")return`Invalid string: must start with "${G.prefix}"`;if(G.format==="ends_with")return`Invalid string: must end with "${G.suffix}"`;if(G.format==="includes")return`Invalid string: must include "${G.includes}"`;if(G.format==="regex")return`Invalid string: must match pattern ${G.pattern}`;return`Invalid ${Y[G.format]??W.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${W.divisor}`;case"unrecognized_keys":return`Unrecognized key${W.keys.length>1?"s":""}: ${m4(W.keys,", ")}`;case"invalid_key":return`Invalid key in ${W.origin}`;case"invalid_union":return"Invalid input";case"invalid_element":return`Invalid value in ${W.origin}`;default:return"Invalid input"}}};function SQ(){return{localeError:UH()}}var mM=Symbol("ZodOutput"),cM=Symbol("ZodInput");class rY{constructor(){this._map=new WeakMap,this._idmap=new Map}add(Q,...X){let Y=X[0];if(this._map.set(Q,Y),Y&&typeof Y==="object"&&"id"in Y){if(this._idmap.has(Y.id))throw Error(`ID ${Y.id} already exists in the registry`);this._idmap.set(Y.id,Q)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(Q){let X=this._map.get(Q);if(X&&typeof X==="object"&&"id"in X)this._idmap.delete(X.id);return this._map.delete(Q),this}get(Q){let X=Q._zod.parent;if(X){let Y={...this.get(X)??{}};delete Y.id;let W={...Y,...this._map.get(Q)};return Object.keys(W).length?W:void 0}return this._map.get(Q)}has(Q){return this._map.has(Q)}}function AH(){return new rY}var e1=AH();function dY(Q,X){return new Q({type:"string",...I(X)})}function oY(Q,X){return new Q({type:"string",format:"email",check:"string_format",abort:!1,...I(X)})}function RQ(Q,X){return new Q({type:"string",format:"guid",check:"string_format",abort:!1,...I(X)})}function tY(Q,X){return new Q({type:"string",format:"uuid",check:"string_format",abort:!1,...I(X)})}function aY(Q,X){return new Q({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...I(X)})}function sY(Q,X){return new Q({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...I(X)})}function eY(Q,X){return new Q({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...I(X)})}function QW(Q,X){return new Q({type:"string",format:"url",check:"string_format",abort:!1,...I(X)})}function XW(Q,X){return new Q({type:"string",format:"emoji",check:"string_format",abort:!1,...I(X)})}function YW(Q,X){return new Q({type:"string",format:"nanoid",check:"string_format",abort:!1,...I(X)})}function WW(Q,X){return new Q({type:"string",format:"cuid",check:"string_format",abort:!1,...I(X)})}function GW(Q,X){return new Q({type:"string",format:"cuid2",check:"string_format",abort:!1,...I(X)})}function $W(Q,X){return new Q({type:"string",format:"ulid",check:"string_format",abort:!1,...I(X)})}function JW(Q,X){return new Q({type:"string",format:"xid",check:"string_format",abort:!1,...I(X)})}function zW(Q,X){return new Q({type:"string",format:"ksuid",check:"string_format",abort:!1,...I(X)})}function HW(Q,X){return new Q({type:"string",format:"ipv4",check:"string_format",abort:!1,...I(X)})}function UW(Q,X){return new Q({type:"string",format:"ipv6",check:"string_format",abort:!1,...I(X)})}function AW(Q,X){return new Q({type:"string",format:"cidrv4",check:"string_format",abort:!1,...I(X)})}function KW(Q,X){return new Q({type:"string",format:"cidrv6",check:"string_format",abort:!1,...I(X)})}function BW(Q,X){return new Q({type:"string",format:"base64",check:"string_format",abort:!1,...I(X)})}function DW(Q,X){return new Q({type:"string",format:"base64url",check:"string_format",abort:!1,...I(X)})}function LW(Q,X){return new Q({type:"string",format:"e164",check:"string_format",abort:!1,...I(X)})}function qW(Q,X){return new Q({type:"string",format:"jwt",check:"string_format",abort:!1,...I(X)})}function FW(Q,X){return new Q({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...I(X)})}function OW(Q,X){return new Q({type:"string",format:"date",check:"string_format",...I(X)})}function MW(Q,X){return new Q({type:"string",format:"time",check:"string_format",precision:null,...I(X)})}function VW(Q,X){return new Q({type:"string",format:"duration",check:"string_format",...I(X)})}function ZW(Q,X){return new Q({type:"number",checks:[],...I(X)})}function NW(Q,X){return new Q({type:"number",check:"number_format",abort:!1,format:"safeint",...I(X)})}function wW(Q,X){return new Q({type:"boolean",...I(X)})}function bW(Q,X){return new Q({type:"null",...I(X)})}function PW(Q){return new Q({type:"unknown"})}function jW(Q,X){return new Q({type:"never",...I(X)})}function Q6(Q,X){return new bQ({check:"less_than",...I(X),value:Q,inclusive:!1})}function Q4(Q,X){return new bQ({check:"less_than",...I(X),value:Q,inclusive:!0})}function X6(Q,X){return new PQ({check:"greater_than",...I(X),value:Q,inclusive:!1})}function X4(Q,X){return new PQ({check:"greater_than",...I(X),value:Q,inclusive:!0})}function Y6(Q,X){return new C8({check:"multiple_of",...I(X),value:Q})}function W6(Q,X){return new v8({check:"max_length",...I(X),maximum:Q})}function j1(Q,X){return new x8({check:"min_length",...I(X),minimum:Q})}function G6(Q,X){return new _8({check:"length_equals",...I(X),length:Q})}function CQ(Q,X){return new y8({check:"string_format",format:"regex",...I(X),pattern:Q})}function kQ(Q){return new g8({check:"string_format",format:"lowercase",...I(Q)})}function vQ(Q){return new u8({check:"string_format",format:"uppercase",...I(Q)})}function xQ(Q,X){return new h8({check:"string_format",format:"includes",...I(X),includes:Q})}function _Q(Q,X){return new f8({check:"string_format",format:"starts_with",...I(X),prefix:Q})}function yQ(Q,X){return new l8({check:"string_format",format:"ends_with",...I(X),suffix:Q})}function D1(Q){return new m8({check:"overwrite",tx:Q})}function gQ(Q){return D1((X)=>X.normalize(Q))}function uQ(){return D1((Q)=>Q.trim())}function hQ(){return D1((Q)=>Q.toLowerCase())}function fQ(){return D1((Q)=>Q.toUpperCase())}function IW(Q,X,Y){return new Q({type:"array",element:X,...I(Y)})}function EW(Q,X,Y){let W=I(Y);return W.abort??(W.abort=!0),new Q({type:"custom",check:"custom",fn:X,...W})}function TW(Q,X,Y){return new Q({type:"custom",check:"custom",fn:X,...I(Y)})}function SW(Q){let X=KH((Y)=>{return Y.addIssue=(W)=>{if(typeof W==="string")Y.issues.push(P1(W,Y.value,X._zod.def));else{let G=W;if(G.fatal)G.continue=!1;G.code??(G.code="custom"),G.input??(G.input=Y.value),G.inst??(G.inst=X),G.continue??(G.continue=!X._zod.def.abort),Y.issues.push(P1(G))}},Q(Y.value,Y)});return X}function KH(Q,X){let Y=new W0({check:"custom",...I(X)});return Y._zod.check=Q,Y}function I1(Q){return!!Q._zod}function X1(Q,X){if(I1(Q))return t1(Q,X);return Q.safeParse(X)}function $6(Q){if(!Q)return;let X;if(I1(Q))X=Q._zod?.def?.shape;else X=Q.shape;if(!X)return;if(typeof X==="function")try{return X()}catch{return}return X}function RW(Q){if(I1(Q)){let $=Q._zod?.def;if($){if($.value!==void 0)return $.value;if(Array.isArray($.values)&&$.values.length>0)return $.values[0]}}let Y=Q._def;if(Y){if(Y.value!==void 0)return Y.value;if(Array.isArray(Y.values)&&Y.values.length>0)return Y.values[0]}let W=Q.value;if(W!==void 0)return W;return}var W4={};_X(W4,{time:()=>cQ,duration:()=>pQ,datetime:()=>lQ,date:()=>mQ,ZodISOTime:()=>vW,ZodISODuration:()=>xW,ZodISODateTime:()=>CW,ZodISODate:()=>kW});var CW=q("ZodISODateTime",(Q,X)=>{AY.init(Q,X),d.init(Q,X)});function lQ(Q){return FW(CW,Q)}var kW=q("ZodISODate",(Q,X)=>{KY.init(Q,X),d.init(Q,X)});function mQ(Q){return OW(kW,Q)}var vW=q("ZodISOTime",(Q,X)=>{BY.init(Q,X),d.init(Q,X)});function cQ(Q){return MW(vW,Q)}var xW=q("ZodISODuration",(Q,X)=>{DY.init(Q,X),d.init(Q,X)});function pQ(Q){return VW(xW,Q)}var _W=(Q,X)=>{n4.init(Q,X),Q.name="ZodError",Object.defineProperties(Q,{format:{value:(Y)=>nX(Q,Y)},flatten:{value:(Y)=>iX(Q,Y)},addIssue:{value:(Y)=>{Q.issues.push(Y),Q.message=JSON.stringify(Q.issues,w1,2)}},addIssues:{value:(Y)=>{Q.issues.push(...Y),Q.message=JSON.stringify(Q.issues,w1,2)}},isEmpty:{get(){return Q.issues.length===0}}})},TV=q("ZodError",_W),V0=q("ZodError",_W,{Parent:Error});var yW=r4(V0),gW=d4(V0),uW=o1(V0),hW=a1(V0),fW=rX(V0),lW=dX(V0),mW=oX(V0),cW=tX(V0),pW=aX(V0),iW=sX(V0),nW=eX(V0),rW=Q8(V0);var s=q("ZodType",(Q,X)=>{return i.init(Q,X),Q.def=X,Q.type=X.type,Object.defineProperty(Q,"_def",{value:X}),Q.check=(...Y)=>{return Q.clone(h.mergeDefs(X,{checks:[...X.checks??[],...Y.map((W)=>typeof W==="function"?{_zod:{check:W,def:{check:"custom"},onattach:[]}}:W)]}))},Q.clone=(Y,W)=>E0(Q,Y,W),Q.brand=()=>Q,Q.register=(Y,W)=>{return Y.add(Q,W),Q},Q.parse=(Y,W)=>yW(Q,Y,W,{callee:Q.parse}),Q.safeParse=(Y,W)=>uW(Q,Y,W),Q.parseAsync=async(Y,W)=>gW(Q,Y,W,{callee:Q.parseAsync}),Q.safeParseAsync=async(Y,W)=>hW(Q,Y,W),Q.spa=Q.safeParseAsync,Q.encode=(Y,W)=>fW(Q,Y,W),Q.decode=(Y,W)=>lW(Q,Y,W),Q.encodeAsync=async(Y,W)=>mW(Q,Y,W),Q.decodeAsync=async(Y,W)=>cW(Q,Y,W),Q.safeEncode=(Y,W)=>pW(Q,Y,W),Q.safeDecode=(Y,W)=>iW(Q,Y,W),Q.safeEncodeAsync=async(Y,W)=>nW(Q,Y,W),Q.safeDecodeAsync=async(Y,W)=>rW(Q,Y,W),Q.refine=(Y,W)=>Q.check(z3(Y,W)),Q.superRefine=(Y)=>Q.check(H3(Y)),Q.overwrite=(Y)=>Q.check(D1(Y)),Q.optional=()=>a(Q),Q.nullable=()=>tW(Q),Q.nullish=()=>a(tW(Q)),Q.nonoptional=(Y)=>X3(Q,Y),Q.array=()=>_(Q),Q.or=(Y)=>p([Q,Y]),Q.and=(Y)=>z6(Q,Y),Q.transform=(Y)=>nQ(Q,XG(Y)),Q.default=(Y)=>sH(Q,Y),Q.prefault=(Y)=>Q3(Q,Y),Q.catch=(Y)=>W3(Q,Y),Q.pipe=(Y)=>nQ(Q,Y),Q.readonly=()=>J3(Q),Q.describe=(Y)=>{let W=Q.clone();return e1.add(W,{description:Y}),W},Object.defineProperty(Q,"description",{get(){return e1.get(Q)?.description},configurable:!0}),Q.meta=(...Y)=>{if(Y.length===0)return e1.get(Q);let W=Q.clone();return e1.add(W,Y[0]),W},Q.isOptional=()=>Q.safeParse(void 0).success,Q.isNullable=()=>Q.safeParse(null).success,Q}),aW=q("_ZodString",(Q,X)=>{e4.init(Q,X),s.init(Q,X);let Y=Q._zod.bag;Q.format=Y.format??null,Q.minLength=Y.minimum??null,Q.maxLength=Y.maximum??null,Q.regex=(...W)=>Q.check(CQ(...W)),Q.includes=(...W)=>Q.check(xQ(...W)),Q.startsWith=(...W)=>Q.check(_Q(...W)),Q.endsWith=(...W)=>Q.check(yQ(...W)),Q.min=(...W)=>Q.check(j1(...W)),Q.max=(...W)=>Q.check(W6(...W)),Q.length=(...W)=>Q.check(G6(...W)),Q.nonempty=(...W)=>Q.check(j1(1,...W)),Q.lowercase=(W)=>Q.check(kQ(W)),Q.uppercase=(W)=>Q.check(vQ(W)),Q.trim=()=>Q.check(uQ()),Q.normalize=(...W)=>Q.check(gQ(...W)),Q.toLowerCase=()=>Q.check(hQ()),Q.toUpperCase=()=>Q.check(fQ())}),ZH=q("ZodString",(Q,X)=>{e4.init(Q,X),aW.init(Q,X),Q.email=(Y)=>Q.check(oY(NH,Y)),Q.url=(Y)=>Q.check(QW(wH,Y)),Q.jwt=(Y)=>Q.check(qW(gH,Y)),Q.emoji=(Y)=>Q.check(XW(bH,Y)),Q.guid=(Y)=>Q.check(RQ(dW,Y)),Q.uuid=(Y)=>Q.check(tY(J6,Y)),Q.uuidv4=(Y)=>Q.check(aY(J6,Y)),Q.uuidv6=(Y)=>Q.check(sY(J6,Y)),Q.uuidv7=(Y)=>Q.check(eY(J6,Y)),Q.nanoid=(Y)=>Q.check(YW(PH,Y)),Q.guid=(Y)=>Q.check(RQ(dW,Y)),Q.cuid=(Y)=>Q.check(WW(jH,Y)),Q.cuid2=(Y)=>Q.check(GW(IH,Y)),Q.ulid=(Y)=>Q.check($W(EH,Y)),Q.base64=(Y)=>Q.check(BW(xH,Y)),Q.base64url=(Y)=>Q.check(DW(_H,Y)),Q.xid=(Y)=>Q.check(JW(TH,Y)),Q.ksuid=(Y)=>Q.check(zW(SH,Y)),Q.ipv4=(Y)=>Q.check(HW(RH,Y)),Q.ipv6=(Y)=>Q.check(UW(CH,Y)),Q.cidrv4=(Y)=>Q.check(AW(kH,Y)),Q.cidrv6=(Y)=>Q.check(KW(vH,Y)),Q.e164=(Y)=>Q.check(LW(yH,Y)),Q.datetime=(Y)=>Q.check(lQ(Y)),Q.date=(Y)=>Q.check(mQ(Y)),Q.time=(Y)=>Q.check(cQ(Y)),Q.duration=(Y)=>Q.check(pQ(Y))});function D(Q){return dY(ZH,Q)}var d=q("ZodStringFormat",(Q,X)=>{n.init(Q,X),aW.init(Q,X)}),NH=q("ZodEmail",(Q,X)=>{XY.init(Q,X),d.init(Q,X)});var dW=q("ZodGUID",(Q,X)=>{e8.init(Q,X),d.init(Q,X)});var J6=q("ZodUUID",(Q,X)=>{QY.init(Q,X),d.init(Q,X)});var wH=q("ZodURL",(Q,X)=>{YY.init(Q,X),d.init(Q,X)});var bH=q("ZodEmoji",(Q,X)=>{WY.init(Q,X),d.init(Q,X)});var PH=q("ZodNanoID",(Q,X)=>{GY.init(Q,X),d.init(Q,X)});var jH=q("ZodCUID",(Q,X)=>{$Y.init(Q,X),d.init(Q,X)});var IH=q("ZodCUID2",(Q,X)=>{JY.init(Q,X),d.init(Q,X)});var EH=q("ZodULID",(Q,X)=>{zY.init(Q,X),d.init(Q,X)});var TH=q("ZodXID",(Q,X)=>{HY.init(Q,X),d.init(Q,X)});var SH=q("ZodKSUID",(Q,X)=>{UY.init(Q,X),d.init(Q,X)});var RH=q("ZodIPv4",(Q,X)=>{LY.init(Q,X),d.init(Q,X)});var CH=q("ZodIPv6",(Q,X)=>{qY.init(Q,X),d.init(Q,X)});var kH=q("ZodCIDRv4",(Q,X)=>{FY.init(Q,X),d.init(Q,X)});var vH=q("ZodCIDRv6",(Q,X)=>{OY.init(Q,X),d.init(Q,X)});var xH=q("ZodBase64",(Q,X)=>{VY.init(Q,X),d.init(Q,X)});var _H=q("ZodBase64URL",(Q,X)=>{ZY.init(Q,X),d.init(Q,X)});var yH=q("ZodE164",(Q,X)=>{NY.init(Q,X),d.init(Q,X)});var gH=q("ZodJWT",(Q,X)=>{wY.init(Q,X),d.init(Q,X)});var sW=q("ZodNumber",(Q,X)=>{EQ.init(Q,X),s.init(Q,X),Q.gt=(W,G)=>Q.check(X6(W,G)),Q.gte=(W,G)=>Q.check(X4(W,G)),Q.min=(W,G)=>Q.check(X4(W,G)),Q.lt=(W,G)=>Q.check(Q6(W,G)),Q.lte=(W,G)=>Q.check(Q4(W,G)),Q.max=(W,G)=>Q.check(Q4(W,G)),Q.int=(W)=>Q.check(oW(W)),Q.safe=(W)=>Q.check(oW(W)),Q.positive=(W)=>Q.check(X6(0,W)),Q.nonnegative=(W)=>Q.check(X4(0,W)),Q.negative=(W)=>Q.check(Q6(0,W)),Q.nonpositive=(W)=>Q.check(Q4(0,W)),Q.multipleOf=(W,G)=>Q.check(Y6(W,G)),Q.step=(W,G)=>Q.check(Y6(W,G)),Q.finite=()=>Q;let Y=Q._zod.bag;Q.minValue=Math.max(Y.minimum??Number.NEGATIVE_INFINITY,Y.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,Q.maxValue=Math.min(Y.maximum??Number.POSITIVE_INFINITY,Y.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,Q.isInt=(Y.format??"").includes("int")||Number.isSafeInteger(Y.multipleOf??0.5),Q.isFinite=!0,Q.format=Y.format??null});function l(Q){return ZW(sW,Q)}var uH=q("ZodNumberFormat",(Q,X)=>{bY.init(Q,X),sW.init(Q,X)});function oW(Q){return NW(uH,Q)}var hH=q("ZodBoolean",(Q,X)=>{PY.init(Q,X),s.init(Q,X)});function Y0(Q){return wW(hH,Q)}var fH=q("ZodNull",(Q,X)=>{jY.init(Q,X),s.init(Q,X)});function rQ(Q){return bW(fH,Q)}var lH=q("ZodUnknown",(Q,X)=>{IY.init(Q,X),s.init(Q,X)});function o(){return PW(lH)}var mH=q("ZodNever",(Q,X)=>{EY.init(Q,X),s.init(Q,X)});function cH(Q){return jW(mH,Q)}var pH=q("ZodArray",(Q,X)=>{TY.init(Q,X),s.init(Q,X),Q.element=X.element,Q.min=(Y,W)=>Q.check(j1(Y,W)),Q.nonempty=(Y)=>Q.check(j1(1,Y)),Q.max=(Y,W)=>Q.check(W6(Y,W)),Q.length=(Y,W)=>Q.check(G6(Y,W)),Q.unwrap=()=>Q.element});function _(Q,X){return IW(pH,Q,X)}var eW=q("ZodObject",(Q,X)=>{CY.init(Q,X),s.init(Q,X),h.defineLazy(Q,"shape",()=>{return X.shape}),Q.keyof=()=>L0(Object.keys(Q._zod.def.shape)),Q.catchall=(Y)=>Q.clone({...Q._zod.def,catchall:Y}),Q.passthrough=()=>Q.clone({...Q._zod.def,catchall:o()}),Q.loose=()=>Q.clone({...Q._zod.def,catchall:o()}),Q.strict=()=>Q.clone({...Q._zod.def,catchall:cH()}),Q.strip=()=>Q.clone({...Q._zod.def,catchall:void 0}),Q.extend=(Y)=>{return h.extend(Q,Y)},Q.safeExtend=(Y)=>{return h.safeExtend(Q,Y)},Q.merge=(Y)=>h.merge(Q,Y),Q.pick=(Y)=>h.pick(Q,Y),Q.omit=(Y)=>h.omit(Q,Y),Q.partial=(...Y)=>h.partial(YG,Q,Y[0]),Q.required=(...Y)=>h.required(WG,Q,Y[0])});function w(Q,X){let Y={type:"object",shape:Q??{},...h.normalizeParams(X)};return new eW(Y)}function A0(Q,X){return new eW({type:"object",shape:Q,catchall:o(),...h.normalizeParams(X)})}var QG=q("ZodUnion",(Q,X)=>{TQ.init(Q,X),s.init(Q,X),Q.options=X.options});function p(Q,X){return new QG({type:"union",options:Q,...h.normalizeParams(X)})}var iH=q("ZodDiscriminatedUnion",(Q,X)=>{QG.init(Q,X),kY.init(Q,X)});function dQ(Q,X,Y){return new iH({type:"union",options:X,discriminator:Q,...h.normalizeParams(Y)})}var nH=q("ZodIntersection",(Q,X)=>{vY.init(Q,X),s.init(Q,X)});function z6(Q,X){return new nH({type:"intersection",left:Q,right:X})}var rH=q("ZodRecord",(Q,X)=>{xY.init(Q,X),s.init(Q,X),Q.keyType=X.keyType,Q.valueType=X.valueType});function t(Q,X,Y){return new rH({type:"record",keyType:Q,valueType:X,...h.normalizeParams(Y)})}var iQ=q("ZodEnum",(Q,X)=>{_Y.init(Q,X),s.init(Q,X),Q.enum=X.entries,Q.options=Object.values(X.entries);let Y=new Set(Object.keys(X.entries));Q.extract=(W,G)=>{let $={};for(let J of W)if(Y.has(J))$[J]=X.entries[J];else throw Error(`Key ${J} not found in enum`);return new iQ({...X,checks:[],...h.normalizeParams(G),entries:$})},Q.exclude=(W,G)=>{let $={...X.entries};for(let J of W)if(Y.has(J))delete $[J];else throw Error(`Key ${J} not found in enum`);return new iQ({...X,checks:[],...h.normalizeParams(G),entries:$})}});function L0(Q,X){let Y=Array.isArray(Q)?Object.fromEntries(Q.map((W)=>[W,W])):Q;return new iQ({type:"enum",entries:Y,...h.normalizeParams(X)})}var dH=q("ZodLiteral",(Q,X)=>{yY.init(Q,X),s.init(Q,X),Q.values=new Set(X.values),Object.defineProperty(Q,"value",{get(){if(X.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return X.values[0]}})});function b(Q,X){return new dH({type:"literal",values:Array.isArray(Q)?Q:[Q],...h.normalizeParams(X)})}var oH=q("ZodTransform",(Q,X)=>{gY.init(Q,X),s.init(Q,X),Q._zod.parse=(Y,W)=>{if(W.direction==="backward")throw new p1(Q.constructor.name);Y.addIssue=($)=>{if(typeof $==="string")Y.issues.push(h.issue($,Y.value,X));else{let J=$;if(J.fatal)J.continue=!1;J.code??(J.code="custom"),J.input??(J.input=Y.value),J.inst??(J.inst=Q),Y.issues.push(h.issue(J))}};let G=X.transform(Y.value,Y);if(G instanceof Promise)return G.then(($)=>{return Y.value=$,Y});return Y.value=G,Y}});function XG(Q){return new oH({type:"transform",transform:Q})}var YG=q("ZodOptional",(Q,X)=>{uY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType});function a(Q){return new YG({type:"optional",innerType:Q})}var tH=q("ZodNullable",(Q,X)=>{hY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType});function tW(Q){return new tH({type:"nullable",innerType:Q})}var aH=q("ZodDefault",(Q,X)=>{fY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType,Q.removeDefault=Q.unwrap});function sH(Q,X){return new aH({type:"default",innerType:Q,get defaultValue(){return typeof X==="function"?X():h.shallowClone(X)}})}var eH=q("ZodPrefault",(Q,X)=>{lY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType});function Q3(Q,X){return new eH({type:"prefault",innerType:Q,get defaultValue(){return typeof X==="function"?X():h.shallowClone(X)}})}var WG=q("ZodNonOptional",(Q,X)=>{mY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType});function X3(Q,X){return new WG({type:"nonoptional",innerType:Q,...h.normalizeParams(X)})}var Y3=q("ZodCatch",(Q,X)=>{cY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType,Q.removeCatch=Q.unwrap});function W3(Q,X){return new Y3({type:"catch",innerType:Q,catchValue:typeof X==="function"?X:()=>X})}var G3=q("ZodPipe",(Q,X)=>{pY.init(Q,X),s.init(Q,X),Q.in=X.in,Q.out=X.out});function nQ(Q,X){return new G3({type:"pipe",in:Q,out:X})}var $3=q("ZodReadonly",(Q,X)=>{iY.init(Q,X),s.init(Q,X),Q.unwrap=()=>Q._zod.def.innerType});function J3(Q){return new $3({type:"readonly",innerType:Q})}var GG=q("ZodCustom",(Q,X)=>{nY.init(Q,X),s.init(Q,X)});function $G(Q,X){return EW(GG,Q??(()=>!0),X)}function z3(Q,X={}){return TW(GG,Q,X)}function H3(Q){return SW(Q)}function oQ(Q,X){return nQ(XG(Q),X)}w0(SQ());var tQ="2025-11-25";var JG=[tQ,"2025-06-18","2025-03-26","2024-11-05","2024-10-07"],Y1="io.modelcontextprotocol/related-task",U6="2.0",G0=$G((Q)=>Q!==null&&(typeof Q==="object"||typeof Q==="function")),zG=p([D(),l().int()]),HG=D(),bZ=A0({ttl:p([l(),rQ()]).optional(),pollInterval:l().optional()}),U3=w({ttl:l().optional()}),A3=w({taskId:D()}),aQ=A0({progressToken:zG.optional(),[Y1]:A3.optional()}),Z0=w({_meta:aQ.optional()}),G4=Z0.extend({task:U3.optional()}),UG=(Q)=>G4.safeParse(Q).success,$0=w({method:D(),params:Z0.loose().optional()}),b0=w({_meta:aQ.optional()}),P0=w({method:D(),params:b0.loose().optional()}),J0=A0({_meta:aQ.optional()}),A6=p([D(),l().int()]),AG=w({jsonrpc:b(U6),id:A6,...$0.shape}).strict(),sQ=(Q)=>AG.safeParse(Q).success,KG=w({jsonrpc:b(U6),...P0.shape}).strict(),BG=(Q)=>KG.safeParse(Q).success,eQ=w({jsonrpc:b(U6),id:A6,result:J0}).strict(),$4=(Q)=>eQ.safeParse(Q).success;var y;(function(Q){Q[Q.ConnectionClosed=-32000]="ConnectionClosed",Q[Q.RequestTimeout=-32001]="RequestTimeout",Q[Q.ParseError=-32700]="ParseError",Q[Q.InvalidRequest=-32600]="InvalidRequest",Q[Q.MethodNotFound=-32601]="MethodNotFound",Q[Q.InvalidParams=-32602]="InvalidParams",Q[Q.InternalError=-32603]="InternalError",Q[Q.UrlElicitationRequired=-32042]="UrlElicitationRequired"})(y||(y={}));var Q9=w({jsonrpc:b(U6),id:A6.optional(),error:w({code:l().int(),message:D(),data:o().optional()})}).strict();var DG=(Q)=>Q9.safeParse(Q).success;var LG=p([AG,KG,eQ,Q9]),PZ=p([eQ,Q9]),K6=J0.strict(),K3=b0.extend({requestId:A6.optional(),reason:D().optional()}),B6=P0.extend({method:b("notifications/cancelled"),params:K3}),B3=w({src:D(),mimeType:D().optional(),sizes:_(D()).optional(),theme:L0(["light","dark"]).optional()}),J4=w({icons:_(B3).optional()}),E1=w({name:D(),title:D().optional()}),qG=E1.extend({...E1.shape,...J4.shape,version:D(),websiteUrl:D().optional(),description:D().optional()}),D3=z6(w({applyDefaults:Y0().optional()}),t(D(),o())),L3=oQ((Q)=>{if(Q&&typeof Q==="object"&&!Array.isArray(Q)){if(Object.keys(Q).length===0)return{form:{}}}return Q},z6(w({form:D3.optional(),url:G0.optional()}),t(D(),o()).optional())),q3=A0({list:G0.optional(),cancel:G0.optional(),requests:A0({sampling:A0({createMessage:G0.optional()}).optional(),elicitation:A0({create:G0.optional()}).optional()}).optional()}),F3=A0({list:G0.optional(),cancel:G0.optional(),requests:A0({tools:A0({call:G0.optional()}).optional()}).optional()}),O3=w({experimental:t(D(),G0).optional(),sampling:w({context:G0.optional(),tools:G0.optional()}).optional(),elicitation:L3.optional(),roots:w({listChanged:Y0().optional()}).optional(),tasks:q3.optional()}),M3=Z0.extend({protocolVersion:D(),capabilities:O3,clientInfo:qG}),X9=$0.extend({method:b("initialize"),params:M3});var V3=w({experimental:t(D(),G0).optional(),logging:G0.optional(),completions:G0.optional(),prompts:w({listChanged:Y0().optional()}).optional(),resources:w({subscribe:Y0().optional(),listChanged:Y0().optional()}).optional(),tools:w({listChanged:Y0().optional()}).optional(),tasks:F3.optional()}),Z3=J0.extend({protocolVersion:D(),capabilities:V3,serverInfo:qG,instructions:D().optional()}),Y9=P0.extend({method:b("notifications/initialized"),params:b0.optional()});var D6=$0.extend({method:b("ping"),params:Z0.optional()}),N3=w({progress:l(),total:a(l()),message:a(D())}),w3=w({...b0.shape,...N3.shape,progressToken:zG}),L6=P0.extend({method:b("notifications/progress"),params:w3}),b3=Z0.extend({cursor:HG.optional()}),z4=$0.extend({params:b3.optional()}),H4=J0.extend({nextCursor:HG.optional()}),P3=L0(["working","input_required","completed","failed","cancelled"]),U4=w({taskId:D(),status:P3,ttl:p([l(),rQ()]),createdAt:D(),lastUpdatedAt:D(),pollInterval:a(l()),statusMessage:a(D())}),T1=J0.extend({task:U4}),j3=b0.merge(U4),A4=P0.extend({method:b("notifications/tasks/status"),params:j3}),q6=$0.extend({method:b("tasks/get"),params:Z0.extend({taskId:D()})}),F6=J0.merge(U4),O6=$0.extend({method:b("tasks/result"),params:Z0.extend({taskId:D()})}),jZ=J0.loose(),M6=z4.extend({method:b("tasks/list")}),V6=H4.extend({tasks:_(U4)}),Z6=$0.extend({method:b("tasks/cancel"),params:Z0.extend({taskId:D()})}),FG=J0.merge(U4),OG=w({uri:D(),mimeType:a(D()),_meta:t(D(),o()).optional()}),MG=OG.extend({text:D()}),W9=D().refine((Q)=>{try{return atob(Q),!0}catch{return!1}},{message:"Invalid Base64 string"}),VG=OG.extend({blob:W9}),K4=L0(["user","assistant"]),S1=w({audience:_(K4).optional(),priority:l().min(0).max(1).optional(),lastModified:W4.datetime({offset:!0}).optional()}),ZG=w({...E1.shape,...J4.shape,uri:D(),description:a(D()),mimeType:a(D()),annotations:S1.optional(),_meta:a(A0({}))}),I3=w({...E1.shape,...J4.shape,uriTemplate:D(),description:a(D()),mimeType:a(D()),annotations:S1.optional(),_meta:a(A0({}))}),G9=z4.extend({method:b("resources/list")}),E3=H4.extend({resources:_(ZG)}),T3=z4.extend({method:b("resources/templates/list")}),S3=H4.extend({resourceTemplates:_(I3)}),$9=Z0.extend({uri:D()}),R3=$9,J9=$0.extend({method:b("resources/read"),params:R3}),C3=J0.extend({contents:_(p([MG,VG]))}),k3=P0.extend({method:b("notifications/resources/list_changed"),params:b0.optional()}),v3=$9,x3=$0.extend({method:b("resources/subscribe"),params:v3}),_3=$9,y3=$0.extend({method:b("resources/unsubscribe"),params:_3}),g3=b0.extend({uri:D()}),u3=P0.extend({method:b("notifications/resources/updated"),params:g3}),h3=w({name:D(),description:a(D()),required:a(Y0())}),f3=w({...E1.shape,...J4.shape,description:a(D()),arguments:a(_(h3)),_meta:a(A0({}))}),l3=z4.extend({method:b("prompts/list")}),m3=H4.extend({prompts:_(f3)}),c3=Z0.extend({name:D(),arguments:t(D(),D()).optional()}),p3=$0.extend({method:b("prompts/get"),params:c3}),z9=w({type:b("text"),text:D(),annotations:S1.optional(),_meta:t(D(),o()).optional()}),H9=w({type:b("image"),data:W9,mimeType:D(),annotations:S1.optional(),_meta:t(D(),o()).optional()}),U9=w({type:b("audio"),data:W9,mimeType:D(),annotations:S1.optional(),_meta:t(D(),o()).optional()}),i3=w({type:b("tool_use"),name:D(),id:D(),input:t(D(),o()),_meta:t(D(),o()).optional()}),n3=w({type:b("resource"),resource:p([MG,VG]),annotations:S1.optional(),_meta:t(D(),o()).optional()}),r3=ZG.extend({type:b("resource_link")}),A9=p([z9,H9,U9,r3,n3]),d3=w({role:K4,content:A9}),o3=J0.extend({description:D().optional(),messages:_(d3)}),t3=P0.extend({method:b("notifications/prompts/list_changed"),params:b0.optional()}),a3=w({title:D().optional(),readOnlyHint:Y0().optional(),destructiveHint:Y0().optional(),idempotentHint:Y0().optional(),openWorldHint:Y0().optional()}),s3=w({taskSupport:L0(["required","optional","forbidden"]).optional()}),NG=w({...E1.shape,...J4.shape,description:D().optional(),inputSchema:w({type:b("object"),properties:t(D(),G0).optional(),required:_(D()).optional()}).catchall(o()),outputSchema:w({type:b("object"),properties:t(D(),G0).optional(),required:_(D()).optional()}).catchall(o()).optional(),annotations:a3.optional(),execution:s3.optional(),_meta:t(D(),o()).optional()}),K9=z4.extend({method:b("tools/list")}),e3=H4.extend({tools:_(NG)}),N6=J0.extend({content:_(A9).default([]),structuredContent:t(D(),o()).optional(),isError:Y0().optional()}),IZ=N6.or(J0.extend({toolResult:o()})),QU=G4.extend({name:D(),arguments:t(D(),o()).optional()}),B4=$0.extend({method:b("tools/call"),params:QU}),XU=P0.extend({method:b("notifications/tools/list_changed"),params:b0.optional()}),EZ=w({autoRefresh:Y0().default(!0),debounceMs:l().int().nonnegative().default(300)}),D4=L0(["debug","info","notice","warning","error","critical","alert","emergency"]),YU=Z0.extend({level:D4}),B9=$0.extend({method:b("logging/setLevel"),params:YU}),WU=b0.extend({level:D4,logger:D().optional(),data:o()}),GU=P0.extend({method:b("notifications/message"),params:WU}),$U=w({name:D().optional()}),JU=w({hints:_($U).optional(),costPriority:l().min(0).max(1).optional(),speedPriority:l().min(0).max(1).optional(),intelligencePriority:l().min(0).max(1).optional()}),zU=w({mode:L0(["auto","required","none"]).optional()}),HU=w({type:b("tool_result"),toolUseId:D().describe("The unique identifier for the corresponding tool call."),content:_(A9).default([]),structuredContent:w({}).loose().optional(),isError:Y0().optional(),_meta:t(D(),o()).optional()}),UU=dQ("type",[z9,H9,U9]),H6=dQ("type",[z9,H9,U9,i3,HU]),AU=w({role:K4,content:p([H6,_(H6)]),_meta:t(D(),o()).optional()}),KU=G4.extend({messages:_(AU),modelPreferences:JU.optional(),systemPrompt:D().optional(),includeContext:L0(["none","thisServer","allServers"]).optional(),temperature:l().optional(),maxTokens:l().int(),stopSequences:_(D()).optional(),metadata:G0.optional(),tools:_(NG).optional(),toolChoice:zU.optional()}),BU=$0.extend({method:b("sampling/createMessage"),params:KU}),D9=J0.extend({model:D(),stopReason:a(L0(["endTurn","stopSequence","maxTokens"]).or(D())),role:K4,content:UU}),L9=J0.extend({model:D(),stopReason:a(L0(["endTurn","stopSequence","maxTokens","toolUse"]).or(D())),role:K4,content:p([H6,_(H6)])}),DU=w({type:b("boolean"),title:D().optional(),description:D().optional(),default:Y0().optional()}),LU=w({type:b("string"),title:D().optional(),description:D().optional(),minLength:l().optional(),maxLength:l().optional(),format:L0(["email","uri","date","date-time"]).optional(),default:D().optional()}),qU=w({type:L0(["number","integer"]),title:D().optional(),description:D().optional(),minimum:l().optional(),maximum:l().optional(),default:l().optional()}),FU=w({type:b("string"),title:D().optional(),description:D().optional(),enum:_(D()),default:D().optional()}),OU=w({type:b("string"),title:D().optional(),description:D().optional(),oneOf:_(w({const:D(),title:D()})),default:D().optional()}),MU=w({type:b("string"),title:D().optional(),description:D().optional(),enum:_(D()),enumNames:_(D()).optional(),default:D().optional()}),VU=p([FU,OU]),ZU=w({type:b("array"),title:D().optional(),description:D().optional(),minItems:l().optional(),maxItems:l().optional(),items:w({type:b("string"),enum:_(D())}),default:_(D()).optional()}),NU=w({type:b("array"),title:D().optional(),description:D().optional(),minItems:l().optional(),maxItems:l().optional(),items:w({anyOf:_(w({const:D(),title:D()}))}),default:_(D()).optional()}),wU=p([ZU,NU]),bU=p([MU,VU,wU]),PU=p([bU,DU,LU,qU]),jU=G4.extend({mode:b("form").optional(),message:D(),requestedSchema:w({type:b("object"),properties:t(D(),PU),required:_(D()).optional()})}),IU=G4.extend({mode:b("url"),message:D(),elicitationId:D(),url:D().url()}),EU=p([jU,IU]),TU=$0.extend({method:b("elicitation/create"),params:EU}),SU=b0.extend({elicitationId:D()}),RU=P0.extend({method:b("notifications/elicitation/complete"),params:SU}),w6=J0.extend({action:L0(["accept","decline","cancel"]),content:oQ((Q)=>Q===null?void 0:Q,t(D(),p([D(),l(),Y0(),_(D())])).optional())}),CU=w({type:b("ref/resource"),uri:D()});var kU=w({type:b("ref/prompt"),name:D()}),vU=Z0.extend({ref:p([kU,CU]),argument:w({name:D(),value:D()}),context:w({arguments:t(D(),D()).optional()}).optional()}),xU=$0.extend({method:b("completion/complete"),params:vU});var _U=J0.extend({completion:A0({values:_(D()).max(100),total:a(l().int()),hasMore:a(Y0())})}),yU=w({uri:D().startsWith("file://"),name:D().optional(),_meta:t(D(),o()).optional()}),gU=$0.extend({method:b("roots/list"),params:Z0.optional()}),q9=J0.extend({roots:_(yU)}),uU=P0.extend({method:b("notifications/roots/list_changed"),params:b0.optional()}),TZ=p([D6,X9,xU,B9,p3,l3,G9,T3,J9,x3,y3,B4,K9,q6,O6,M6,Z6]),SZ=p([B6,L6,Y9,uU,A4]),RZ=p([K6,D9,L9,w6,q9,F6,V6,T1]),CZ=p([D6,BU,TU,gU,q6,O6,M6,Z6]),kZ=p([B6,L6,GU,u3,k3,XU,t3,A4,RU]),vZ=p([K6,Z3,_U,o3,m3,E3,S3,C3,N6,e3,F6,V6,T1]);class k extends Error{constructor(Q,X,Y){super(`MCP error ${Q}: ${X}`);this.code=Q,this.data=Y,this.name="McpError"}static fromError(Q,X,Y){if(Q===y.UrlElicitationRequired&&Y){let W=Y;if(W.elicitations)return new wG(W.elicitations,X)}return new k(Q,X,Y)}}class wG extends k{constructor(Q,X=`URL elicitation${Q.length>1?"s":""} required`){super(y.UrlElicitationRequired,X,{elicitations:Q})}get elicitations(){return this.data?.elicitations??[]}}function W1(Q){return Q==="completed"||Q==="failed"||Q==="cancelled"}var hU=Symbol("Let zodToJsonSchema decide on which parser to use");var BN=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function F9(Q){let Y=$6(Q)?.method;if(!Y)throw Error("Schema is missing a method literal");let W=RW(Y);if(typeof W!=="string")throw Error("Schema method literal must be a string");return W}function O9(Q,X){let Y=X1(Q,X);if(!Y.success)throw Y.error;return Y.data}var iU=60000;class M9{constructor(Q){if(this._options=Q,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this._pendingDebouncedNotifications=new Set,this._taskProgressTokens=new Map,this._requestResolvers=new Map,this.setNotificationHandler(B6,(X)=>{this._oncancel(X)}),this.setNotificationHandler(L6,(X)=>{this._onprogress(X)}),this.setRequestHandler(D6,(X)=>({})),this._taskStore=Q?.taskStore,this._taskMessageQueue=Q?.taskMessageQueue,this._taskStore)this.setRequestHandler(q6,async(X,Y)=>{let W=await this._taskStore.getTask(X.params.taskId,Y.sessionId);if(!W)throw new k(y.InvalidParams,"Failed to retrieve task: Task not found");return{...W}}),this.setRequestHandler(O6,async(X,Y)=>{let W=async()=>{let G=X.params.taskId;if(this._taskMessageQueue){let J;while(J=await this._taskMessageQueue.dequeue(G,Y.sessionId)){if(J.type==="response"||J.type==="error"){let z=J.message,H=z.id,U=this._requestResolvers.get(H);if(U)if(this._requestResolvers.delete(H),J.type==="response")U(z);else{let A=z,K=new k(A.error.code,A.error.message,A.error.data);U(K)}else{let A=J.type==="response"?"Response":"Error";this._onerror(Error(`${A} handler missing for request ${H}`))}continue}await this._transport?.send(J.message,{relatedRequestId:Y.requestId})}}let $=await this._taskStore.getTask(G,Y.sessionId);if(!$)throw new k(y.InvalidParams,`Task not found: ${G}`);if(!W1($.status))return await this._waitForTaskUpdate(G,Y.signal),await W();if(W1($.status)){let J=await this._taskStore.getTaskResult(G,Y.sessionId);return this._clearTaskQueue(G),{...J,_meta:{...J._meta,[Y1]:{taskId:G}}}}return await W()};return await W()}),this.setRequestHandler(M6,async(X,Y)=>{try{let{tasks:W,nextCursor:G}=await this._taskStore.listTasks(X.params?.cursor,Y.sessionId);return{tasks:W,nextCursor:G,_meta:{}}}catch(W){throw new k(y.InvalidParams,`Failed to list tasks: ${W instanceof Error?W.message:String(W)}`)}}),this.setRequestHandler(Z6,async(X,Y)=>{try{let W=await this._taskStore.getTask(X.params.taskId,Y.sessionId);if(!W)throw new k(y.InvalidParams,`Task not found: ${X.params.taskId}`);if(W1(W.status))throw new k(y.InvalidParams,`Cannot cancel task in terminal status: ${W.status}`);await this._taskStore.updateTaskStatus(X.params.taskId,"cancelled","Client cancelled task execution.",Y.sessionId),this._clearTaskQueue(X.params.taskId);let G=await this._taskStore.getTask(X.params.taskId,Y.sessionId);if(!G)throw new k(y.InvalidParams,`Task not found after cancellation: ${X.params.taskId}`);return{_meta:{},...G}}catch(W){if(W instanceof k)throw W;throw new k(y.InvalidRequest,`Failed to cancel task: ${W instanceof Error?W.message:String(W)}`)}})}async _oncancel(Q){if(!Q.params.requestId)return;this._requestHandlerAbortControllers.get(Q.params.requestId)?.abort(Q.params.reason)}_setupTimeout(Q,X,Y,W,G=!1){this._timeoutInfo.set(Q,{timeoutId:setTimeout(W,X),startTime:Date.now(),timeout:X,maxTotalTimeout:Y,resetTimeoutOnProgress:G,onTimeout:W})}_resetTimeout(Q){let X=this._timeoutInfo.get(Q);if(!X)return!1;let Y=Date.now()-X.startTime;if(X.maxTotalTimeout&&Y>=X.maxTotalTimeout)throw this._timeoutInfo.delete(Q),k.fromError(y.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:X.maxTotalTimeout,totalElapsed:Y});return clearTimeout(X.timeoutId),X.timeoutId=setTimeout(X.onTimeout,X.timeout),!0}_cleanupTimeout(Q){let X=this._timeoutInfo.get(Q);if(X)clearTimeout(X.timeoutId),this._timeoutInfo.delete(Q)}async connect(Q){this._transport=Q;let X=this.transport?.onclose;this._transport.onclose=()=>{X?.(),this._onclose()};let Y=this.transport?.onerror;this._transport.onerror=(G)=>{Y?.(G),this._onerror(G)};let W=this._transport?.onmessage;this._transport.onmessage=(G,$)=>{if(W?.(G,$),$4(G)||DG(G))this._onresponse(G);else if(sQ(G))this._onrequest(G,$);else if(BG(G))this._onnotification(G);else this._onerror(Error(`Unknown message type: ${JSON.stringify(G)}`))},await this._transport.start()}_onclose(){let Q=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._taskProgressTokens.clear(),this._pendingDebouncedNotifications.clear();let X=k.fromError(y.ConnectionClosed,"Connection closed");this._transport=void 0,this.onclose?.();for(let Y of Q.values())Y(X)}_onerror(Q){this.onerror?.(Q)}_onnotification(Q){let X=this._notificationHandlers.get(Q.method)??this.fallbackNotificationHandler;if(X===void 0)return;Promise.resolve().then(()=>X(Q)).catch((Y)=>this._onerror(Error(`Uncaught error in notification handler: ${Y}`)))}_onrequest(Q,X){let Y=this._requestHandlers.get(Q.method)??this.fallbackRequestHandler,W=this._transport,G=Q.params?._meta?.[Y1]?.taskId;if(Y===void 0){let U={jsonrpc:"2.0",id:Q.id,error:{code:y.MethodNotFound,message:"Method not found"}};if(G&&this._taskMessageQueue)this._enqueueTaskMessage(G,{type:"error",message:U,timestamp:Date.now()},W?.sessionId).catch((A)=>this._onerror(Error(`Failed to enqueue error response: ${A}`)));else W?.send(U).catch((A)=>this._onerror(Error(`Failed to send an error response: ${A}`)));return}let $=new AbortController;this._requestHandlerAbortControllers.set(Q.id,$);let J=UG(Q.params)?Q.params.task:void 0,z=this._taskStore?this.requestTaskStore(Q,W?.sessionId):void 0,H={signal:$.signal,sessionId:W?.sessionId,_meta:Q.params?._meta,sendNotification:async(U)=>{let A={relatedRequestId:Q.id};if(G)A.relatedTask={taskId:G};await this.notification(U,A)},sendRequest:async(U,A,K)=>{let B={...K,relatedRequestId:Q.id};if(G&&!B.relatedTask)B.relatedTask={taskId:G};let L=B.relatedTask?.taskId??G;if(L&&z)await z.updateTaskStatus(L,"input_required");return await this.request(U,A,B)},authInfo:X?.authInfo,requestId:Q.id,requestInfo:X?.requestInfo,taskId:G,taskStore:z,taskRequestedTtl:J?.ttl,closeSSEStream:X?.closeSSEStream,closeStandaloneSSEStream:X?.closeStandaloneSSEStream};Promise.resolve().then(()=>{if(J)this.assertTaskHandlerCapability(Q.method)}).then(()=>Y(Q,H)).then(async(U)=>{if($.signal.aborted)return;let A={result:U,jsonrpc:"2.0",id:Q.id};if(G&&this._taskMessageQueue)await this._enqueueTaskMessage(G,{type:"response",message:A,timestamp:Date.now()},W?.sessionId);else await W?.send(A)},async(U)=>{if($.signal.aborted)return;let A={jsonrpc:"2.0",id:Q.id,error:{code:Number.isSafeInteger(U.code)?U.code:y.InternalError,message:U.message??"Internal error",...U.data!==void 0&&{data:U.data}}};if(G&&this._taskMessageQueue)await this._enqueueTaskMessage(G,{type:"error",message:A,timestamp:Date.now()},W?.sessionId);else await W?.send(A)}).catch((U)=>this._onerror(Error(`Failed to send response: ${U}`))).finally(()=>{this._requestHandlerAbortControllers.delete(Q.id)})}_onprogress(Q){let{progressToken:X,...Y}=Q.params,W=Number(X),G=this._progressHandlers.get(W);if(!G){this._onerror(Error(`Received a progress notification for an unknown token: ${JSON.stringify(Q)}`));return}let $=this._responseHandlers.get(W),J=this._timeoutInfo.get(W);if(J&&$&&J.resetTimeoutOnProgress)try{this._resetTimeout(W)}catch(z){this._responseHandlers.delete(W),this._progressHandlers.delete(W),this._cleanupTimeout(W),$(z);return}G(Y)}_onresponse(Q){let X=Number(Q.id),Y=this._requestResolvers.get(X);if(Y){if(this._requestResolvers.delete(X),$4(Q))Y(Q);else{let $=new k(Q.error.code,Q.error.message,Q.error.data);Y($)}return}let W=this._responseHandlers.get(X);if(W===void 0){this._onerror(Error(`Received a response for an unknown message ID: ${JSON.stringify(Q)}`));return}this._responseHandlers.delete(X),this._cleanupTimeout(X);let G=!1;if($4(Q)&&Q.result&&typeof Q.result==="object"){let $=Q.result;if($.task&&typeof $.task==="object"){let J=$.task;if(typeof J.taskId==="string")G=!0,this._taskProgressTokens.set(J.taskId,X)}}if(!G)this._progressHandlers.delete(X);if($4(Q))W(Q);else{let $=k.fromError(Q.error.code,Q.error.message,Q.error.data);W($)}}get transport(){return this._transport}async close(){await this._transport?.close()}async*requestStream(Q,X,Y){let{task:W}=Y??{};if(!W){try{yield{type:"result",result:await this.request(Q,X,Y)}}catch($){yield{type:"error",error:$ instanceof k?$:new k(y.InternalError,String($))}}return}let G;try{let $=await this.request(Q,T1,Y);if($.task)G=$.task.taskId,yield{type:"taskCreated",task:$.task};else throw new k(y.InternalError,"Task creation did not return a task");while(!0){let J=await this.getTask({taskId:G},Y);if(yield{type:"taskStatus",task:J},W1(J.status)){if(J.status==="completed")yield{type:"result",result:await this.getTaskResult({taskId:G},X,Y)};else if(J.status==="failed")yield{type:"error",error:new k(y.InternalError,`Task ${G} failed`)};else if(J.status==="cancelled")yield{type:"error",error:new k(y.InternalError,`Task ${G} was cancelled`)};return}if(J.status==="input_required"){yield{type:"result",result:await this.getTaskResult({taskId:G},X,Y)};return}let z=J.pollInterval??this._options?.defaultTaskPollInterval??1000;await new Promise((H)=>setTimeout(H,z)),Y?.signal?.throwIfAborted()}}catch($){yield{type:"error",error:$ instanceof k?$:new k(y.InternalError,String($))}}}request(Q,X,Y){let{relatedRequestId:W,resumptionToken:G,onresumptiontoken:$,task:J,relatedTask:z}=Y??{};return new Promise((H,U)=>{let A=(M)=>{U(M)};if(!this._transport){A(Error("Not connected"));return}if(this._options?.enforceStrictCapabilities===!0)try{if(this.assertCapabilityForMethod(Q.method),J)this.assertTaskCapability(Q.method)}catch(M){A(M);return}Y?.signal?.throwIfAborted();let K=this._requestMessageId++,B={...Q,jsonrpc:"2.0",id:K};if(Y?.onprogress)this._progressHandlers.set(K,Y.onprogress),B.params={...Q.params,_meta:{...Q.params?._meta||{},progressToken:K}};if(J)B.params={...B.params,task:J};if(z)B.params={...B.params,_meta:{...B.params?._meta||{},[Y1]:z}};let L=(M)=>{this._responseHandlers.delete(K),this._progressHandlers.delete(K),this._cleanupTimeout(K),this._transport?.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:K,reason:String(M)}},{relatedRequestId:W,resumptionToken:G,onresumptiontoken:$}).catch((E)=>this._onerror(Error(`Failed to send cancellation: ${E}`)));let S=M instanceof k?M:new k(y.RequestTimeout,String(M));U(S)};this._responseHandlers.set(K,(M)=>{if(Y?.signal?.aborted)return;if(M instanceof Error)return U(M);try{let S=X1(X,M.result);if(!S.success)U(S.error);else H(S.data)}catch(S){U(S)}}),Y?.signal?.addEventListener("abort",()=>{L(Y?.signal?.reason)});let F=Y?.timeout??iU,O=()=>L(k.fromError(y.RequestTimeout,"Request timed out",{timeout:F}));this._setupTimeout(K,F,Y?.maxTotalTimeout,O,Y?.resetTimeoutOnProgress??!1);let V=z?.taskId;if(V){let M=(S)=>{let E=this._responseHandlers.get(K);if(E)E(S);else this._onerror(Error(`Response handler missing for side-channeled request ${K}`))};this._requestResolvers.set(K,M),this._enqueueTaskMessage(V,{type:"request",message:B,timestamp:Date.now()}).catch((S)=>{this._cleanupTimeout(K),U(S)})}else this._transport.send(B,{relatedRequestId:W,resumptionToken:G,onresumptiontoken:$}).catch((M)=>{this._cleanupTimeout(K),U(M)})})}async getTask(Q,X){return this.request({method:"tasks/get",params:Q},F6,X)}async getTaskResult(Q,X,Y){return this.request({method:"tasks/result",params:Q},X,Y)}async listTasks(Q,X){return this.request({method:"tasks/list",params:Q},V6,X)}async cancelTask(Q,X){return this.request({method:"tasks/cancel",params:Q},FG,X)}async notification(Q,X){if(!this._transport)throw Error("Not connected");this.assertNotificationCapability(Q.method);let Y=X?.relatedTask?.taskId;if(Y){let J={...Q,jsonrpc:"2.0",params:{...Q.params,_meta:{...Q.params?._meta||{},[Y1]:X.relatedTask}}};await this._enqueueTaskMessage(Y,{type:"notification",message:J,timestamp:Date.now()});return}if((this._options?.debouncedNotificationMethods??[]).includes(Q.method)&&!Q.params&&!X?.relatedRequestId&&!X?.relatedTask){if(this._pendingDebouncedNotifications.has(Q.method))return;this._pendingDebouncedNotifications.add(Q.method),Promise.resolve().then(()=>{if(this._pendingDebouncedNotifications.delete(Q.method),!this._transport)return;let J={...Q,jsonrpc:"2.0"};if(X?.relatedTask)J={...J,params:{...J.params,_meta:{...J.params?._meta||{},[Y1]:X.relatedTask}}};this._transport?.send(J,X).catch((z)=>this._onerror(z))});return}let $={...Q,jsonrpc:"2.0"};if(X?.relatedTask)$={...$,params:{...$.params,_meta:{...$.params?._meta||{},[Y1]:X.relatedTask}}};await this._transport.send($,X)}setRequestHandler(Q,X){let Y=F9(Q);this.assertRequestHandlerCapability(Y),this._requestHandlers.set(Y,(W,G)=>{let $=O9(Q,W);return Promise.resolve(X($,G))})}removeRequestHandler(Q){this._requestHandlers.delete(Q)}assertCanSetRequestHandler(Q){if(this._requestHandlers.has(Q))throw Error(`A request handler for ${Q} already exists, which would be overridden`)}setNotificationHandler(Q,X){let Y=F9(Q);this._notificationHandlers.set(Y,(W)=>{let G=O9(Q,W);return Promise.resolve(X(G))})}removeNotificationHandler(Q){this._notificationHandlers.delete(Q)}_cleanupTaskProgressHandler(Q){let X=this._taskProgressTokens.get(Q);if(X!==void 0)this._progressHandlers.delete(X),this._taskProgressTokens.delete(Q)}async _enqueueTaskMessage(Q,X,Y){if(!this._taskStore||!this._taskMessageQueue)throw Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");let W=this._options?.maxTaskQueueSize;await this._taskMessageQueue.enqueue(Q,X,Y,W)}async _clearTaskQueue(Q,X){if(this._taskMessageQueue){let Y=await this._taskMessageQueue.dequeueAll(Q,X);for(let W of Y)if(W.type==="request"&&sQ(W.message)){let G=W.message.id,$=this._requestResolvers.get(G);if($)$(new k(y.InternalError,"Task cancelled or completed")),this._requestResolvers.delete(G);else this._onerror(Error(`Resolver missing for request ${G} during task ${Q} cleanup`))}}}async _waitForTaskUpdate(Q,X){let Y=this._options?.defaultTaskPollInterval??1000;try{let W=await this._taskStore?.getTask(Q);if(W?.pollInterval)Y=W.pollInterval}catch{}return new Promise((W,G)=>{if(X.aborted){G(new k(y.InvalidRequest,"Request cancelled"));return}let $=setTimeout(W,Y);X.addEventListener("abort",()=>{clearTimeout($),G(new k(y.InvalidRequest,"Request cancelled"))},{once:!0})})}requestTaskStore(Q,X){let Y=this._taskStore;if(!Y)throw Error("No task store configured");return{createTask:async(W)=>{if(!Q)throw Error("No request provided");return await Y.createTask(W,Q.id,{method:Q.method,params:Q.params},X)},getTask:async(W)=>{let G=await Y.getTask(W,X);if(!G)throw new k(y.InvalidParams,"Failed to retrieve task: Task not found");return G},storeTaskResult:async(W,G,$)=>{await Y.storeTaskResult(W,G,$,X);let J=await Y.getTask(W,X);if(J){let z=A4.parse({method:"notifications/tasks/status",params:J});if(await this.notification(z),W1(J.status))this._cleanupTaskProgressHandler(W)}},getTaskResult:(W)=>{return Y.getTaskResult(W,X)},updateTaskStatus:async(W,G,$)=>{let J=await Y.getTask(W,X);if(!J)throw new k(y.InvalidParams,`Task "${W}" not found - it may have been cleaned up`);if(W1(J.status))throw new k(y.InvalidParams,`Cannot update task "${W}" from terminal status "${J.status}" to "${G}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);await Y.updateTaskStatus(W,G,$,X);let z=await Y.getTask(W,X);if(z){let H=A4.parse({method:"notifications/tasks/status",params:z});if(await this.notification(H),W1(z.status))this._cleanupTaskProgressHandler(W)}},listTasks:(W)=>{return Y.listTasks(W,X)}}}}function bG(Q){return Q!==null&&typeof Q==="object"&&!Array.isArray(Q)}function PG(Q,X){let Y={...Q};for(let W in X){let G=W,$=X[G];if($===void 0)continue;let J=Y[G];if(bG(J)&&bG($))Y[G]={...J,...$};else Y[G]=$}return Y}var X5=xX(BX(),1),Y5=xX(Q5(),1);function QM(){let Q=new X5.default({strict:!1,validateFormats:!0,validateSchema:!1,allErrors:!0});return Y5.default(Q),Q}class wX{constructor(Q){this._ajv=Q??QM()}getValidator(Q){let X="$id"in Q&&typeof Q.$id==="string"?this._ajv.getSchema(Q.$id)??this._ajv.compile(Q):this._ajv.compile(Q);return(Y)=>{if(X(Y))return{valid:!0,data:Y,errorMessage:void 0};else return{valid:!1,data:void 0,errorMessage:this._ajv.errorsText(X.errors)}}}}class bX{constructor(Q){this._server=Q}requestStream(Q,X,Y){return this._server.requestStream(Q,X,Y)}async getTask(Q,X){return this._server.getTask({taskId:Q},X)}async getTaskResult(Q,X,Y){return this._server.getTaskResult({taskId:Q},X,Y)}async listTasks(Q,X){return this._server.listTasks(Q?{cursor:Q}:void 0,X)}async cancelTask(Q,X){return this._server.cancelTask({taskId:Q},X)}}function W5(Q,X,Y){if(!Q)throw Error(`${Y} does not support task creation (required for ${X})`);switch(X){case"tools/call":if(!Q.tools?.call)throw Error(`${Y} does not support task creation for tools/call (required for ${X})`);break;default:break}}function G5(Q,X,Y){if(!Q)throw Error(`${Y} does not support task creation (required for ${X})`);switch(X){case"sampling/createMessage":if(!Q.sampling?.createMessage)throw Error(`${Y} does not support task creation for sampling/createMessage (required for ${X})`);break;case"elicitation/create":if(!Q.elicitation?.create)throw Error(`${Y} does not support task creation for elicitation/create (required for ${X})`);break;default:break}}class PX extends M9{constructor(Q,X){super(X);if(this._serverInfo=Q,this._loggingLevels=new Map,this.LOG_LEVEL_SEVERITY=new Map(D4.options.map((Y,W)=>[Y,W])),this.isMessageIgnored=(Y,W)=>{let G=this._loggingLevels.get(W);return G?this.LOG_LEVEL_SEVERITY.get(Y)<this.LOG_LEVEL_SEVERITY.get(G):!1},this._capabilities=X?.capabilities??{},this._instructions=X?.instructions,this._jsonSchemaValidator=X?.jsonSchemaValidator??new wX,this.setRequestHandler(X9,(Y)=>this._oninitialize(Y)),this.setNotificationHandler(Y9,()=>this.oninitialized?.()),this._capabilities.logging)this.setRequestHandler(B9,async(Y,W)=>{let G=W.sessionId||W.requestInfo?.headers["mcp-session-id"]||void 0,{level:$}=Y.params,J=D4.safeParse($);if(J.success)this._loggingLevels.set(G,J.data);return{}})}get experimental(){if(!this._experimental)this._experimental={tasks:new bX(this)};return this._experimental}registerCapabilities(Q){if(this.transport)throw Error("Cannot register capabilities after connecting to transport");this._capabilities=PG(this._capabilities,Q)}setRequestHandler(Q,X){let W=$6(Q)?.method;if(!W)throw Error("Schema is missing a method literal");let G;if(I1(W)){let J=W;G=J._zod?.def?.value??J.value}else{let J=W;G=J._def?.value??J.value}if(typeof G!=="string")throw Error("Schema method literal must be a string");if(G==="tools/call"){let J=async(z,H)=>{let U=X1(B4,z);if(!U.success){let L=U.error instanceof Error?U.error.message:String(U.error);throw new k(y.InvalidParams,`Invalid tools/call request: ${L}`)}let{params:A}=U.data,K=await Promise.resolve(X(z,H));if(A.task){let L=X1(T1,K);if(!L.success){let F=L.error instanceof Error?L.error.message:String(L.error);throw new k(y.InvalidParams,`Invalid task creation result: ${F}`)}return L.data}let B=X1(N6,K);if(!B.success){let L=B.error instanceof Error?B.error.message:String(B.error);throw new k(y.InvalidParams,`Invalid tools/call result: ${L}`)}return B.data};return super.setRequestHandler(Q,J)}return super.setRequestHandler(Q,X)}assertCapabilityForMethod(Q){switch(Q){case"sampling/createMessage":if(!this._clientCapabilities?.sampling)throw Error(`Client does not support sampling (required for ${Q})`);break;case"elicitation/create":if(!this._clientCapabilities?.elicitation)throw Error(`Client does not support elicitation (required for ${Q})`);break;case"roots/list":if(!this._clientCapabilities?.roots)throw Error(`Client does not support listing roots (required for ${Q})`);break;case"ping":break}}assertNotificationCapability(Q){switch(Q){case"notifications/message":if(!this._capabilities.logging)throw Error(`Server does not support logging (required for ${Q})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw Error(`Server does not support notifying about resources (required for ${Q})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw Error(`Server does not support notifying of tool list changes (required for ${Q})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw Error(`Server does not support notifying of prompt list changes (required for ${Q})`);break;case"notifications/elicitation/complete":if(!this._clientCapabilities?.elicitation?.url)throw Error(`Client does not support URL elicitation (required for ${Q})`);break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(Q){if(!this._capabilities)return;switch(Q){case"completion/complete":if(!this._capabilities.completions)throw Error(`Server does not support completions (required for ${Q})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw Error(`Server does not support logging (required for ${Q})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw Error(`Server does not support prompts (required for ${Q})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw Error(`Server does not support resources (required for ${Q})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Server does not support tools (required for ${Q})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw Error(`Server does not support tasks capability (required for ${Q})`);break;case"ping":case"initialize":break}}assertTaskCapability(Q){G5(this._clientCapabilities?.tasks?.requests,Q,"Client")}assertTaskHandlerCapability(Q){if(!this._capabilities)return;W5(this._capabilities.tasks?.requests,Q,"Server")}async _oninitialize(Q){let X=Q.params.protocolVersion;return this._clientCapabilities=Q.params.capabilities,this._clientVersion=Q.params.clientInfo,{protocolVersion:JG.includes(X)?X:tQ,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},K6)}async createMessage(Q,X){if(Q.tools||Q.toolChoice){if(!this._clientCapabilities?.sampling?.tools)throw Error("Client does not support sampling tools capability.")}if(Q.messages.length>0){let Y=Q.messages[Q.messages.length-1],W=Array.isArray(Y.content)?Y.content:[Y.content],G=W.some((H)=>H.type==="tool_result"),$=Q.messages.length>1?Q.messages[Q.messages.length-2]:void 0,J=$?Array.isArray($.content)?$.content:[$.content]:[],z=J.some((H)=>H.type==="tool_use");if(G){if(W.some((H)=>H.type!=="tool_result"))throw Error("The last message must contain only tool_result content if any is present");if(!z)throw Error("tool_result blocks are not matching any tool_use from the previous message")}if(z){let H=new Set(J.filter((A)=>A.type==="tool_use").map((A)=>A.id)),U=new Set(W.filter((A)=>A.type==="tool_result").map((A)=>A.toolUseId));if(H.size!==U.size||![...H].every((A)=>U.has(A)))throw Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}if(Q.tools)return this.request({method:"sampling/createMessage",params:Q},L9,X);return this.request({method:"sampling/createMessage",params:Q},D9,X)}async elicitInput(Q,X){switch(Q.mode??"form"){case"url":{if(!this._clientCapabilities?.elicitation?.url)throw Error("Client does not support url elicitation.");let W=Q;return this.request({method:"elicitation/create",params:W},w6,X)}case"form":{if(!this._clientCapabilities?.elicitation?.form)throw Error("Client does not support form elicitation.");let W=Q.mode==="form"?Q:{...Q,mode:"form"},G=await this.request({method:"elicitation/create",params:W},w6,X);if(G.action==="accept"&&G.content&&W.requestedSchema)try{let J=this._jsonSchemaValidator.getValidator(W.requestedSchema)(G.content);if(!J.valid)throw new k(y.InvalidParams,`Elicitation response content does not match requested schema: ${J.errorMessage}`)}catch($){if($ instanceof k)throw $;throw new k(y.InternalError,`Error validating elicitation response: ${$ instanceof Error?$.message:String($)}`)}return G}}}createElicitationCompletionNotifier(Q,X){if(!this._clientCapabilities?.elicitation?.url)throw Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");return()=>this.notification({method:"notifications/elicitation/complete",params:{elicitationId:Q}},X)}async listRoots(Q,X){return this.request({method:"roots/list",params:Q},q9,X)}async sendLoggingMessage(Q,X){if(this._capabilities.logging){if(!this.isMessageIgnored(Q.level,X))return this.notification({method:"notifications/message",params:Q})}}async sendResourceUpdated(Q){return this.notification({method:"notifications/resources/updated",params:Q})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}import J5 from"node:process";class jX{append(Q){this._buffer=this._buffer?Buffer.concat([this._buffer,Q]):Q}readMessage(){if(!this._buffer)return null;let Q=this._buffer.indexOf(`
29
29
  `);if(Q===-1)return null;let X=this._buffer.toString("utf8",0,Q).replace(/\r$/,"");return this._buffer=this._buffer.subarray(Q+1),XM(X)}clear(){this._buffer=void 0}}function XM(Q){return LG.parse(JSON.parse(Q))}function $5(Q){return JSON.stringify(Q)+`
30
- `}class IX{constructor(Q=J5.stdin,X=J5.stdout){this._stdin=Q,this._stdout=X,this._readBuffer=new jX,this._started=!1,this._ondata=(Y)=>{this._readBuffer.append(Y),this.processReadBuffer()},this._onerror=(Y)=>{this.onerror?.(Y)}}async start(){if(this._started)throw Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){while(!0)try{let Q=this._readBuffer.readMessage();if(Q===null)break;this.onmessage?.(Q)}catch(Q){this.onerror?.(Q)}}async close(){if(this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0)this._stdin.pause();this._readBuffer.clear(),this.onclose?.()}send(Q){return new Promise((X)=>{let Y=$5(Q);if(this._stdout.write(Y))X();else this._stdout.once("drain",X)})}}var z5={name:"@sequenzy/mcp",version:"0.0.41",mcpName:"io.github.sequenzy/mcp",description:"Sequenzy MCP server for AI-powered email marketing automation",type:"module",bin:{"sequenzy-mcp":"dist/index.js"},main:"./dist/index.js",exports:{".":"./dist/index.js","./server.json":"./server.json"},scripts:{dev:"bun --watch src/index.ts",build:"bun build src/index.ts --outdir dist --target node --minify",start:"node dist/index.js","type-check":"tsc --noEmit",test:"bun test","test:watch":"bun test --watch",prepublishOnly:"bun run build"},dependencies:{"@modelcontextprotocol/sdk":"^1.0.0"},devDependencies:{"@types/bun":"latest","@types/node":"^22.0.0","bun-types":"latest",typescript:"^5.8.0"},files:["dist","server.json"],keywords:["sequenzy","email","mcp","ai","claude","automation"],license:"MIT",publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/Sequenzy/mcp.git"},homepage:"https://sequenzy.com",bugs:{url:"https://github.com/Sequenzy/mcp/issues"}};class l1 extends Error{statusCode;rawDetails;code;context;constructor(Q,X,Y,W,G){super(Q);this.statusCode=X;this.rawDetails=Y;this.code=W;this.context=G;this.name="McpApiError"}}function WM(Q){if(Q instanceof l1)return{message:Q.message,statusCode:Q.statusCode,code:Q.code,rawDetails:Q.rawDetails,context:Q.context};if(Q instanceof Error)return{message:Q.message};return{message:String(Q)}}function GM(Q){let X=WM(Q),Y=X.message.trim()||"Unknown error",W=Y.toLowerCase(),G=X.rawDetails?.trim()||Y;if(X.context?.title||X.context?.description||X.context?.howToFix||X.context?.docsUrl)return{title:X.context.title??(X.statusCode===409?"Request conflict":"API request failed"),description:X.context.description??Y,howToFix:X.context.howToFix??"Review the details below, adjust the tool input, and retry.",docsUrl:X.context.docsUrl??"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.code==="MCP_AUTH_REQUIRED"||W.includes("sequenzy_api_key environment variable is required"))return{title:"Missing MCP API key",description:"The MCP server started without a Sequenzy API key, so it cannot authenticate any tool or resource request.",howToFix:"Add `SEQUENZY_API_KEY` to the MCP server environment, or run `npx @sequenzy/setup` to configure the integration automatically.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===401||X.code==="UNAUTHORIZED")return{title:"Authentication failed",description:"The MCP server reached Sequenzy, but the current API key was rejected.",howToFix:"Replace `SEQUENZY_API_KEY` with a valid personal API key, then restart the MCP client so it reconnects with fresh credentials.",docsUrl:"https://docs.sequenzy.com/authentication",details:G};if(X.statusCode===403||W.includes("access denied"))return{title:"Access denied",description:"The current API key is valid, but it does not have permission to access the requested company or action.",howToFix:"Use an API key that belongs to the right account, or select a company the key can access before retrying the tool call.",docsUrl:"https://docs.sequenzy.com/authentication",details:G};if(W.includes("no company available")||W.includes("company not found"))return{title:"Company selection required",description:"The MCP server could not resolve a company for this request.",howToFix:"Call `get_account` to inspect available companies, then call `select_company`, or pass `companyId` explicitly in the next tool call.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===404||W.includes("not found"))return{title:"Requested resource not found",description:"Sequenzy could not find the requested campaign, template, sequence, company, or subscriber.",howToFix:"List or fetch the resource collection first, then retry the tool with a confirmed ID or email value.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===409||W.includes("already exists"))return{title:"Resource already exists",description:"Sequenzy rejected this MCP request because it would create a duplicate resource.",howToFix:"List the existing resources first, reuse the matching resource when appropriate, or retry with a unique name or domain.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===429||W.includes("rate limit"))return{title:"Rate limited",description:"Sequenzy temporarily slowed this MCP request because too many requests were sent too quickly.",howToFix:"Wait briefly before retrying. If the client is looping, reduce retries or add backoff before the next tool call.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.code==="NETWORK_ERROR"||W.includes("fetch failed"))return{title:"Network or configuration error",description:"The MCP server could not reach the Sequenzy API from this environment.",howToFix:"Check connectivity and verify `SEQUENZY_API_URL` if you override it in the MCP environment.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(W.includes("unknown tool")||W.includes("unknown resource"))return{title:"Unsupported MCP request",description:"The client asked for a tool or resource name that this Sequenzy MCP server does not expose.",howToFix:"Refresh the client's tool list and call only the names returned by `list_tools` or `list_resources`.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(W.includes("is required")||W.includes("invalid"))return{title:"Invalid MCP input",description:"The tool call was missing a required field or included an invalid value.",howToFix:"Review the tool schema, supply the missing argument, and retry the request with corrected input.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode&&X.statusCode>=500)return{title:"Sequenzy server error",description:"The request reached Sequenzy, but the server could not complete it successfully.",howToFix:"Retry once. If it still fails, keep the details below and consult the docs before escalating.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};return{title:"Tool execution failed",description:"The MCP server could not complete the requested operation.",howToFix:"Review the details below, adjust the tool input or credentials, and retry.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G}}function Z1(Q){let X=GM(Q);return[`Sequenzy MCP error: ${X.title}`,`Description: ${X.description}`,`How to fix: ${X.howToFix}`,`Docs: ${X.docsUrl}`,`Details: ${X.details}`].join(`
30
+ `}class IX{constructor(Q=J5.stdin,X=J5.stdout){this._stdin=Q,this._stdout=X,this._readBuffer=new jX,this._started=!1,this._ondata=(Y)=>{this._readBuffer.append(Y),this.processReadBuffer()},this._onerror=(Y)=>{this.onerror?.(Y)}}async start(){if(this._started)throw Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){while(!0)try{let Q=this._readBuffer.readMessage();if(Q===null)break;this.onmessage?.(Q)}catch(Q){this.onerror?.(Q)}}async close(){if(this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0)this._stdin.pause();this._readBuffer.clear(),this.onclose?.()}send(Q){return new Promise((X)=>{let Y=$5(Q);if(this._stdout.write(Y))X();else this._stdout.once("drain",X)})}}var z5={name:"@sequenzy/mcp",version:"0.0.42",mcpName:"io.github.sequenzy/mcp",description:"Sequenzy MCP server for AI-powered email marketing automation",type:"module",bin:{"sequenzy-mcp":"dist/index.js"},main:"./dist/index.js",exports:{".":"./dist/index.js","./server.json":"./server.json"},scripts:{dev:"bun --watch src/index.ts",build:"bun build src/index.ts --outdir dist --target node --minify",start:"node dist/index.js","type-check":"tsc --noEmit",test:"bun test","test:watch":"bun test --watch",prepublishOnly:"bun run build"},dependencies:{"@modelcontextprotocol/sdk":"^1.0.0"},devDependencies:{"@types/bun":"latest","@types/node":"^22.0.0","bun-types":"latest",typescript:"^5.8.0"},files:["dist","server.json"],keywords:["sequenzy","email","mcp","ai","claude","automation"],license:"MIT",publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/Sequenzy/mcp.git"},homepage:"https://sequenzy.com",bugs:{url:"https://github.com/Sequenzy/mcp/issues"}};class l1 extends Error{statusCode;rawDetails;code;context;constructor(Q,X,Y,W,G){super(Q);this.statusCode=X;this.rawDetails=Y;this.code=W;this.context=G;this.name="McpApiError"}}function WM(Q){if(Q instanceof l1)return{message:Q.message,statusCode:Q.statusCode,code:Q.code,rawDetails:Q.rawDetails,context:Q.context};if(Q instanceof Error)return{message:Q.message};return{message:String(Q)}}function GM(Q){let X=WM(Q),Y=X.message.trim()||"Unknown error",W=Y.toLowerCase(),G=X.rawDetails?.trim()||Y;if(X.context?.title||X.context?.description||X.context?.howToFix||X.context?.docsUrl)return{title:X.context.title??(X.statusCode===409?"Request conflict":"API request failed"),description:X.context.description??Y,howToFix:X.context.howToFix??"Review the details below, adjust the tool input, and retry.",docsUrl:X.context.docsUrl??"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.code==="MCP_AUTH_REQUIRED"||W.includes("sequenzy_api_key environment variable is required"))return{title:"Missing MCP API key",description:"The MCP server started without a Sequenzy API key, so it cannot authenticate any tool or resource request.",howToFix:"Add `SEQUENZY_API_KEY` to the MCP server environment, or run `npx @sequenzy/setup` to configure the integration automatically.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===401||X.code==="UNAUTHORIZED")return{title:"Authentication failed",description:"The MCP server reached Sequenzy, but the current API key was rejected.",howToFix:"Replace `SEQUENZY_API_KEY` with a valid personal API key, then restart the MCP client so it reconnects with fresh credentials.",docsUrl:"https://docs.sequenzy.com/authentication",details:G};if(X.statusCode===403||W.includes("access denied"))return{title:"Access denied",description:"The current API key is valid, but it does not have permission to access the requested company or action.",howToFix:"Use an API key that belongs to the right account, or select a company the key can access before retrying the tool call.",docsUrl:"https://docs.sequenzy.com/authentication",details:G};if(W.includes("no company available")||W.includes("company not found"))return{title:"Company selection required",description:"The MCP server could not resolve a company for this request.",howToFix:"Call `get_account` to inspect available companies, then call `select_company`, or pass `companyId` explicitly in the next tool call.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===404||W.includes("not found"))return{title:"Requested resource not found",description:"Sequenzy could not find the requested campaign, template, sequence, company, or subscriber.",howToFix:"List or fetch the resource collection first, then retry the tool with a confirmed ID or email value.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===409||W.includes("already exists"))return{title:"Resource already exists",description:"Sequenzy rejected this MCP request because it would create a duplicate resource.",howToFix:"List the existing resources first, reuse the matching resource when appropriate, or retry with a unique name or domain.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode===429||W.includes("rate limit"))return{title:"Rate limited",description:"Sequenzy temporarily slowed this MCP request because too many requests were sent too quickly.",howToFix:"Wait briefly before retrying. If the client is looping, reduce retries or add backoff before the next tool call.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.code==="NETWORK_ERROR"||W.includes("fetch failed"))return{title:"Network or configuration error",description:"The MCP server could not reach the Sequenzy API from this environment.",howToFix:"Check connectivity and verify `SEQUENZY_API_URL` if you override it in the MCP environment.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(W.includes("unknown tool")||W.includes("unknown resource"))return{title:"Unsupported MCP request",description:"The client asked for a tool or resource name that this Sequenzy MCP server does not expose.",howToFix:"Refresh the client's tool list and call only the names returned by `list_tools` or `list_resources`.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(W.includes("is required")||W.includes("invalid"))return{title:"Invalid MCP input",description:"The tool call was missing a required field or included an invalid value.",howToFix:"Review the tool schema, supply the missing argument, and retry the request with corrected input.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};if(X.statusCode&&X.statusCode>=500)return{title:"Sequenzy server error",description:"The request reached Sequenzy, but the server could not complete it successfully.",howToFix:"Retry once. If it still fails, keep the details below and consult the docs before escalating.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G};return{title:"Tool execution failed",description:"The MCP server could not complete the requested operation.",howToFix:"Review the details below, adjust the tool input or credentials, and retry.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:G}}function Z1(Q){let X=GM(Q);return[`Sequenzy MCP error: ${X.title}`,`Description: ${X.description}`,`How to fix: ${X.howToFix}`,`Docs: ${X.docsUrl}`,`Details: ${X.details}`].join(`
31
31
  `)}var EX=["product-info","domain","tracking","localization","integrations","products","events","tags","labels","goals","sync-rules","api-keys","widgets","team","danger"],H5={dashboard:"/dashboard/company/{companyId}",campaigns:"/dashboard/company/{companyId}/campaign",campaign:"/dashboard/company/{companyId}/campaign/{campaignId}",campaignPreview:"/dashboard/company/{companyId}/campaign/{campaignId}?step=review",campaignList:"/dashboard/company/{companyId}/campaign/list/{status}",sequences:"/dashboard/company/{companyId}/sequences",sequence:"/dashboard/company/{companyId}/sequences/{sequenceId}",sequenceList:"/dashboard/company/{companyId}/sequences/list/{status}",settings:"/dashboard/company/{companyId}/settings",settingsTab:"/dashboard/company/{companyId}/settings?tab={tab}",emails:"/dashboard/company/{companyId}/emails",email:"/dashboard/company/{companyId}/emails/{emailId}",subscribers:"/dashboard/company/{companyId}/subscribers",sentEmails:"/dashboard/company/{companyId}/sent-emails",emailSend:"/dashboard/company/{companyId}/sent-emails/{emailSendId}",segments:"/dashboard/company/{companyId}/segments",metrics:"/dashboard/company/{companyId}/metrics",transactional:"/dashboard/company/{companyId}/transactional",transactionalEmail:"/dashboard/company/{companyId}/transactional/{transactionalId}",domain:"/dashboard/company/{companyId}/settings/domain/{domainId}",domainVerify:"/dashboard/company/{companyId}/settings/domain/{domainId}/verify"};function $M(Q){let Y=(Q??process.env.SEQUENZY_APP_URL??"https://sequenzy.com").trim().replace(/\/+$/,"");return Y.length>0?Y:"https://sequenzy.com"}function h0(Q){let X=Q?.trim();return X?X:void 0}function t0(Q){return encodeURIComponent(Q)}function Q0(Q,X){return`${Q}${X}`}function X0(Q,X=""){return`/dashboard/company/${t0(Q)}${X}`}function U5(Q,X,Y){return Q0(Q,`${X0(X,"/settings")}?tab=${encodeURIComponent(Y)}`)}function JM(Q,X){let Y=EX.map((W)=>[W,X?U5(Q,X,W):""]);return Object.fromEntries(Y)}function K1(Q={},X){let Y=$M(X),W=h0(Q.companyId),G={},$=JM(Y,W);if(!W)return{appUrl:Y,routeTemplates:H5,settingsTabValues:EX,urls:G,settingsUrls:$};G.dashboard=Q0(Y,X0(W)),G.campaigns=Q0(Y,X0(W,"/campaign")),G.sequences=Q0(Y,X0(W,"/sequences")),G.settings=Q0(Y,X0(W,"/settings")),G.emails=Q0(Y,X0(W,"/emails")),G.subscribers=Q0(Y,X0(W,"/subscribers")),G.sentEmails=Q0(Y,X0(W,"/sent-emails")),G.segments=Q0(Y,X0(W,"/segments")),G.metrics=Q0(Y,X0(W,"/metrics")),G.transactional=Q0(Y,X0(W,"/transactional"));let J=h0(Q.campaignId);if(J)G.campaign=Q0(Y,X0(W,`/campaign/${t0(J)}`)),G.campaignPreview=`${G.campaign}?step=review`;let z=h0(Q.sequenceId);if(z)G.sequence=Q0(Y,X0(W,`/sequences/${t0(z)}`));let H=h0(Q.emailId)??h0(Q.templateId);if(H)G.email=Q0(Y,X0(W,`/emails/${t0(H)}`)),G.template=G.email;let U=h0(Q.transactionalId);if(U)G.transactionalEmail=Q0(Y,X0(W,`/transactional/${t0(U)}`));let A=h0(Q.emailSendId);if(A)G.emailSend=Q0(Y,X0(W,`/sent-emails/${t0(A)}`));let K=h0(Q.domainId);if(K)G.domain=Q0(Y,X0(W,`/settings/domain/${t0(K)}`)),G.domainVerify=`${G.domain}/verify`;let B=h0(Q.status);if(B)G.campaignList=Q0(Y,X0(W,`/campaign/list/${t0(B)}`)),G.sequenceList=Q0(Y,X0(W,`/sequences/list/${t0(B)}`));let L=h0(Q.settingsTab);if(L)G.settingsTab=U5(Y,W,L);return{appUrl:Y,routeTemplates:H5,settingsTabValues:EX,urls:G,settingsUrls:$}}var A5=[{uri:"sequenzy://dashboard",name:"Dashboard Overview",description:"Live overview stats for the last 7 days",mimeType:"application/json"},{uri:"sequenzy://company",name:"Current Company",description:"The currently selected company, including localization settings",mimeType:"application/json"},{uri:"sequenzy://campaigns/recent",name:"Recent Campaigns",description:"Last 10 campaigns with status and basic stats",mimeType:"application/json"},{uri:"sequenzy://subscribers/recent",name:"Recent Subscribers",description:"Most recently added subscribers",mimeType:"application/json"},{uri:"sequenzy://subscribers/engaged",name:"Engaged Subscribers",description:"Most active/engaged subscribers",mimeType:"application/json"},{uri:"sequenzy://sequences",name:"Sequences",description:"All email sequences with status",mimeType:"application/json"},{uri:"sequenzy://templates",name:"Templates",description:"All available email templates with localization status",mimeType:"application/json"},{uri:"sequenzy://segments",name:"Segments",description:"All defined segments with subscriber counts",mimeType:"application/json"},{uri:"sequenzy://tags",name:"Tags",description:"All tags with usage counts",mimeType:"application/json"},{uri:"sequenzy://health",name:"Deliverability Health",description:"Email deliverability metrics and health status",mimeType:"application/json"},{uri:"sequenzy://app-routes",name:"Dashboard URL Routes",description:"Route templates and settings tabs for building Sequenzy dashboard links",mimeType:"application/json"}];async function K5(Q){try{let X;switch(Q){case"sequenzy://dashboard":X=await Z("GET","/api/v1/metrics?period=7d");break;case"sequenzy://company":{let Y=await Z("GET","/api/v1/account"),W=m1()??Y.currentCompanyId;if(!W)throw Error("No company available. Create or select a company first.");X=await Z("GET",`/api/v1/companies/${W}`);break}case"sequenzy://campaigns/recent":X=await Z("GET","/api/v1/campaigns?limit=10");break;case"sequenzy://subscribers/recent":X=await Z("GET","/api/v1/subscribers?sort=createdAt&limit=20");break;case"sequenzy://subscribers/engaged":X=await Z("GET","/api/v1/subscribers?sort=engagement&limit=20");break;case"sequenzy://sequences":X=await Z("GET","/api/v1/sequences");break;case"sequenzy://templates":X=await Z("GET","/api/v1/templates");break;case"sequenzy://segments":X=await Z("GET","/api/v1/segments");break;case"sequenzy://tags":X=await Z("GET","/api/v1/tags");break;case"sequenzy://health":X=await Z("GET","/api/v1/health/deliverability");break;case"sequenzy://app-routes":X=K1();break;default:throw Error(`Unknown resource: ${Q}`)}return{contents:[{uri:Q,mimeType:"application/json",text:JSON.stringify(X,null,2)}]}}catch(X){return{contents:[{uri:Q,mimeType:"text/plain",text:Z1(X)}]}}}var zM={type:"object",properties:{id:{type:"string",description:"Optional filter ID. Any stable string works; one will be generated if omitted."},field:{type:"string",enum:["status","tag","email","emailProvider","added","firstName","lastName","list","emailSent","emailOpened","emailClicked","emailBounced","emailComplained","attribute","event","segment","stripeProduct","stripeCurrentProduct","stripeTrialProduct"],description:"Filter field. Use `event` for custom subscriber events, `segment` for saved segment membership, and `stripeProduct`/`stripeCurrentProduct`/`stripeTrialProduct` for Stripe product-based segments. Engagement fields (`emailSent`, `emailOpened`, `emailClicked`, `emailBounced`, `emailComplained`) accept a time range as the value or a specific campaign via `campaign:<campaign_id>`."},operator:{type:"string",enum:["is","is_not","is_empty","is_not_empty","contains","not_contains","less_than","more_than","at_least","less_than_count","gte","lte","gt","lt"],description:"Filter operator. Use `is_empty` or `is_not_empty` for fields that can be blank, including custom attributes. For `stripeProduct`, use `is` or `is_not` with a raw product ID, and `at_least` or `less_than_count` with `productId:count`. For `event`, use `is`, `is_not`, `at_least`, or `less_than_count`. For engagement fields, use `is` (event happened) or `is_not` (event did not happen)."},value:{type:"string",description:"Filter value. For custom attribute empty checks, use `attributeName:` such as `last_logged_in:`. Event examples: `saas.purchase:30d`, `saas.purchase:all`, or `saas.purchase:5:30d` for thresholds. Segment values are segment IDs. Stripe product examples: `prod_123` for bought/didn't buy, `prod_123:3` for payment thresholds. Engagement examples: `7d`, `30d`, `90d`, `180d`, `all` for rolling time windows, or `campaign:<campaign_id>` to scope to a specific sent campaign (use `list_campaigns` to find IDs)."}},required:["field","operator","value"],additionalProperties:!1},HM={type:"object",properties:{kind:{type:"string",enum:["group"]},id:{type:"string",description:"Stable group ID. Any string works; one will be generated if omitted."},joinOperator:{type:"string",enum:["and","or"],description:"How children in this group combine."},children:{type:"array",minItems:1,items:{type:"object",description:'Either a filter leaf (`kind: "filter"`) or another group (`kind: "group"`).'}}},required:["kind","joinOperator","children"],additionalProperties:!0};function L5(Q){if(!Array.isArray(Q))return Q;return Q.map((X)=>{if(typeof X!=="object"||X===null)return X;let Y=X;if(typeof Y.id==="string"&&Y.id.trim()!=="")return Y;return{...Y,id:crypto.randomUUID()}})}function q5(Q){if(typeof Q!=="object"||Q===null)return Q;let X=Q;if(X.kind==="filter"){let Y=L5([X]);return Array.isArray(Y)?Y[0]:X}if(X.kind!=="group")return Q;return{...X,id:typeof X.id==="string"&&X.id.trim()!==""?X.id:crypto.randomUUID(),children:Array.isArray(X.children)?X.children.map(q5):[]}}function N1(Q,X,Y){if(X.html!==void 0&&X.blocks!==void 0)throw Error(`Provide either \`html\` or \`blocks\` when calling \`${Q}\`, not both.`);if(X.blocks!==void 0&&!Array.isArray(X.blocks))throw Error(`\`blocks\` must be an array when calling \`${Q}\`.`);if(Y?.requireContent&&X.html===void 0&&X.blocks===void 0)throw Error(`Provide either \`html\` or \`blocks\` when calling \`${Q}\`.`)}function HQ(Q,X){if(X.labels===void 0)return;if(!Array.isArray(X.labels))throw Error(`\`labels\` must be an array when calling \`${Q}\`.`);if(X.labels.some((Y)=>typeof Y!=="string"||Y.trim().length===0))throw Error(`\`labels\` must contain only non-empty strings when calling \`${Q}\`.`)}function UM(Q){let X=Q.filters!==void 0,Y=Q.root!==void 0;if(X&&Y)throw Error("Provide either `filters` or `root` when calling `create_segment`, not both.");if(!X&&!Y)throw Error("Provide either `filters` or `root` when calling `create_segment`.");if(X){if(!Array.isArray(Q.filters))throw Error("`filters` must be an array when calling `create_segment`.");if(Q.filters.length===0)throw Error("`filters` must include at least one filter when calling `create_segment`.")}if(Y&&(typeof Q.root!=="object"||Q.root===null))throw Error("`root` must be an object when calling `create_segment`.")}function AM(Q){if(Q.clearEnrollmentFieldPath===!0&&Q.enrollmentFieldPath!==void 0)throw Error("Provide either `enrollmentFieldPath` or `clearEnrollmentFieldPath` when calling `update_sequence`, not both.");let X={...Q};if(delete X.clearEnrollmentFieldPath,Q.clearEnrollmentFieldPath===!0)X.enrollmentFieldPath=null;return X}function KM(Q){let X=j(Q,"subscriberId"),Y=Q.fieldValues,W=Y===void 0?void 0:Array.isArray(Y)?Y:void 0;if(Y!==void 0&&W===void 0)throw Error("`fieldValues` must be an array when calling `cancel_sequence_enrollments`.");let G=W?.map((z)=>typeof z==="string"?z.trim():"").filter((z)=>z.length>0)??[];if(W?.some((z)=>typeof z!=="string")||W!==void 0&&G.length===0)throw Error("`fieldValues` must contain at least one non-empty string when calling `cancel_sequence_enrollments`.");if(X!==void 0===G.length>0)throw Error("Provide exactly one target when calling `cancel_sequence_enrollments`: `subscriberId` or `fieldValues`.");let $=j(Q,"fieldPath"),J=j(Q,"reason");return{...X!==void 0&&{subscriberId:X},...$!==void 0&&{fieldPath:$},...G.length>0&&{fieldValues:G},...typeof Q.dryRun==="boolean"&&{dryRun:Q.dryRun},...J!==void 0&&{reason:J}}}function BM(Q){N1("create_campaign",Q),HQ("create_campaign",Q);let X=j(Q,"prompt")!==void 0,Y=Q.html!==void 0,W=Q.blocks!==void 0,G=Q.templateId!==void 0;if(Q.prompt!==void 0&&!X)throw Error("`prompt` cannot be empty when calling `create_campaign`.");if(X&&(Y||W||G))throw Error("Provide either `prompt`, `html`, `blocks`, or `templateId` when calling `create_campaign`, not multiple content sources.");if(!X&&(Q.style!==void 0||Q.tone!==void 0))throw Error("`style` and `tone` can only be used with `prompt` when calling `create_campaign`.");if(!X&&j(Q,"subject")===void 0)throw Error("`subject` is required unless `prompt` is provided when calling `create_campaign`.")}function DM(Q){if(j(Q,"scheduledAt")===void 0)throw Error("`scheduledAt` is required when calling `schedule_campaign`.");if(Q.targetLists!==void 0&&!D0(Q.targetLists))throw Error("`targetLists` must be an object when calling `schedule_campaign`.");if(Q.sendTimeOptimization!==void 0){if(typeof Q.sendTimeOptimization!=="boolean")throw Error("`sendTimeOptimization` must be a boolean when calling `schedule_campaign`.")}if(Q.spreadOverHours!==void 0){if(typeof Q.spreadOverHours!=="number"||!Number.isInteger(Q.spreadOverHours)||Q.spreadOverHours<1||Q.spreadOverHours>72)throw Error("`spreadOverHours` must be an integer between 1 and 72 when calling `schedule_campaign`.")}}function LM(Q){N1("create_transactional_email",Q);let X=j(Q,"prompt")!==void 0,Y=Q.html!==void 0,W=Q.blocks!==void 0;if(Q.prompt!==void 0&&!X)throw Error("`prompt` cannot be empty when calling `create_transactional_email`.");if(X&&(Y||W))throw Error("Provide either `prompt`, `html`, or `blocks` when calling `create_transactional_email`, not multiple content sources.");if(!X&&(Q.style!==void 0||Q.tone!==void 0))throw Error("`style` and `tone` can only be used with `prompt` when calling `create_transactional_email`.");if(!X&&!Y&&!W)throw Error("Provide either `prompt`, `html`, or `blocks` when calling `create_transactional_email`.");if(!X&&j(Q,"subject")===void 0)throw Error("`subject` is required unless `prompt` is provided when calling `create_transactional_email`.")}var B5={type:"object",description:"A step to create inside a branch path. Use type:'delay' for a standalone delay, type:'email' for an email, or type:'create_discount' for a discount action.",properties:{type:{type:"string",enum:["email","delay","create_discount","discount","webhook"],description:"Branch path step type. Omit for email steps; use delay for standalone waits."},nodeType:{type:"string",enum:["logic_delay","action_email","action_create_discount","action_add_tag","action_remove_tag","action_add_to_list","action_remove_from_list","action_update_attributes","logic_wait_for_event","action_webhook"],description:"Advanced branch path node type. Prefer type unless creating a non-email action."},config:{type:"object",description:"Config for advanced nodeType steps such as tag/list/webhook/wait-for-event actions.",additionalProperties:!0},subject:{type:"string",description:"Email subject. Required for email steps."},previewText:{type:"string",description:"Email preview text."},blocks:{type:"array",description:"Sequenzy email blocks for email steps.",items:{type:"object"}},html:{type:"string",description:"HTML content for email steps."},delay:{type:"object",description:"Delay before this step, or the delay duration when type is delay.",properties:{days:{type:"number"},hours:{type:"number"},minutes:{type:"number"}}},delayMs:{type:"number",description:"Delay in milliseconds. Useful for standalone type:'delay' steps."},name:{type:"string",description:"Email template name for email steps."},discount:{type:"object",description:"Discount configuration for create_discount steps. Same shape as create_sequence steps.",additionalProperties:!0},label:{type:"string",description:"Node label for discount or advanced node steps."},provider:{type:"string",enum:["stripe","shopify"]},discountType:{type:"string",enum:["percent","amount"]},percentOff:{type:"number"},amountOff:{type:"number"},currency:{type:"string"},duration:{type:"string",enum:["once","forever","repeating"]},durationInMonths:{type:"number"},appliesToAllPlans:{type:"boolean"},planIds:{type:"array",items:{type:"string"}},codePrefix:{type:"string"},maxRedemptions:{type:"number"},lockToSubscriber:{type:"boolean"},expiresAt:{type:"string"},expiresInHours:{type:"number"}},additionalProperties:!1};function qM(Q){if(!Q||typeof Q!=="object")return null;let X=Q;if(X.success!==!1)return null;if(typeof X.error==="string")return Error(X.error);if(X.error&&typeof X.error==="object"&&typeof X.error.message==="string")return Error(X.error.message);if(typeof X.message==="string")return Error(X.message);return Error("The tool returned an unsuccessful response.")}function D0(Q){return typeof Q==="object"&&Q!==null&&!Array.isArray(Q)}function D5(Q){return Q.trim().toLowerCase().replace(/\s+/g,"-")}function FM(Q){let X=new URLSearchParams;if(typeof Q.query==="string"&&Q.query.trim()!=="")X.set("query",Q.query.trim());if(Array.isArray(Q.tags)&&Q.tags.length>0)X.set("tags",Q.tags.filter((Y)=>typeof Y==="string"&&Y.trim()!=="").join(","));if(typeof Q.segmentId==="string"&&Q.segmentId.trim()!=="")X.set("segmentId",Q.segmentId);if(typeof Q.status==="string"&&Q.status.trim()!=="")X.set("status",Q.status.trim());return X.set("page",String(Q.page)),X.set("limit",String(Q.pageSize)),X}async function OM(Q,X){let Y=typeof Q.limit==="number"&&Number.isFinite(Q.limit)?Math.max(1,Math.trunc(Q.limit)):void 0,W=Math.min(100,Math.max(1,Y??100)),G=[],$=1,J=0,z=0,H=0;while(!0){let A=FM({query:Q.query,tags:Q.tags,segmentId:Q.segmentId,status:Q.status,page:$,pageSize:W}),K=await Z("GET",`/api/v1/subscribers?${A.toString()}`,void 0,X);J=K.pagination?.total??K.subscribers.length,z=K.pagination?.totalPages??1,H+=1,G.push(...K.subscribers??[]);let B=Y!==void 0&&G.length>=Y,L=K.pagination?$>=K.pagination.totalPages:(K.subscribers??[]).length<W;if(B||L)break;$+=1}let U=Y!==void 0?G.slice(0,Y):G;return{success:!0,subscribers:U,pagination:{page:1,limit:W,total:J,totalPages:z,fetchedPages:H},returned:U.length,truncated:Y!==void 0&&J>0&&U.length<J}}function MM(Q){let X=typeof Q.email==="string"&&Q.email.trim()!==""?Q.email.trim():void 0,Y=typeof Q.externalId==="string"&&Q.externalId.trim()!==""?Q.externalId.trim():void 0;return{...X?{email:X}:{},...Y?{externalId:Y}:{}}}function u4(Q,X){let Y=MM(X);if(!Y.email&&!Y.externalId)throw Error(`Provide either \`email\` or \`externalId\` when calling \`${Q}\`.`);return Y}function SX(Q){if(Q.email)return`/api/v1/subscribers/${encodeURIComponent(Q.email)}`;return`/api/v1/subscribers/external?externalId=${encodeURIComponent(String(Q.externalId))}`}async function TX(Q,X){return Z("GET",SX(Q),void 0,X)}function j(Q,X){let Y=Q[X];if(typeof Y!=="string")return;let W=Y.trim();return W.length>0?W:void 0}async function F5(Q){let X=j(Q,"companyId");if(X)return X;let Y=m1();if(Y)return Y;try{return(await Z("GET","/api/v1/account")).currentCompanyId??void 0}catch{return}}function h4(Q,X){if(!D0(Q)||!X)return Q;return{...Q,url:X}}function O5(Q,X){if(!D0(Q))return Q;return{...Q,...X.campaign!==void 0&&{url:X.campaign},...X.campaignPreview!==void 0&&{previewUrl:X.campaignPreview}}}function zQ(Q,X,Y){if(!Array.isArray(Q)||!X)return Q;return Q.map((W)=>{if(!D0(W))return W;let G=j(W,"id");if(!G)return W;let $=K1({companyId:X,...Y==="campaign"&&{campaignId:G},...Y==="sequence"&&{sequenceId:G},...Y==="template"&&{emailId:G},...Y==="transactional"&&{transactionalId:G}});if(Y==="campaign")return O5(W,$.urls);let J=Y==="sequence"?$.urls.sequence:Y==="template"?$.urls.email:$.urls.transactionalEmail;return h4(W,J)})}function VM(Q){if(!Array.isArray(Q))return Q;return Q.map((X)=>{if(!D0(X))return X;let Y=j(X,"id");if(!Y)return X;let W=K1({companyId:Y});return{...X,url:W.urls.dashboard,settingsUrl:W.urls.settings}})}var ZM=new Set(["get_account","select_company","create_company","get_company","list_campaigns","get_campaign","get_email_send","create_campaign","update_campaign","schedule_campaign","send_test_email","list_sequences","get_sequence","create_sequence","update_sequence","enable_sequence","disable_sequence","cancel_sequence_enrollments","list_ab_tests","get_ab_test","get_ab_test_stats","update_ab_test_variant","list_templates","get_template","create_template","update_template","list_transactional_emails","get_transactional_email","create_transactional_email","update_transactional_email"]);async function NM(Q,X,Y){if(!D0(Y)||!ZM.has(Q))return Y;let W=D0(Y.company)?Y.company:void 0,$=j(Y,"selectedCompanyId")??j(Y,"currentCompanyId")??j(Y,"companyId")??(W?j(W,"id"):void 0)??(W?j(W,"companyId"):void 0)??await F5(X);if(!$)return Y;let J=D0(Y.campaign)?Y.campaign:void 0,z=D0(Y.sequence)?Y.sequence:void 0,H=D0(Y.template)?Y.template:void 0,U=D0(Y.transactional)&&!Array.isArray(Y.transactional)?Y.transactional:void 0,A={companyId:$,campaignId:j(X,"campaignId")??j(Y,"campaignId")??(J?j(J,"id"):void 0),sequenceId:j(X,"sequenceId")??j(Y,"sequenceId")??(z?j(z,"id"):void 0),emailId:j(Y,"templateId")??(H?j(H,"id"):void 0)??(U?j(U,"emailId"):void 0)??j(X,"templateId"),transactionalId:j(X,"transactionalId")??(U?j(U,"id"):void 0)??j(X,"idOrSlug"),emailSendId:j(X,"emailSendId")??j(Y,"emailSendId")??(D0(Y.emailSend)?j(Y.emailSend,"id"):void 0),status:j(X,"status")},K=K1(A),B=W?K1({companyId:$}):void 0;return{...Y,...Array.isArray(Y.companies)&&{companies:VM(Y.companies)},...Array.isArray(Y.campaigns)&&{campaigns:zQ(Y.campaigns,$,"campaign")},...Array.isArray(Y.sequences)&&{sequences:zQ(Y.sequences,$,"sequence")},...Array.isArray(Y.templates)&&{templates:zQ(Y.templates,$,"template")},...Array.isArray(Y.transactional)&&{transactional:zQ(Y.transactional,$,"transactional")},...W&&B!==void 0&&{company:{...W,url:B.urls.dashboard,settingsUrl:B.urls.settings}},...J&&K.urls.campaign!==void 0&&{campaign:O5(J,K.urls)},...z&&K.urls.sequence!==void 0&&{sequence:h4(z,K.urls.sequence)},...H&&K.urls.email!==void 0&&{template:h4(H,K.urls.email)},...U&&K.urls.transactionalEmail!==void 0&&{transactional:h4(U,K.urls.transactionalEmail)},...D0(Y.emailSend)&&K.urls.emailSend!==void 0&&{emailSend:h4(Y.emailSend,K.urls.emailSend)},appUrls:K.urls}}var M5=[{name:"get_account",description:`Get current account information including available companies. IMPORTANT: If you have access to multiple companies, you MUST either:
32
32
  1. Call select_company first to choose which company to work with, OR
33
33
  2. Pass companyId explicitly in each tool call
@@ -45,7 +45,7 @@ Use cases:
45
45
  - 'subscribe_form': Adding subscribers from signup forms
46
46
  - 'event_tracking': Tracking CUSTOM events only (not payment events - those come from the integration)
47
47
 
48
- Before implementing, use create_api_key to generate an API key and save it to .env as SEQUENZY_API_KEY.`,inputSchema:{type:"object",properties:{framework:{type:"string",description:"Framework/language (nextjs, express, python, etc.)"},use_case:{type:"string",description:"Use case: 'transactional' (sending emails), 'subscribe_form' (adding subscribers), 'event_tracking' (tracking CUSTOM events only - payment events should come from Stripe/Polar/etc integration)"}}}},{name:"add_subscriber",description:"Add a new subscriber to your list",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to add subscriber to. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address"},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide this with email when creating, or instead of email for an existing subscriber."},attributes:{type:"object",description:"Custom attributes (name, plan, etc.)"},tags:{type:"array",items:{type:"string"},description:"Tags to apply to the subscriber"},listIds:{type:"array",items:{type:"string"},description:"List IDs to add subscriber to"},status:{type:"string",description:"Initial subscriber status: active, unsubscribed, or bounced. Defaults to active."},optInMode:{type:"string",description:"Consent mode: confirmed creates active immediately when consent is verified, double_opt_in sends a confirmation email before activation, and default obeys company double opt-in settings."}},required:[]}},{name:"update_subscriber",description:"Update an existing subscriber's attributes or tags",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."},attributes:{type:"object",description:"Attributes to update"},addTags:{type:"array",items:{type:"string"},description:"Tags to add"},removeTags:{type:"array",items:{type:"string"},description:"Tags to remove"}},required:[]}},{name:"remove_subscriber",description:"Unsubscribe or delete a subscriber",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."},hardDelete:{type:"boolean",description:"If true, permanently deletes. If false, just unsubscribes."}},required:[]}},{name:"get_subscriber",description:"Get the full subscriber profile, including tags, list memberships, sequence enrollments, email stats, and recent activity",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."}},required:[]}},{name:"search_subscribers",description:"Search subscribers by free-text query, tags, or segment. If you omit limit, the tool fetches all pages and returns every match.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},query:{type:"string",description:"Search query (email or name)"},tags:{type:"array",items:{type:"string"},description:"Filter by tags"},segmentId:{type:"string",description:"Filter by segment ID"},status:{type:"string",description:"Filter by subscriber status: active, unsubscribed, or bounced."},limit:{type:"number",description:"Maximum results to return. If omitted, the tool returns all matches across pages."}}}},{name:"list_tags",description:"List all tags in the account",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list tags for. If not provided, uses the currently selected company."}}}},{name:"list_lists",description:"List all subscriber lists",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list lists for. If not provided, uses the currently selected company."}}}},{name:"create_list",description:"Create a new subscriber list",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the list in. If not provided, uses the currently selected company."},name:{type:"string",description:"List name"},description:{type:"string",description:"List description"}},required:["name"]}},{name:"list_segments",description:"List all segments",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list segments for. If not provided, uses the currently selected company."}}}},{name:"create_segment",description:'Create a new segment from explicit filter rules. Use `filters` plus `filterJoinOperator` for flat legacy rules, or `root` for nested AND/OR groups such as `{ "kind": "group", "joinOperator": "and", "children": [{ "kind": "filter", "field": "attribute", "operator": "gte", "value": "mrr:50" }, { "kind": "group", "joinOperator": "or", "children": [{ "kind": "filter", "field": "tag", "operator": "contains", "value": "vip" }, { "kind": "filter", "field": "event", "operator": "is_not", "value": "saas.purchase:30d" }] }] }`. Supports `event` and `segment` fields, Stripe product purchase filters, and campaign-specific engagement filters.',inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the segment in. If not provided, uses the currently selected company."},name:{type:"string",description:"Segment name"},filterJoinOperator:{type:"string",enum:["and","or"],description:'How top-level filters combine. Use `"and"` to require every filter or `"or"` to match any filter.'},filters:{type:"array",items:zM,minItems:1,description:'Array of segment filters. Example custom attribute empty check: [{"id":"filter-1","field":"attribute","operator":"is_empty","value":"last_logged_in:"}]. Example Stripe purchase filter: [{"id":"filter-1","field":"stripeProduct","operator":"is","value":"prod_123"}]. Example threshold filter: [{"id":"filter-1","field":"stripeProduct","operator":"at_least","value":"prod_123:3"}]. Example campaign-specific engagement combo: [{"id":"filter-1","field":"emailBounced","operator":"is","value":"campaign:cmp_abc"},{"id":"filter-2","field":"emailBounced","operator":"is_not","value":"campaign:cmp_xyz"}]. Combine them with `filterJoinOperator: "or"` to match any filter.'},root:{...HM,description:"Nested filter root. Mutually exclusive with `filters` and `filterJoinOperator`."}},required:["name"]}},{name:"get_segment_count",description:"Get the number of subscribers in a segment",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},segmentId:{type:"string",description:"Segment ID"}},required:["segmentId"]}},{name:"list_templates",description:"List all email templates, including per-locale localization sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."}}}},{name:"get_template",description:"Get a template's details, content, and all localized variants with sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"}},required:["templateId"]}},{name:"create_template",description:"Create a new email template",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},name:{type:"string",description:"Template name"},subject:{type:"string",description:"Email subject line"},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},labels:{type:"array",description:"Optional label names to assign. Missing labels are created automatically.",items:{type:"string"}}},required:["name","subject"]}},{name:"update_template",description:"Update an existing template. At least one of `name`, `subject`, `html`, `blocks`, or `labels` is required, and only those update fields are accepted.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"},name:{type:"string",description:"Template name"},subject:{type:"string",description:"Email subject line"},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},labels:{type:"array",description:"Replacement label names. Send an empty array to clear labels. Missing labels are created automatically.",items:{type:"string"}}},required:["templateId"],additionalProperties:!1}},{name:"delete_template",description:"Delete a template",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"}},required:["templateId"]}},{name:"list_ab_tests",description:"List A/B tests and their variants",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Optional sequence ID to filter automation A/B tests."}}}},{name:"get_ab_test",description:"Get A/B test details, variants, and per-locale localization sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"}},required:["abTestId"]}},{name:"get_ab_test_stats",description:"Get A/B test aggregate stats and per-variant stats. Supports period or custom start/end ranges.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"},period:{type:"string",description:"Optional period: 1h, 24h, 7d, 30d, or 90d."},start:{type:"string",description:"Custom range start as ISO 8601. Requires end."},end:{type:"string",description:"Custom range end as ISO 8601. Requires start."}},required:["abTestId"]}},{name:"update_ab_test_variant",description:"Update a draft A/B test variant. Provide at least one of subject, previewText, html, or blocks. Use either html or blocks, not both.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"},variantId:{type:"string",description:"A/B test variant ID"},subject:{type:"string",description:"Variant subject line"},previewText:{type:"string",description:"Variant preview text. Pass an empty string to clear it."},html:{type:"string",description:"Replacement HTML body. Mutually exclusive with blocks."},blocks:{type:"array",description:"Replacement Sequenzy email blocks. Mutually exclusive with html.",items:{type:"object"}}},required:["abTestId","variantId"],additionalProperties:!1}},{name:"list_campaigns",description:"List all campaigns",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list campaigns for. If not provided, uses the currently selected company."},status:{type:"string",description:"Filter by status (draft, scheduled, sent)"},label:{type:"string",description:"Optional label name filter. Only campaigns assigned this label are returned."}}}},{name:"get_campaign",description:"Get campaign details and stats",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"}},required:["campaignId"]}},{name:"get_email_send",description:"Get a sent email by emailSendId, including the stored HTML body when available and the ClickHouse event timeline. If the short-lived email send row has been cleaned up, returns the retained ClickHouse events and a sparse summary.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},emailSendId:{type:"string",description:"Email send ID to inspect."}},required:["emailSendId"]}},{name:"create_campaign",description:"Create a new campaign (as draft)",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the campaign in. If not provided, uses the currently selected company."},name:{type:"string",description:"Campaign name"},subject:{type:"string",description:"Email subject line. Optional when `prompt` is provided because the generated subject will be used."},trackingCode:{type:"string",description:"Optional campaign tracking code for UTM templates. Use only when explicitly requested."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},prompt:{type:"string",description:"Generate campaign blocks from a prompt. Mutually exclusive with `html`, `blocks`, and `templateId`."},style:{type:"string",description:"Prompt generation style: minimal, branded, promotional. Only used with `prompt`."},tone:{type:"string",description:"Prompt generation tone: professional, casual, friendly. Only used with `prompt`."},templateId:{type:"string",description:"Use a template instead of html"},segmentId:{type:"string",description:"Target segment ID"},campaignData:{type:"object",description:"Optional campaign-scoped JSON data for repeat blocks and personalization."},computedLists:{type:"array",description:"Optional computed list definitions derived from campaignData at send time.",items:{type:"object"}},labels:{type:"array",description:"Optional label names to assign. Missing labels are created automatically.",items:{type:"string"}}},required:["name"]}},{name:"update_campaign",description:"Update a draft campaign",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"},name:{type:"string",description:"Campaign name"},subject:{type:"string",description:"Email subject line"},trackingCode:{type:"string",description:"Optional campaign tracking code for UTM templates. Use only when explicitly requested. Send an empty string to clear it."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},replyTo:{type:"string",description:"Set reply-to using an existing reply profile email address for this company."},replyProfileId:{type:"string",description:"Set reply-to using a reply profile ID for this company."},campaignData:{type:"object",description:"Set campaign-scoped JSON data for repeat blocks and personalization."},computedLists:{type:"array",description:"Set computed list definitions derived from campaignData at send time.",items:{type:"object"}},labels:{type:"array",description:"Replacement label names. Send an empty array to clear labels. Missing labels are created automatically.",items:{type:"string"}}},required:["campaignId"],additionalProperties:!1}},{name:"schedule_campaign",description:"Schedule a draft or already scheduled campaign. Returns dashboard edit and preview URLs.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"},scheduledAt:{type:"string",description:"Future ISO 8601 timestamp for the send, for example 2026-06-01T14:00:00Z."},targetLists:{type:"object",description:"Optional campaign targeting object. Omit to use saved targeting or all active subscribers. Examples: {type:'all'}, {type:'lists', listIds:['list_123']}, {type:'segment', segmentId:'seg_123'}, or {type:'filtered', filters:[...], filterJoinOperator:'and'}.",additionalProperties:!0},sendTimeOptimization:{type:"boolean",description:"Whether to use send-time optimization."},spreadOverHours:{type:"number",description:"Spread delivery over an integer number of hours from 1 to 72. When set, spread delivery takes precedence over send-time optimization."}},required:["campaignId","scheduledAt"],additionalProperties:!1}},{name:"send_test_email",description:"Send a test email to a single address",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID to test"},to:{type:"string",description:"Email address to send test to"}},required:["campaignId","to"]}},{name:"list_sequences",description:"List all email sequences (automations)",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list sequences for. If not provided, uses the currently selected company."}}}},{name:"get_sequence",description:"Get sequence details plus editable step content. The response includes sequence.emails with each step's nodeId, linked emailId, subject, previewText, and blocks.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"],additionalProperties:!1}},{name:"create_sequence",description:`Create a new email sequence. Provide either a goal for AI generation or explicit steps. Explicit steps can include email content and create_discount actions; emails after a discount action can use merge tags such as {{discount.code}} and {{discount.percentOff}}. For AI-generated sequences, the tool polls until emails are generated (typically 30-60 seconds).
48
+ Before implementing, use create_api_key to generate an API key and save it to .env as SEQUENZY_API_KEY.`,inputSchema:{type:"object",properties:{framework:{type:"string",description:"Framework/language (nextjs, express, python, etc.)"},use_case:{type:"string",description:"Use case: 'transactional' (sending emails), 'subscribe_form' (adding subscribers), 'event_tracking' (tracking CUSTOM events only - payment events should come from Stripe/Polar/etc integration)"}}}},{name:"add_subscriber",description:"Add a new subscriber to your list",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to add subscriber to. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address"},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide this with email when creating, or instead of email for an existing subscriber."},attributes:{type:"object",description:"Custom attributes (name, plan, etc.)"},tags:{type:"array",items:{type:"string"},description:"Tags to apply to the subscriber"},listIds:{type:"array",items:{type:"string"},description:"List IDs to add subscriber to"},status:{type:"string",description:"Initial subscriber status: active, unsubscribed, or bounced. Defaults to active."},optInMode:{type:"string",description:"Consent mode: confirmed creates active immediately when consent is verified, double_opt_in sends a confirmation email before activation, and default obeys company double opt-in settings."}},required:[]}},{name:"update_subscriber",description:"Update an existing subscriber's attributes or tags",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."},attributes:{type:"object",description:"Attributes to update"},addTags:{type:"array",items:{type:"string"},description:"Tags to add"},removeTags:{type:"array",items:{type:"string"},description:"Tags to remove"}},required:[]}},{name:"remove_subscriber",description:"Unsubscribe or delete a subscriber",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."},hardDelete:{type:"boolean",description:"If true, permanently deletes. If false, just unsubscribes."}},required:[]}},{name:"get_subscriber",description:"Get the full subscriber profile, including tags, list memberships, sequence enrollments, email stats, and recent activity",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."}},required:[]}},{name:"search_subscribers",description:"Search subscribers by free-text query, tags, or segment. If you omit limit, the tool fetches all pages and returns every match.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},query:{type:"string",description:"Search query (email or name)"},tags:{type:"array",items:{type:"string"},description:"Filter by tags"},segmentId:{type:"string",description:"Filter by segment ID"},status:{type:"string",description:"Filter by subscriber status: active, unsubscribed, or bounced."},limit:{type:"number",description:"Maximum results to return. If omitted, the tool returns all matches across pages."}}}},{name:"list_tags",description:"List all tags in the account",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list tags for. If not provided, uses the currently selected company."}}}},{name:"list_lists",description:"List all subscriber lists",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list lists for. If not provided, uses the currently selected company."}}}},{name:"create_list",description:"Create a new subscriber list",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the list in. If not provided, uses the currently selected company."},name:{type:"string",description:"List name"},description:{type:"string",description:"List description"}},required:["name"]}},{name:"list_segments",description:"List all segments",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list segments for. If not provided, uses the currently selected company."}}}},{name:"create_segment",description:'Create a new segment from explicit filter rules. Use `filters` plus `filterJoinOperator` for flat legacy rules, or `root` for nested AND/OR groups such as `{ "kind": "group", "joinOperator": "and", "children": [{ "kind": "filter", "field": "attribute", "operator": "gte", "value": "mrr:50" }, { "kind": "group", "joinOperator": "or", "children": [{ "kind": "filter", "field": "tag", "operator": "contains", "value": "vip" }, { "kind": "filter", "field": "event", "operator": "is_not", "value": "saas.purchase:30d" }] }] }`. Supports `event` and `segment` fields, Stripe product purchase filters, and campaign-specific engagement filters.',inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the segment in. If not provided, uses the currently selected company."},name:{type:"string",description:"Segment name"},filterJoinOperator:{type:"string",enum:["and","or"],description:'How top-level filters combine. Use `"and"` to require every filter or `"or"` to match any filter.'},filters:{type:"array",items:zM,minItems:1,description:'Array of segment filters. Example custom attribute empty check: [{"id":"filter-1","field":"attribute","operator":"is_empty","value":"last_logged_in:"}]. Example Stripe purchase filter: [{"id":"filter-1","field":"stripeProduct","operator":"is","value":"prod_123"}]. Example threshold filter: [{"id":"filter-1","field":"stripeProduct","operator":"at_least","value":"prod_123:3"}]. Example campaign-specific engagement combo: [{"id":"filter-1","field":"emailBounced","operator":"is","value":"campaign:cmp_abc"},{"id":"filter-2","field":"emailBounced","operator":"is_not","value":"campaign:cmp_xyz"}]. Combine them with `filterJoinOperator: "or"` to match any filter.'},root:{...HM,description:"Nested filter root. Mutually exclusive with `filters` and `filterJoinOperator`."}},required:["name"]}},{name:"get_segment_count",description:"Get the number of subscribers in a segment",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},segmentId:{type:"string",description:"Segment ID"}},required:["segmentId"]}},{name:"list_templates",description:"List all email templates, including per-locale localization sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."}}}},{name:"get_template",description:"Get a template's details, content, and all localized variants with sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"}},required:["templateId"]}},{name:"create_template",description:"Create a new email template",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},name:{type:"string",description:"Template name"},subject:{type:"string",description:"Email subject line"},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},labels:{type:"array",description:"Optional label names to assign. Missing labels are created automatically.",items:{type:"string"}}},required:["name","subject"]}},{name:"update_template",description:"Update an existing template. At least one of `name`, `subject`, `html`, `blocks`, or `labels` is required, and only those update fields are accepted.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"},name:{type:"string",description:"Template name"},subject:{type:"string",description:"Email subject line"},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},labels:{type:"array",description:"Replacement label names. Send an empty array to clear labels. Missing labels are created automatically.",items:{type:"string"}}},required:["templateId"],additionalProperties:!1}},{name:"delete_template",description:"Delete a template",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},templateId:{type:"string",description:"Template ID"}},required:["templateId"]}},{name:"list_ab_tests",description:"List A/B tests and their variants",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Optional sequence ID to filter automation A/B tests."}}}},{name:"get_ab_test",description:"Get A/B test details, variants, and per-locale localization sync status",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"}},required:["abTestId"]}},{name:"get_ab_test_stats",description:"Get A/B test aggregate stats and per-variant stats. Supports period or custom start/end ranges.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"},period:{type:"string",description:"Optional period: 1h, 24h, 7d, 30d, or 90d."},start:{type:"string",description:"Custom range start as ISO 8601. Requires end."},end:{type:"string",description:"Custom range end as ISO 8601. Requires start."}},required:["abTestId"]}},{name:"restart_ab_test",description:"Run another sequence A/B test after a winner is selected. By default the winner becomes the new control; pass sourceVariantId to use another variant as the control email.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID to restart"},sourceVariantId:{type:"string",description:"Optional variant ID to use as the new control email. Defaults to the selected winner."},testType:{type:"string",description:"Optional test type: subject or content."},winnerThreshold:{type:"number",description:"Optional number of subscribers before selecting a winner. Must be from 10 to 1000."},variantCount:{type:"number",description:"Optional total variants including the control. Must be from 2 to 4."}},required:["abTestId"],additionalProperties:!1}},{name:"update_ab_test_variant",description:"Update a draft A/B test variant. Provide at least one of subject, previewText, html, or blocks. Use either html or blocks, not both.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},abTestId:{type:"string",description:"A/B test ID"},variantId:{type:"string",description:"A/B test variant ID"},subject:{type:"string",description:"Variant subject line"},previewText:{type:"string",description:"Variant preview text. Pass an empty string to clear it."},html:{type:"string",description:"Replacement HTML body. Mutually exclusive with blocks."},blocks:{type:"array",description:"Replacement Sequenzy email blocks. Mutually exclusive with html.",items:{type:"object"}}},required:["abTestId","variantId"],additionalProperties:!1}},{name:"list_campaigns",description:"List all campaigns",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list campaigns for. If not provided, uses the currently selected company."},status:{type:"string",description:"Filter by status (draft, scheduled, sent)"},label:{type:"string",description:"Optional label name filter. Only campaigns assigned this label are returned."}}}},{name:"get_campaign",description:"Get campaign details and stats",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"}},required:["campaignId"]}},{name:"get_email_send",description:"Get a sent email by emailSendId, including the stored HTML body when available and the ClickHouse event timeline. If the short-lived email send row has been cleaned up, returns the retained ClickHouse events and a sparse summary.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},emailSendId:{type:"string",description:"Email send ID to inspect."}},required:["emailSendId"]}},{name:"create_campaign",description:"Create a new campaign (as draft)",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the campaign in. If not provided, uses the currently selected company."},name:{type:"string",description:"Campaign name"},subject:{type:"string",description:"Email subject line. Optional when `prompt` is provided because the generated subject will be used."},trackingCode:{type:"string",description:"Optional campaign tracking code for UTM templates. Use only when explicitly requested."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},prompt:{type:"string",description:"Generate campaign blocks from a prompt. Mutually exclusive with `html`, `blocks`, and `templateId`."},style:{type:"string",description:"Prompt generation style: minimal, branded, promotional. Only used with `prompt`."},tone:{type:"string",description:"Prompt generation tone: professional, casual, friendly. Only used with `prompt`."},templateId:{type:"string",description:"Use a template instead of html"},segmentId:{type:"string",description:"Target segment ID"},campaignData:{type:"object",description:"Optional campaign-scoped JSON data for repeat blocks and personalization."},computedLists:{type:"array",description:"Optional computed list definitions derived from campaignData at send time.",items:{type:"object"}},labels:{type:"array",description:"Optional label names to assign. Missing labels are created automatically.",items:{type:"string"}}},required:["name"]}},{name:"update_campaign",description:"Update a draft campaign",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"},name:{type:"string",description:"Campaign name"},subject:{type:"string",description:"Email subject line"},trackingCode:{type:"string",description:"Optional campaign tracking code for UTM templates. Use only when explicitly requested. Send an empty string to clear it."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }.",items:{type:"object"}},replyTo:{type:"string",description:"Set reply-to using an existing reply profile email address for this company."},replyProfileId:{type:"string",description:"Set reply-to using a reply profile ID for this company."},campaignData:{type:"object",description:"Set campaign-scoped JSON data for repeat blocks and personalization."},computedLists:{type:"array",description:"Set computed list definitions derived from campaignData at send time.",items:{type:"object"}},labels:{type:"array",description:"Replacement label names. Send an empty array to clear labels. Missing labels are created automatically.",items:{type:"string"}}},required:["campaignId"],additionalProperties:!1}},{name:"schedule_campaign",description:"Schedule a draft or already scheduled campaign. Returns dashboard edit and preview URLs.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"},scheduledAt:{type:"string",description:"Future ISO 8601 timestamp for the send, for example 2026-06-01T14:00:00Z."},targetLists:{type:"object",description:"Optional campaign targeting object. Omit to use saved targeting or all active subscribers. Examples: {type:'all'}, {type:'lists', listIds:['list_123']}, {type:'segment', segmentId:'seg_123'}, or {type:'filtered', filters:[...], filterJoinOperator:'and'}.",additionalProperties:!0},sendTimeOptimization:{type:"boolean",description:"Whether to use send-time optimization."},spreadOverHours:{type:"number",description:"Spread delivery over an integer number of hours from 1 to 72. When set, spread delivery takes precedence over send-time optimization."}},required:["campaignId","scheduledAt"],additionalProperties:!1}},{name:"send_test_email",description:"Send a test email to a single address",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID to test"},to:{type:"string",description:"Email address to send test to"}},required:["campaignId","to"]}},{name:"list_sequences",description:"List all email sequences (automations)",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to list sequences for. If not provided, uses the currently selected company."}}}},{name:"get_sequence",description:"Get sequence details plus editable step content. The response includes sequence.emails with each step's nodeId, linked emailId, subject, previewText, and blocks.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"],additionalProperties:!1}},{name:"create_sequence",description:`Create a new email sequence. Provide either a goal for AI generation or explicit steps. Explicit steps can include email content and create_discount actions; emails after a discount action can use merge tags such as {{discount.code}} and {{discount.percentOff}}. For AI-generated sequences, the tool polls until emails are generated (typically 30-60 seconds).
49
49
 
50
50
  IMPORTANT GUIDELINES:
51
51
 
@@ -174,4 +174,4 @@ BUILT-IN EVENTS (auto-fired by payment integrations):
174
174
 
175
175
  OTHER BUILT-IN EVENTS:
176
176
  - email.opened, email.clicked, email.replied, email.bounced, email.unsubscribed
177
- - contact.subscribed, contact.unsubscribed`,inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the sequence in. If not provided, uses the currently selected company."},name:{type:"string",description:"Sequence name (e.g., 'User Onboarding', 'Welcome Series')"},trigger:{type:"string",enum:["contact_added","tag_added","segment_entered","event_received","inactivity","frequency"],description:"Trigger type: 'contact_added' (when added to a list), 'tag_added' (when tag is applied), 'segment_entered' (when a contact newly enters a saved segment), 'event_received' (when custom event fires), 'inactivity' (when subscriber hasn't performed an event for X days), 'frequency' (when subscriber performs event X times in Y days)"},listId:{type:"string",description:"List ID to trigger on (for contact_added trigger). If not provided, triggers on any list."},tagName:{type:"string",description:"Tag name to trigger on (required for tag_added trigger)"},segmentId:{type:"string",description:"Segment ID to trigger on (required for segment_entered trigger). Use list_segments first to choose a saved segment."},eventName:{type:"string",description:"Event name to trigger on (required for event_received, inactivity, and frequency triggers)"},inactiveDays:{type:"number",description:"Number of days of inactivity (required for inactivity trigger, must be >= 1)"},minCount:{type:"number",description:"Minimum event count (required for frequency trigger, must be >= 1)"},timeWindowDays:{type:"number",description:"Time window in days for frequency trigger (required for frequency trigger, must be >= 1)"},emailCount:{type:"number",description:"Number of emails in the sequence (default: 5, max: 10)"},goal:{type:"string",description:"What this sequence should accomplish for AI generation. Be specific to the app's actual features and user journey. Avoid generic goals that don't match the app's business model."},enrollmentMode:{type:"string",enum:["unlimited","one_time","matching_field"],description:"Sequence re-entry mode. Use 'matching_field' only for event_received triggers when duplicate active runs should be blocked per event field value."},enrollmentFieldPath:{type:"string",description:"Dot-path event property used by enrollmentMode='matching_field', such as 'order.id' or 'product.providerVariantId'. Leave omitted for Shopify back-in-stock/replenishment product-variant defaults."},stopCondition:{type:"object",description:"Optional explicit auto-stop condition. Use { type: 'has_tag', value: 'customer' } to end the sequence when a subscriber gets a tag, { type: 'does_not_have_tag', value: 'trial' } when a tag is removed, { type: 'removed_from_list', value: 'list_123' } when they leave a list, { type: 'event_received', value: 'onboarding.completed' } when an event is tracked, or { type: 'none', value: null } for no auto-stop.",properties:{type:{type:"string",enum:["none","has_tag","does_not_have_tag","added_to_list","removed_from_list","event_received"],description:"Stop condition type."},value:{type:["string","null"],description:"Tag name, list ID, or event name for the stop condition. Use null or omit for type 'none'."}},required:["type"]},steps:{type:"array",description:"Explicit sequence steps. Omit type for email steps, or use type: 'create_discount' for a Stripe discount action. Later email steps can reference the most recent discount with {{discount.code}}, {{discount.percentOff}}, {{discount.amountOff}}, and {{discount.expiresAt}}.",items:{type:"object",properties:{type:{type:"string",enum:["email","create_discount","discount"],description:"Step type. Omit or use 'email' for email content. Use 'create_discount' to generate a discount code before later emails."},subject:{type:"string",description:"Email subject. Required for email steps."},previewText:{type:"string",description:"Email preview text."},blocks:{type:"array",description:"Sequenzy email blocks. Provide blocks or html for email steps. Blocks can include repeat blocks over array variables such as items.",items:{type:"object"}},html:{type:"string",description:"HTML content for email steps. Will be converted to Sequenzy blocks."},delay:{type:"object",description:"Delay before this step.",properties:{days:{type:"number"},hours:{type:"number"},minutes:{type:"number"}}},name:{type:"string",description:"Email template name for email steps."},discount:{type:"object",description:"Discount configuration for create_discount steps. Prefer this nested shape for new integrations; legacy top-level discount fields are still accepted.",properties:{label:{type:"string",description:"Builder label for the discount step."},provider:{type:"string",enum:["stripe"],description:"Discount provider. Currently only 'stripe'."},discountType:{type:"string",enum:["percent","amount"],description:"Discount type."},percentOff:{type:"number",description:"Percent discount from 1 to 100. Required when discountType is percent."},amountOff:{type:"number",description:"Fixed amount discount in the smallest currency unit, for example 500 for $5. Required when discountType is amount."},currency:{type:"string",description:"ISO currency for amount discounts. Defaults to usd."},duration:{type:"string",enum:["once","forever","repeating"],description:"Stripe coupon duration. Defaults to once."},durationInMonths:{type:"number",description:"Required for repeating discounts."},appliesToAllPlans:{type:"boolean",description:"Whether the discount applies to all plans. Defaults to true."},planIds:{type:"array",description:"Stripe product IDs, such as prod_abc123, when appliesToAllPlans is false.",items:{type:"string"}},codePrefix:{type:"string",description:"Optional prefix for generated promotion codes."},maxRedemptions:{type:"number",description:"Maximum promotion code redemptions. Use 1 for subscriber-specific codes."},lockToSubscriber:{type:"boolean",description:"Stripe-only. Restrict each generated promotion code to the matched subscriber's Stripe customer."},expiresAt:{type:"string",description:"Optional future expiration date or ISO timestamp."},expiresInHours:{type:"number",description:"Optional relative expiration in hours, resolved when each subscriber's code is created (e.g., 48 for a 48-hour window per subscriber). Takes precedence over expiresAt."},name:{type:"string",description:"Optional provider coupon name."}}},label:{type:"string",description:"Legacy top-level discount label. Prefer discount.label."},provider:{type:"string",enum:["stripe"],description:"Legacy top-level discount provider. Prefer discount.provider."},discountType:{type:"string",enum:["percent","amount"],description:"Legacy top-level discount type. Prefer discount.discountType."},percentOff:{type:"number",description:"Percent discount from 1 to 100. Required when discountType is percent."},amountOff:{type:"number",description:"Fixed amount discount in the smallest currency unit, for example 500 for $5. Required when discountType is amount."},currency:{type:"string",description:"ISO currency for amount discounts. Defaults to usd."},duration:{type:"string",enum:["once","forever","repeating"],description:"Stripe coupon duration. Defaults to once."},durationInMonths:{type:"number",description:"Required for repeating discounts."},appliesToAllPlans:{type:"boolean",description:"Whether the discount applies to all plans. Defaults to true."},planIds:{type:"array",description:"Stripe product IDs, such as prod_abc123, when appliesToAllPlans is false.",items:{type:"string"}},codePrefix:{type:"string",description:"Optional prefix for generated promotion codes."},maxRedemptions:{type:"number",description:"Maximum promotion code redemptions. Use 1 for subscriber-specific codes."},lockToSubscriber:{type:"boolean",description:"Legacy top-level Stripe-only flag. Prefer discount.lockToSubscriber."},expiresAt:{type:"string",description:"Optional future expiration date or ISO timestamp."},expiresInHours:{type:"number",description:"Optional relative expiration in hours, resolved when each subscriber's code is created (e.g., 48 for a 48-hour window per subscriber). Takes precedence over expiresAt."}}}}},required:["name","trigger"]}},{name:"update_sequence",description:"Update an existing sequence. To target a specific step, use the emailId or nodeId returned in get_sequence.sequence.emails. You can also update enrollmentMode and enrollmentFieldPath for event-triggered matching-field enrollment. When inserting an if/else branch, include steps for every branch arm and elseSteps so the branch is usable immediately. Branch conditions support tags, lists, saved segments, custom events, clicked links, and subscriber field comparisons.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"},name:{type:"string",description:"Sequence name"},enrollmentMode:{type:"string",enum:["unlimited","one_time","matching_field"],description:"Updated sequence re-entry mode. 'matching_field' is only valid for event-based sequence triggers."},enrollmentFieldPath:{type:"string",description:"Dot-path event property used by enrollmentMode='matching_field', such as 'order.id' or 'product.providerVariantId'. Omit to leave unchanged. Use clearEnrollmentFieldPath to clear it."},clearEnrollmentFieldPath:{type:"boolean",description:"Set true to clear enrollmentFieldPath without sending a nullable schema value."},stopCondition:{type:"object",description:"Update the sequence auto-stop condition. Example: { type: 'has_tag', value: 'customer' } ends the sequence when the subscriber has that tag. Use { type: 'removed_from_list', value: 'list_123' } to stop when they leave a list, or { type: 'none', value: null } to clear it.",properties:{type:{type:"string",enum:["none","has_tag","does_not_have_tag","added_to_list","removed_from_list","event_received"]},value:{type:["string","null"],description:"Tag name, list ID, or event name for the stop condition."}},required:["type"]},branch:{type:"object",description:"Insert an if/else branch into an existing sequence. The branch is inserted after afterNodeId and creates an if path plus an else fallback path. Use get_sequence first to choose afterNodeId. Each branch condition should include steps, and elseSteps is required unless allowEmptyPaths is true. Conditions support tags, lists, saved segments, events, clicked links, and field comparisons. Use activityScope for event_received and link_clicked checks.",properties:{afterNodeId:{type:"string",description:"Existing node ID to insert the branch after. Use a nodeId from get_sequence.sequence.nodes or get_sequence.sequence.emails."},label:{type:"string",description:"Optional branch node label."},branches:{type:"array",description:"Conditional branches evaluated in order. An else fallback is created automatically.",items:{type:"object",properties:{id:{type:"string",description:"Optional stable branch ID. Defaults to branch-0, branch-1, etc."},label:{type:"string",description:"Display label, e.g. 'If has customer tag'."},conditionType:{type:"string",enum:["has_tag","in_list","in_segment","event_received","link_clicked","field_equals","field_contains","field_greater_than","field_less_than"],description:"Condition type for this branch."},tagName:{type:"string",description:"Tag name for has_tag conditions. This can be used instead of tagId."},tagId:{type:"string",description:"Tag ID or tag name for has_tag conditions."},listId:{type:"string",description:"List ID for in_list conditions."},segmentId:{type:"string",description:"Segment ID for in_segment conditions."},segmentName:{type:"string",description:"Optional display name for in_segment conditions."},eventName:{type:"string",description:"Event name for event_received conditions, such as project.invite.accepted."},linkUrl:{type:"string",description:"Optional URL substring for link_clicked conditions. Omit to match any clicked link."},activityScope:{type:"string",enum:["ever","this_sequence","previous_email"],description:"Scope for event_received and link_clicked conditions. Omit to check ever."},fieldName:{type:"string",description:"Subscriber attribute name for field conditions."},fieldValue:{type:"string",description:"Comparison value for field conditions."},steps:{type:"array",description:"Steps to create inside this branch path. Required by default so the branch is not an empty placeholder.",items:B5}},required:["conditionType"]}},elseSteps:{type:"array",description:"Steps to create inside the else fallback path. Required by default so the else arm is usable.",items:B5},allowEmptyPaths:{type:"boolean",description:"Set true only when intentionally creating empty UI placeholders. Normal API/MCP use should omit this and provide branch steps plus elseSteps."}},required:["afterNodeId","branches"]},emails:{type:"array",description:"Updated sequence emails. If you omit emailId/nodeId, items are matched by existing step order.",items:{type:"object",properties:{emailId:{type:"string",description:"Optional target linked email template ID for a step. Use the emailId returned in get_sequence.sequence.emails."},nodeId:{type:"string",description:"Optional target action_email node ID for a step. Use the nodeId returned in get_sequence.sequence.emails."},name:{type:"string",description:"Updated step/template name"},subject:{type:"string",description:"Updated email subject"},previewText:{type:"string",description:"Updated preview text"},html:{type:"string",description:"Updated HTML content. Will be converted to Sequenzy blocks."},htmlContent:{type:"string",description:"Alias for html. Use this when updating HTML content for a step."},blocks:{type:"array",description:"Updated Sequenzy block JSON for the step",items:{type:"object"}}}}},steps:{type:"array",description:"Alias for emails. Supports the same fields and matching rules.",items:{type:"object",properties:{emailId:{type:"string",description:"Optional target linked email template ID for a step. Use the emailId returned in get_sequence.sequence.emails."},nodeId:{type:"string",description:"Optional target action_email node ID for a step. Use the nodeId returned in get_sequence.sequence.emails."},name:{type:"string",description:"Updated step/template name"},subject:{type:"string",description:"Updated email subject"},previewText:{type:"string",description:"Updated preview text"},html:{type:"string",description:"Updated HTML content. Will be converted to Sequenzy blocks."},htmlContent:{type:"string",description:"Alias for html. Use this when updating HTML content for a step."},blocks:{type:"array",description:"Updated Sequenzy block JSON for the step",items:{type:"object"}}}}}},required:["sequenceId"]}},{name:"enable_sequence",description:"Enable/activate a sequence. IMPORTANT: Only call this when the user EXPLICITLY asks to enable or activate a sequence. Never enable sequences automatically after creation - the user must review the content first.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"disable_sequence",description:"Disable/pause a sequence",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"cancel_sequence_enrollments",description:"Cancel active/waiting enrollments in one sequence. Provide sequenceId and exactly one target: subscriberId for one subscriber, or fieldValues to match stored entry event properties. For fieldValues, fieldPath is optional when the sequence has enrollmentFieldPath configured; otherwise provide a dot path such as order.id.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID whose enrollments should be cancelled."},subscriberId:{type:"string",description:"Subscriber ID to cancel in this sequence. Provide subscriberId or fieldValues, not both."},fieldPath:{type:"string",description:"Dot-path inside the token's stored entry event properties, such as order.id or event.id. Optional when the sequence has enrollmentFieldPath configured."},fieldValues:{type:"array",items:{type:"string"},description:"Entry field values to match. Cancels all active/waiting enrollments in the sequence whose entry field value is in this list. Provide fieldValues or subscriberId, not both."},dryRun:{type:"boolean",description:"When true, returns matching enrollments without cancelling them. Field-value cancellation defaults to dryRun on the API unless explicitly false."},reason:{type:"string",description:"Optional cancellation reason stored on matched enrollment tokens."}},required:["sequenceId"],additionalProperties:!1}},{name:"delete_sequence",description:"Delete a sequence",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"list_transactional_emails",description:"List transactional email templates, including their API slugs and linked email IDs",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."}}}},{name:"get_transactional_email",description:"Get a transactional email by ID or slug, including subject, preview text, blocks, variables, and linked dashboard URLs",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},idOrSlug:{type:"string",description:"Transactional email ID or API slug, for example `welcome-email`."}},required:["idOrSlug"]}},{name:"create_transactional_email",description:"Create a saved transactional email template with an API slug. Provide `prompt` to generate the email with AI, or provide either `html` or Sequenzy `blocks` for the email body.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},name:{type:"string",description:"Transactional email name."},slug:{type:"string",description:"Optional API slug used when sending by slug, for example `password-reset`. If omitted, Sequenzy generates one from the name."},subject:{type:"string",description:"Email subject line. Optional when `prompt` is provided because the generated subject will be used."},previewText:{type:["string","null"],description:"Email preview text."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }. Mutually exclusive with `html`.",items:{type:"object"}},prompt:{type:"string",description:"Generate transactional email blocks from a prompt. Mutually exclusive with `html` and `blocks`."},style:{type:"string",description:"Prompt generation style: minimal, branded, promotional. Only used with `prompt`."},tone:{type:"string",description:"Prompt generation tone: professional, casual, friendly. Only used with `prompt`."},enabled:{type:"boolean",description:"Whether this transactional email can be sent immediately. Defaults to true."}},required:["name"],additionalProperties:!1}},{name:"update_transactional_email",description:"Update a transactional email by ID or slug. At least one of `name`, `enabled`, `subject`, `previewText`, `html`, or `blocks` is required. Use `html` or `blocks` to replace the linked email body.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},idOrSlug:{type:"string",description:"Transactional email ID or API slug, for example `welcome-email`."},name:{type:"string",description:"Transactional email name."},enabled:{type:"boolean",description:"Whether this transactional email can be sent."},subject:{type:"string",description:"Email subject line."},previewText:{type:["string","null"],description:"Email preview text."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks, including conditional and repeat blocks. Mutually exclusive with `html`.",items:{type:"object"}}},required:["idOrSlug"],additionalProperties:!1}},{name:"send_email",description:"Send a transactional email to a single recipient",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},to:{type:"string",description:"Recipient email address"},subject:{type:"string",description:"Email subject (required if not using templateId)"},html:{type:"string",description:"Email HTML content (required if not using templateId)"},templateId:{type:"string",description:"Template ID to use (alternative to html)"},variables:{type:"object",description:"Variables for template personalization. Nested objects and arrays are supported for repeat blocks, for example { items: [...] }."},subscriberExternalId:{type:"string",description:"Customer-owned subscriber ID for attaching analytics/localization on single-recipient sends."}},required:["to"]}},{name:"get_stats",description:"Get overview statistics for a time period",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},period:{type:"string",description:"Time period: 7d, 30d, or 90d (default: 7d)"}}}},{name:"get_campaign_stats",description:"Get detailed statistics for a campaign",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"}},required:["campaignId"]}},{name:"get_sequence_stats",description:"Get statistics for a sequence, including per-step failed subscribers and failure reasons",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"get_subscriber_activity",description:"Get recent activity, email stats, and current sequence enrollments for a subscriber",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."}},required:[]}},{name:"generate_email",description:"Generate email blocks from a prompt",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},prompt:{type:"string",description:"Description of the email to generate"},style:{type:"string",description:"Style: minimal, branded, promotional"},tone:{type:"string",description:"Tone: professional, casual, friendly"}},required:["prompt"]}},{name:"generate_sequence",description:"[DEPRECATED - Use create_sequence instead] Generate a multi-email sequence from a goal. Note: create_sequence now handles AI generation automatically.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},goal:{type:"string",description:"Goal of the sequence (e.g., 'onboard new SaaS trial users')"},emailCount:{type:"number",description:"Number of emails in the sequence (default: 5, max: 10)"},durationDays:{type:"number",description:"Total duration in days (default: 14)"}},required:["goal"]}},{name:"generate_subject_lines",description:"Generate A/B test subject line variants",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},topic:{type:"string",description:"Topic or context for the subject lines"},count:{type:"number",description:"Number of variants to generate (default: 5)"}},required:["topic"]}}];async function V5(Q,X){try{let Y;switch(Q){case"get_account":{let G=await Z("GET","/api/v1/account"),$=m1();Y={...G,selectedCompanyId:$??G.currentCompanyId};break}case"select_company":{let G=X.companyId,$=await Z("GET","/api/v1/account"),J=$.companies?.find((z)=>z.id===G);if(!J)throw Error(`Company not found. Available companies: ${$.companies?.map((z)=>`${z.name} (${z.id})`).join(", ")??"none"}`);RX(G),Y={success:!0,message:`Switched to company: ${J.name}`,companyId:J.id,companyName:J.name};break}case"get_app_urls":{let G=await F5(X);Y={...K1({companyId:G,campaignId:j(X,"campaignId"),sequenceId:j(X,"sequenceId"),emailId:j(X,"emailId")??j(X,"templateId"),transactionalId:j(X,"transactionalId"),emailSendId:j(X,"emailSendId"),domainId:j(X,"domainId"),status:j(X,"status"),settingsTab:j(X,"settingsTab")}),...G===void 0&&{note:"No company ID is selected. Call get_account, select_company, or pass companyId to get concrete dashboard URLs."}};break}case"create_company":{let G=await Z("POST","/api/v1/companies",{name:X.name,domain:X.domain});if(!G.success)throw Error("Failed to create company");let $=G.company.id,J=6,z=0,H=G.company.status;while(H==="processing"&&z<J){await new Promise((K)=>setTimeout(K,20000)),z++;let A=await Z("GET",`/api/v1/companies/${$}`);if(A.success)H=A.company.status}RX($);let U=await Z("GET",`/api/v1/companies/${$}`);Y={success:!0,company:U.company,message:H==="processing"?"Company created but still processing. You can continue using it while processing completes.":`Company '${U.company.name}' created and ready to use.`,autoSelected:!0};break}case"get_company":{let G=X.companyId;Y=await Z("GET",`/api/v1/companies/${G}`);break}case"create_api_key":{let G=X.companyId;Y=await Z("POST","/api/v1/api-keys",{name:X.name},G);break}case"list_websites":{let G=X.companyId;Y=await Z("GET","/api/v1/websites",void 0,G);break}case"add_website":{let G=X.companyId;Y=await Z("POST","/api/v1/websites",{domain:X.domain},G);break}case"check_website":{let G=X.companyId;Y=await Z("GET",`/api/v1/websites/${X.domain}`,void 0,G);break}case"get_integration_guide":Y=await Z("POST","/api/v1/integration-guide",X);break;case"add_subscriber":{let G=X.companyId,$=u4("add_subscriber",X);Y=await Z("POST","/api/v1/subscribers",{...$,customAttributes:X.attributes,tags:X.tags,lists:X.listIds,...X.status!==void 0&&{status:X.status},...X.optInMode!==void 0&&{optInMode:X.optInMode}},G);break}case"update_subscriber":{let G=X.companyId,$=u4("update_subscriber",X),J=await TX($,G),z=Array.isArray(J.subscriber.tags)?J.subscriber.tags.filter((B)=>typeof B==="string"):[],H=Array.isArray(X.addTags)?X.addTags.filter((B)=>typeof B==="string"&&B.trim()!=="").map(D5):[],U=new Set(Array.isArray(X.removeTags)?X.removeTags.filter((B)=>typeof B==="string"&&B.trim()!=="").map(D5):[]),A=z.filter((B)=>!U.has(B));for(let B of H)if(!A.includes(B))A.push(B);let K={};if($.email&&$.externalId)K.externalId=$.externalId;if(D0(X.attributes))K.customAttributes={...D0(J.subscriber.customAttributes)?J.subscriber.customAttributes:{},...X.attributes};if(X.addTags||X.removeTags)K.tags=A;Y=await Z("PATCH",SX($),K,G);break}case"remove_subscriber":{let G=X.companyId,$=u4("remove_subscriber",X),J=SX($);if(X.hardDelete===!0)Y=await Z("DELETE",J,void 0,G);else Y=await Z("PATCH",J,{status:"unsubscribed"},G);break}case"get_subscriber":{let G=X.companyId,$=u4("get_subscriber",X);Y=await TX($,G);break}case"search_subscribers":{let G=X.companyId;Y=await OM(X,G);break}case"list_tags":{let G=X.companyId;Y=await Z("GET","/api/v1/tags",void 0,G);break}case"list_lists":{let G=X.companyId;Y=await Z("GET","/api/v1/lists",void 0,G);break}case"create_list":{let G=X.companyId;Y=await Z("POST","/api/v1/lists",X,G);break}case"list_segments":{let G=X.companyId;Y=await Z("GET","/api/v1/segments",void 0,G);break}case"create_segment":{UM(X);let G=X.companyId;Y=await Z("POST","/api/v1/segments",{...X,...X.filters!==void 0?{filters:L5(X.filters)}:{},...X.root!==void 0?{root:q5(X.root)}:{}},G);break}case"get_segment_count":{let G=X.companyId;Y=await Z("GET",`/api/v1/segments/${X.segmentId}/count`,void 0,G);break}case"list_templates":{let G=X.companyId,$=new URLSearchParams,J=j(X,"label");if(J)$.set("label",J);Y=await Z("GET",`/api/v1/templates${$.size>0?`?${$}`:""}`,void 0,G);break}case"get_template":{let G=X.companyId;Y=await Z("GET",`/api/v1/templates/${X.templateId}`,void 0,G);break}case"create_template":{let G=X.companyId;N1("create_template",X,{requireContent:!0}),HQ("create_template",X),Y=await Z("POST","/api/v1/templates",X,G);break}case"update_template":{let G=X.companyId,$=new Set(["companyId","templateId","name","subject","html","blocks","labels"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_template\` accepts only \`name\`, \`subject\`, \`html\`, \`blocks\`, and \`labels\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_template",X),HQ("update_template",X),X.name===void 0&&X.subject===void 0&&X.html===void 0&&X.blocks===void 0&&X.labels===void 0)throw Error("Provide at least one of `name`, `subject`, `html`, `blocks`, or `labels` when calling `update_template`.");Y=await Z("PUT",`/api/v1/templates/${X.templateId}`,X,G);break}case"delete_template":{let G=X.companyId;Y=await Z("DELETE",`/api/v1/templates/${X.templateId}`,void 0,G);break}case"list_ab_tests":{let G=X.companyId,$=new URLSearchParams,J=j(X,"sequenceId");if(J)$.set("sequenceId",J);Y=await Z("GET",`/api/v1/ab-tests${$.size>0?`?${$}`:""}`,void 0,G);break}case"get_ab_test":{let G=X.companyId;Y=await Z("GET",`/api/v1/ab-tests/${X.abTestId}`,void 0,G);break}case"get_ab_test_stats":{let G=X.companyId,$=new URLSearchParams,J=j(X,"period"),z=j(X,"start"),H=j(X,"end");if(J)$.set("period",J);if(z)$.set("start",z);if(H)$.set("end",H);Y=await Z("GET",`/api/v1/ab-tests/${X.abTestId}/stats${$.size>0?`?${$}`:""}`,void 0,G);break}case"update_ab_test_variant":{let G=X.companyId,$=new Set(["companyId","abTestId","variantId","subject","previewText","html","blocks"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_ab_test_variant\` accepts only \`subject\`, \`previewText\`, \`html\`, and \`blocks\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_ab_test_variant",X),X.subject===void 0&&X.previewText===void 0&&X.html===void 0&&X.blocks===void 0)throw Error("Provide at least one of `subject`, `previewText`, `html`, or `blocks` when calling `update_ab_test_variant`.");Y=await Z("PATCH",`/api/v1/ab-tests/${X.abTestId}/variants/${X.variantId}`,X,G);break}case"list_campaigns":{let G=X.companyId,$=new URLSearchParams;if(X.status)$.set("status",String(X.status));let J=j(X,"label");if(J)$.set("label",J);Y=await Z("GET",`/api/v1/campaigns?${$}`,void 0,G);break}case"get_campaign":{let G=X.companyId;Y=await Z("GET",`/api/v1/campaigns/${X.campaignId}`,void 0,G);break}case"get_email_send":{let G=X.companyId;Y=await Z("GET",`/api/v1/email-sends/${encodeURIComponent(String(X.emailSendId))}`,void 0,G);break}case"create_campaign":{let G=X.companyId;BM(X);let $=j(X,"prompt");if($!==void 0){let J=await Z("POST","/api/v1/generate/email",{prompt:$,...X.style!==void 0&&{style:X.style},...X.tone!==void 0&&{tone:X.tone}},G),z=j(X,"subject")??(typeof J.subject==="string"&&J.subject.trim()!==""?J.subject.trim():void 0);if(!z)throw Error("`create_campaign` prompt generation did not return a subject. Provide `subject` explicitly.");let H=Array.isArray(J.blocks)&&J.blocks.length>0?J.blocks:void 0,U=typeof J.html==="string"&&J.html.trim()!==""?J.html:void 0;if(H===void 0&&U===void 0)throw Error("`create_campaign` prompt generation did not return email blocks. Try again or provide `html` or `blocks` explicitly.");Y=await Z("POST","/api/v1/campaigns",{name:X.name,subject:z,...H!==void 0?{blocks:H}:{html:U},...X.segmentId!==void 0&&{segmentId:X.segmentId},...X.trackingCode!==void 0&&{trackingCode:X.trackingCode},...X.campaignData!==void 0&&{campaignData:X.campaignData},...X.computedLists!==void 0&&{computedLists:X.computedLists},...X.labels!==void 0&&{labels:X.labels}},G);break}Y=await Z("POST","/api/v1/campaigns",X,G);break}case"update_campaign":{let G=X.companyId,$=new Set(["companyId","campaignId","name","subject","trackingCode","html","blocks","replyTo","replyProfileId","campaignData","computedLists","labels"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_campaign\` accepts only \`name\`, \`subject\`, \`trackingCode\`, \`html\`, \`blocks\`, \`replyTo\`, \`replyProfileId\`, \`campaignData\`, \`computedLists\`, and \`labels\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_campaign",X),HQ("update_campaign",X),X.replyTo!==void 0&&X.replyProfileId!==void 0)throw Error("Provide either `replyTo` or `replyProfileId` when calling `update_campaign`, not both.");if(X.name===void 0&&X.subject===void 0&&X.trackingCode===void 0&&X.html===void 0&&X.blocks===void 0&&X.replyTo===void 0&&X.replyProfileId===void 0&&X.campaignData===void 0&&X.computedLists===void 0&&X.labels===void 0)throw Error("Provide at least one of `name`, `subject`, `trackingCode`, `html`, `blocks`, `replyTo`, `replyProfileId`, `campaignData`, `computedLists`, or `labels` when calling `update_campaign`.");Y=await Z("PUT",`/api/v1/campaigns/${X.campaignId}`,X,G);break}case"schedule_campaign":{let G=X.companyId,$=new Set(["companyId","campaignId","scheduledAt","targetLists","sendTimeOptimization","spreadOverHours"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`schedule_campaign\` accepts only \`campaignId\`, \`scheduledAt\`, \`targetLists\`, \`sendTimeOptimization\`, and \`spreadOverHours\`. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);DM(X),Y=await Z("POST",`/api/v1/campaigns/${X.campaignId}/schedule`,{scheduledAt:X.scheduledAt,...X.targetLists!==void 0&&{targetLists:X.targetLists},...X.sendTimeOptimization!==void 0&&{sendTimeOptimization:X.sendTimeOptimization},...X.spreadOverHours!==void 0&&{spreadOverHours:X.spreadOverHours}},G);break}case"send_test_email":{let G=X.companyId;Y=await Z("POST",`/api/v1/campaigns/${X.campaignId}/test`,{to:X.to},G);break}case"list_sequences":{let G=X.companyId;Y=await Z("GET","/api/v1/sequences",void 0,G);break}case"get_sequence":{let G=X.companyId;Y=await Z("GET",`/api/v1/sequences/${X.sequenceId}`,void 0,G);break}case"create_sequence":{let G=X.companyId,$=Array.isArray(X.steps)&&X.steps.length>0,J=await Z("POST","/api/v1/sequences",X,G);if(!J.success){Y=J;break}let z=J.sequence.id;if($){let B=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(B.success)Y={success:!0,sequence:B.sequence,message:`Sequence "${B.sequence.name}" created with explicit steps. Review it before enabling.`};else Y=B;break}let H=6,U=0,A="pending";while(A!=="complete"&&U<H){await new Promise((L)=>setTimeout(L,20000)),U++;let B=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(B.success)A=B.sequence.enrichmentStatus}let K=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(K.success)Y={success:!0,sequence:K.sequence,message:K.sequence.enrichmentStatus==="complete"?`Sequence "${K.sequence.name}" created with ${K.sequence.emailCount} AI-generated emails. The sequence is ready to review and enable.`:`Sequence "${K.sequence.name}" created. Email enrichment is still in progress (${K.sequence.enrichedCount}/${K.sequence.emailCount} emails generated). You can check status with get_sequence.`};else Y=K;break}case"update_sequence":{let G=X.companyId,$=AM(X);Y=await Z("PUT",`/api/v1/sequences/${X.sequenceId}`,$,G);break}case"enable_sequence":{let G=X.companyId;Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/enable`,void 0,G);break}case"disable_sequence":{let G=X.companyId;Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/disable`,void 0,G);break}case"cancel_sequence_enrollments":{let G=X.companyId,$=KM(X);Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/enrollments/cancel`,$,G);break}case"delete_sequence":{let G=X.companyId;Y=await Z("DELETE",`/api/v1/sequences/${X.sequenceId}`,void 0,G);break}case"list_transactional_emails":{let G=X.companyId;Y=await Z("GET","/api/v1/transactional",void 0,G);break}case"get_transactional_email":{let G=X.companyId;Y=await Z("GET",`/api/v1/transactional/${X.idOrSlug}`,void 0,G);break}case"create_transactional_email":{let G=X.companyId,$=new Set(["companyId","name","slug","subject","previewText","html","blocks","prompt","style","tone","enabled"]),J=Object.keys(X).filter((U)=>!$.has(U));if(J.length>0)throw Error(`\`create_transactional_email\` accepts only \`name\`, \`slug\`, \`subject\`, \`previewText\`, \`html\`, \`blocks\`, \`prompt\`, \`style\`, \`tone\`, and \`enabled\` fields. Unsupported field${J.length===1?"":"s"}: ${J.map((U)=>`\`${U}\``).join(", ")}.`);LM(X);let z=j(X,"prompt");if(z!==void 0){let U={companyId:G??m1()??"",name:typeof X.name==="string"&&X.name.trim()!==""?X.name.trim():"",slug:typeof X.slug==="string"&&X.slug.trim()!==""?X.slug.trim():"",promptLength:z.length,style:typeof X.style==="string"?X.style:"",tone:typeof X.tone==="string"?X.tone:""};try{console.error("[mcp:create_transactional_email] generating from prompt",U);let A=await Z("POST","/api/v1/generate/email",{prompt:z,...X.style!==void 0&&{style:X.style},...X.tone!==void 0&&{tone:X.tone}},G);console.error("[mcp:create_transactional_email] prompt generation complete",{...U,subject:A.subject??"",previewTextLength:typeof A.previewText==="string"?A.previewText.length:0,blockCount:Array.isArray(A.blocks)?A.blocks.length:0,htmlLength:typeof A.html==="string"?A.html.length:0});let K=j(X,"subject")??(typeof A.subject==="string"&&A.subject.trim()!==""?A.subject.trim():void 0);if(!K)throw Error("`create_transactional_email` prompt generation did not return a subject. Provide `subject` explicitly.");let B=Array.isArray(A.blocks)&&A.blocks.length>0?A.blocks:void 0,L=typeof A.html==="string"&&A.html.trim()!==""?A.html:void 0,F=j(X,"previewText")??(typeof A.previewText==="string"?A.previewText.trim():void 0);if(B===void 0&&L===void 0)throw Error("`create_transactional_email` prompt generation did not return email blocks. Try again or provide `html` or `blocks` explicitly.");console.error("[mcp:create_transactional_email] creating generated transactional",{...U,subject:K,contentSource:B!==void 0?"blocks":"html",blockCount:B?.length??0,htmlLength:L?.length??0}),Y=await Z("POST","/api/v1/transactional",{name:X.name,...X.slug!==void 0&&{slug:X.slug},subject:K,...F!==void 0&&{previewText:F},...B!==void 0?{blocks:B}:{html:L},...X.enabled!==void 0&&{enabled:X.enabled}},G),console.error("[mcp:create_transactional_email] generated transactional created",U)}catch(A){throw console.error("[mcp:create_transactional_email] prompt-based create failed",{...U,error:A instanceof Error?A.message:String(A)}),A}break}let H=Object.fromEntries(Object.entries(X).filter(([U])=>U!=="companyId"));Y=await Z("POST","/api/v1/transactional",H,G);break}case"update_transactional_email":{let G=X.companyId,$=new Set(["companyId","idOrSlug","name","enabled","subject","previewText","html","blocks"]),J=Object.keys(X).filter((H)=>!$.has(H));if(J.length>0)throw Error(`\`update_transactional_email\` accepts only \`name\`, \`enabled\`, \`subject\`, \`previewText\`, \`html\`, and \`blocks\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((H)=>`\`${H}\``).join(", ")}.`);if(N1("update_transactional_email",X),X.name===void 0&&X.enabled===void 0&&X.subject===void 0&&X.previewText===void 0&&X.html===void 0&&X.blocks===void 0)throw Error("Provide at least one of `name`, `enabled`, `subject`, `previewText`, `html`, or `blocks` when calling `update_transactional_email`.");let z=Object.fromEntries(Object.entries(X).filter(([H])=>H!=="companyId"&&H!=="idOrSlug"));Y=await Z("PATCH",`/api/v1/transactional/${X.idOrSlug}`,z,G);break}case"send_email":{let G=X.companyId;Y=await Z("POST","/api/v1/transactional/send",X,G);break}case"get_stats":{let G=X.companyId,$=X.period??"7d";Y=await Z("GET",`/api/v1/metrics?period=${$}`,void 0,G);break}case"get_campaign_stats":{let G=X.companyId;Y=await Z("GET",`/api/v1/metrics/campaigns/${X.campaignId}`,void 0,G);break}case"get_sequence_stats":{let G=X.companyId;Y=await Z("GET",`/api/v1/metrics/sequences/${X.sequenceId}`,void 0,G);break}case"get_subscriber_activity":{let G=X.companyId,$=u4("get_subscriber_activity",X),J=await TX($,G);Y={success:J.success,email:J.subscriber.email,emailStats:J.subscriber.emailStats??null,activity:J.subscriber.activity??[],sequenceEnrollments:J.subscriber.sequenceEnrollments??[]};break}case"generate_email":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/email",X,G);break}case"generate_sequence":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/sequence",X,G);break}case"generate_subject_lines":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/subjects",X,G);break}default:throw Error(`Unknown tool: ${Q}`)}let W=qM(Y);if(W)throw W;return Y=await NM(Q,X,Y),{content:[{type:"text",text:JSON.stringify(Y,null,2)}]}}catch(Y){return{isError:!0,content:[{type:"text",text:Z1(Y)}]}}}var wM=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com",Z5=process.env.SEQUENZY_API_KEY,CX=null;if(!Z5)console.error(Z1(new l1("SEQUENZY_API_KEY environment variable is required",401,void 0,"MCP_AUTH_REQUIRED"))),process.exit(1);function m1(){return CX}function RX(Q){CX=Q}var f4=new PX({name:"sequenzy",version:z5.version},{capabilities:{tools:{},resources:{}}});function N0(Q,X){let Y=Q[X];return typeof Y==="string"&&Y.trim()!==""?Y.trim():void 0}function bM(Q){if(Q===void 0)return;if(typeof Q==="string")return Q.trim()||void 0;return JSON.stringify(Q)}function PM(Q){if(!Q.trim())return{message:"Request failed"};try{let X=JSON.parse(Q);if(typeof X==="string")return{message:X};let Y=typeof X.error==="object"&&X.error!==null?X.error:void 0,W=N0(X,"code")??(Y?N0(Y,"code"):void 0),G=(typeof X.error==="string"?X.error:void 0)??(Y?N0(Y,"message"):void 0)??N0(X,"message")??N0(X,"error")??Q,$=N0(X,"howToFix")??N0(X,"resolution"),J={...N0(X,"title")?{title:N0(X,"title")}:{},...N0(X,"description")?{description:N0(X,"description")}:{},...$?{howToFix:$}:{},...N0(X,"docsUrl")?{docsUrl:N0(X,"docsUrl")}:{}},z=bM(X.details);if(Object.keys(J).length>0||z)return{message:G,...W?{code:W}:{},...z?{details:z}:{},...Object.keys(J).length>0?{context:J}:{}};if(typeof X.error==="string")return{message:X.error,...W?{code:W}:{}};if(Y)return{message:G,...W?{code:W}:{}};return{message:G,...W?{code:W}:{}}}catch{return{message:Q}}}async function Z(Q,X,Y,W){let G={"Content-Type":"application/json",Authorization:`Bearer ${Z5}`},$=W??CX;if($)G["x-company-id"]=$;let J;try{J=await fetch(`${wM}${X}`,{method:Q,headers:G,body:Y?JSON.stringify(Y):void 0})}catch(z){throw new l1(z instanceof Error?z.message:"Failed to reach Sequenzy API",0,void 0,"NETWORK_ERROR")}if(!J.ok){let z=await J.text(),H=PM(z);throw new l1(H.message,J.status,H.details??z,H.code,H.context)}return J.json()}f4.setRequestHandler(K9,async()=>{return{tools:M5}});f4.setRequestHandler(B4,async(Q)=>{let{name:X,arguments:Y}=Q.params;return V5(X,Y??{})});f4.setRequestHandler(G9,async()=>{return{resources:A5}});f4.setRequestHandler(J9,async(Q)=>{let{uri:X}=Q.params;return K5(X)});async function jM(){let Q=new IX;await f4.connect(Q),console.error("Sequenzy MCP server running on stdio")}jM().catch((Q)=>{console.error(Z1(Q)),process.exit(1)});export{RX as setSelectedCompanyId,m1 as getSelectedCompanyId,Z as apiRequest};
177
+ - contact.subscribed, contact.unsubscribed`,inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID to create the sequence in. If not provided, uses the currently selected company."},name:{type:"string",description:"Sequence name (e.g., 'User Onboarding', 'Welcome Series')"},trigger:{type:"string",enum:["contact_added","tag_added","segment_entered","event_received","inactivity","frequency"],description:"Trigger type: 'contact_added' (when added to a list), 'tag_added' (when tag is applied), 'segment_entered' (when a contact newly enters a saved segment), 'event_received' (when custom event fires), 'inactivity' (when subscriber hasn't performed an event for X days), 'frequency' (when subscriber performs event X times in Y days)"},listId:{type:"string",description:"List ID to trigger on (for contact_added trigger). If not provided, triggers on any list."},tagName:{type:"string",description:"Tag name to trigger on (required for tag_added trigger)"},segmentId:{type:"string",description:"Segment ID to trigger on (required for segment_entered trigger). Use list_segments first to choose a saved segment."},eventName:{type:"string",description:"Event name to trigger on (required for event_received, inactivity, and frequency triggers)"},inactiveDays:{type:"number",description:"Number of days of inactivity (required for inactivity trigger, must be >= 1)"},minCount:{type:"number",description:"Minimum event count (required for frequency trigger, must be >= 1)"},timeWindowDays:{type:"number",description:"Time window in days for frequency trigger (required for frequency trigger, must be >= 1)"},emailCount:{type:"number",description:"Number of emails in the sequence (default: 5, max: 10)"},goal:{type:"string",description:"What this sequence should accomplish for AI generation. Be specific to the app's actual features and user journey. Avoid generic goals that don't match the app's business model."},enrollmentMode:{type:"string",enum:["unlimited","one_time","matching_field"],description:"Sequence re-entry mode. Use 'matching_field' only for event_received triggers when duplicate active runs should be blocked per event field value."},enrollmentFieldPath:{type:"string",description:"Dot-path event property used by enrollmentMode='matching_field', such as 'order.id' or 'product.providerVariantId'. Leave omitted for Shopify back-in-stock/replenishment product-variant defaults."},stopCondition:{type:"object",description:"Optional explicit auto-stop condition. Use { type: 'has_tag', value: 'customer' } to end the sequence when a subscriber gets a tag, { type: 'does_not_have_tag', value: 'trial' } when a tag is removed, { type: 'removed_from_list', value: 'list_123' } when they leave a list, { type: 'event_received', value: 'onboarding.completed' } when an event is tracked, or { type: 'none', value: null } for no auto-stop.",properties:{type:{type:"string",enum:["none","has_tag","does_not_have_tag","added_to_list","removed_from_list","event_received"],description:"Stop condition type."},value:{type:["string","null"],description:"Tag name, list ID, or event name for the stop condition. Use null or omit for type 'none'."}},required:["type"]},steps:{type:"array",description:"Explicit sequence steps. Omit type for email steps, or use type: 'create_discount' for a Stripe discount action. Later email steps can reference the most recent discount with {{discount.code}}, {{discount.percentOff}}, {{discount.amountOff}}, and {{discount.expiresAt}}.",items:{type:"object",properties:{type:{type:"string",enum:["email","create_discount","discount"],description:"Step type. Omit or use 'email' for email content. Use 'create_discount' to generate a discount code before later emails."},subject:{type:"string",description:"Email subject. Required for email steps."},previewText:{type:"string",description:"Email preview text."},blocks:{type:"array",description:"Sequenzy email blocks. Provide blocks or html for email steps. Blocks can include repeat blocks over array variables such as items.",items:{type:"object"}},html:{type:"string",description:"HTML content for email steps. Will be converted to Sequenzy blocks."},delay:{type:"object",description:"Delay before this step.",properties:{days:{type:"number"},hours:{type:"number"},minutes:{type:"number"}}},name:{type:"string",description:"Email template name for email steps."},discount:{type:"object",description:"Discount configuration for create_discount steps. Prefer this nested shape for new integrations; legacy top-level discount fields are still accepted.",properties:{label:{type:"string",description:"Builder label for the discount step."},provider:{type:"string",enum:["stripe"],description:"Discount provider. Currently only 'stripe'."},discountType:{type:"string",enum:["percent","amount"],description:"Discount type."},percentOff:{type:"number",description:"Percent discount from 1 to 100. Required when discountType is percent."},amountOff:{type:"number",description:"Fixed amount discount in the smallest currency unit, for example 500 for $5. Required when discountType is amount."},currency:{type:"string",description:"ISO currency for amount discounts. Defaults to usd."},duration:{type:"string",enum:["once","forever","repeating"],description:"Stripe coupon duration. Defaults to once."},durationInMonths:{type:"number",description:"Required for repeating discounts."},appliesToAllPlans:{type:"boolean",description:"Whether the discount applies to all plans. Defaults to true."},planIds:{type:"array",description:"Stripe product IDs, such as prod_abc123, when appliesToAllPlans is false.",items:{type:"string"}},codePrefix:{type:"string",description:"Optional prefix for generated promotion codes."},maxRedemptions:{type:"number",description:"Maximum promotion code redemptions. Use 1 for subscriber-specific codes."},lockToSubscriber:{type:"boolean",description:"Stripe-only. Restrict each generated promotion code to the matched subscriber's Stripe customer."},expiresAt:{type:"string",description:"Optional future expiration date or ISO timestamp."},expiresInHours:{type:"number",description:"Optional relative expiration in hours, resolved when each subscriber's code is created (e.g., 48 for a 48-hour window per subscriber). Takes precedence over expiresAt."},name:{type:"string",description:"Optional provider coupon name."}}},label:{type:"string",description:"Legacy top-level discount label. Prefer discount.label."},provider:{type:"string",enum:["stripe"],description:"Legacy top-level discount provider. Prefer discount.provider."},discountType:{type:"string",enum:["percent","amount"],description:"Legacy top-level discount type. Prefer discount.discountType."},percentOff:{type:"number",description:"Percent discount from 1 to 100. Required when discountType is percent."},amountOff:{type:"number",description:"Fixed amount discount in the smallest currency unit, for example 500 for $5. Required when discountType is amount."},currency:{type:"string",description:"ISO currency for amount discounts. Defaults to usd."},duration:{type:"string",enum:["once","forever","repeating"],description:"Stripe coupon duration. Defaults to once."},durationInMonths:{type:"number",description:"Required for repeating discounts."},appliesToAllPlans:{type:"boolean",description:"Whether the discount applies to all plans. Defaults to true."},planIds:{type:"array",description:"Stripe product IDs, such as prod_abc123, when appliesToAllPlans is false.",items:{type:"string"}},codePrefix:{type:"string",description:"Optional prefix for generated promotion codes."},maxRedemptions:{type:"number",description:"Maximum promotion code redemptions. Use 1 for subscriber-specific codes."},lockToSubscriber:{type:"boolean",description:"Legacy top-level Stripe-only flag. Prefer discount.lockToSubscriber."},expiresAt:{type:"string",description:"Optional future expiration date or ISO timestamp."},expiresInHours:{type:"number",description:"Optional relative expiration in hours, resolved when each subscriber's code is created (e.g., 48 for a 48-hour window per subscriber). Takes precedence over expiresAt."}}}}},required:["name","trigger"]}},{name:"update_sequence",description:"Update an existing sequence. To target a specific step, use the emailId or nodeId returned in get_sequence.sequence.emails. You can also update enrollmentMode and enrollmentFieldPath for event-triggered matching-field enrollment. When inserting an if/else branch, include steps for every branch arm and elseSteps so the branch is usable immediately. Branch conditions support tags, lists, saved segments, custom events, clicked links, and subscriber field comparisons.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"},name:{type:"string",description:"Sequence name"},enrollmentMode:{type:"string",enum:["unlimited","one_time","matching_field"],description:"Updated sequence re-entry mode. 'matching_field' is only valid for event-based sequence triggers."},enrollmentFieldPath:{type:"string",description:"Dot-path event property used by enrollmentMode='matching_field', such as 'order.id' or 'product.providerVariantId'. Omit to leave unchanged. Use clearEnrollmentFieldPath to clear it."},clearEnrollmentFieldPath:{type:"boolean",description:"Set true to clear enrollmentFieldPath without sending a nullable schema value."},stopCondition:{type:"object",description:"Update the sequence auto-stop condition. Example: { type: 'has_tag', value: 'customer' } ends the sequence when the subscriber has that tag. Use { type: 'removed_from_list', value: 'list_123' } to stop when they leave a list, or { type: 'none', value: null } to clear it.",properties:{type:{type:"string",enum:["none","has_tag","does_not_have_tag","added_to_list","removed_from_list","event_received"]},value:{type:["string","null"],description:"Tag name, list ID, or event name for the stop condition."}},required:["type"]},branch:{type:"object",description:"Insert an if/else branch into an existing sequence. The branch is inserted after afterNodeId and creates an if path plus an else fallback path. Use get_sequence first to choose afterNodeId. Each branch condition should include steps, and elseSteps is required unless allowEmptyPaths is true. Conditions support tags, lists, saved segments, events, clicked links, and field comparisons. Use activityScope for event_received and link_clicked checks.",properties:{afterNodeId:{type:"string",description:"Existing node ID to insert the branch after. Use a nodeId from get_sequence.sequence.nodes or get_sequence.sequence.emails."},label:{type:"string",description:"Optional branch node label."},branches:{type:"array",description:"Conditional branches evaluated in order. An else fallback is created automatically.",items:{type:"object",properties:{id:{type:"string",description:"Optional stable branch ID. Defaults to branch-0, branch-1, etc."},label:{type:"string",description:"Display label, e.g. 'If has customer tag'."},conditionType:{type:"string",enum:["has_tag","in_list","in_segment","event_received","link_clicked","field_equals","field_contains","field_greater_than","field_less_than"],description:"Condition type for this branch."},tagName:{type:"string",description:"Tag name for has_tag conditions. This can be used instead of tagId."},tagId:{type:"string",description:"Tag ID or tag name for has_tag conditions."},listId:{type:"string",description:"List ID for in_list conditions."},segmentId:{type:"string",description:"Segment ID for in_segment conditions."},segmentName:{type:"string",description:"Optional display name for in_segment conditions."},eventName:{type:"string",description:"Event name for event_received conditions, such as project.invite.accepted."},linkUrl:{type:"string",description:"Optional URL substring for link_clicked conditions. Omit to match any clicked link."},activityScope:{type:"string",enum:["ever","this_sequence","previous_email"],description:"Scope for event_received and link_clicked conditions. Omit to check ever."},fieldName:{type:"string",description:"Subscriber attribute name for field conditions."},fieldValue:{type:"string",description:"Comparison value for field conditions."},steps:{type:"array",description:"Steps to create inside this branch path. Required by default so the branch is not an empty placeholder.",items:B5}},required:["conditionType"]}},elseSteps:{type:"array",description:"Steps to create inside the else fallback path. Required by default so the else arm is usable.",items:B5},allowEmptyPaths:{type:"boolean",description:"Set true only when intentionally creating empty UI placeholders. Normal API/MCP use should omit this and provide branch steps plus elseSteps."}},required:["afterNodeId","branches"]},emails:{type:"array",description:"Updated sequence emails. If you omit emailId/nodeId, items are matched by existing step order.",items:{type:"object",properties:{emailId:{type:"string",description:"Optional target linked email template ID for a step. Use the emailId returned in get_sequence.sequence.emails."},nodeId:{type:"string",description:"Optional target action_email node ID for a step. Use the nodeId returned in get_sequence.sequence.emails."},name:{type:"string",description:"Updated step/template name"},subject:{type:"string",description:"Updated email subject"},previewText:{type:"string",description:"Updated preview text"},html:{type:"string",description:"Updated HTML content. Will be converted to Sequenzy blocks."},htmlContent:{type:"string",description:"Alias for html. Use this when updating HTML content for a step."},blocks:{type:"array",description:"Updated Sequenzy block JSON for the step",items:{type:"object"}}}}},steps:{type:"array",description:"Alias for emails. Supports the same fields and matching rules.",items:{type:"object",properties:{emailId:{type:"string",description:"Optional target linked email template ID for a step. Use the emailId returned in get_sequence.sequence.emails."},nodeId:{type:"string",description:"Optional target action_email node ID for a step. Use the nodeId returned in get_sequence.sequence.emails."},name:{type:"string",description:"Updated step/template name"},subject:{type:"string",description:"Updated email subject"},previewText:{type:"string",description:"Updated preview text"},html:{type:"string",description:"Updated HTML content. Will be converted to Sequenzy blocks."},htmlContent:{type:"string",description:"Alias for html. Use this when updating HTML content for a step."},blocks:{type:"array",description:"Updated Sequenzy block JSON for the step",items:{type:"object"}}}}}},required:["sequenceId"]}},{name:"enable_sequence",description:"Enable/activate a sequence. IMPORTANT: Only call this when the user EXPLICITLY asks to enable or activate a sequence. Never enable sequences automatically after creation - the user must review the content first.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"disable_sequence",description:"Disable/pause a sequence",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"cancel_sequence_enrollments",description:"Cancel active/waiting enrollments in one sequence. Provide sequenceId and exactly one target: subscriberId for one subscriber, or fieldValues to match stored entry event properties. For fieldValues, fieldPath is optional when the sequence has enrollmentFieldPath configured; otherwise provide a dot path such as order.id.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID whose enrollments should be cancelled."},subscriberId:{type:"string",description:"Subscriber ID to cancel in this sequence. Provide subscriberId or fieldValues, not both."},fieldPath:{type:"string",description:"Dot-path inside the token's stored entry event properties, such as order.id or event.id. Optional when the sequence has enrollmentFieldPath configured."},fieldValues:{type:"array",items:{type:"string"},description:"Entry field values to match. Cancels all active/waiting enrollments in the sequence whose entry field value is in this list. Provide fieldValues or subscriberId, not both."},dryRun:{type:"boolean",description:"When true, returns matching enrollments without cancelling them. Field-value cancellation defaults to dryRun on the API unless explicitly false."},reason:{type:"string",description:"Optional cancellation reason stored on matched enrollment tokens."}},required:["sequenceId"],additionalProperties:!1}},{name:"delete_sequence",description:"Delete a sequence",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"list_transactional_emails",description:"List transactional email templates, including their API slugs and linked email IDs",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."}}}},{name:"get_transactional_email",description:"Get a transactional email by ID or slug, including subject, preview text, blocks, variables, and linked dashboard URLs",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},idOrSlug:{type:"string",description:"Transactional email ID or API slug, for example `welcome-email`."}},required:["idOrSlug"]}},{name:"create_transactional_email",description:"Create a saved transactional email template with an API slug. Provide `prompt` to generate the email with AI, or provide either `html` or Sequenzy `blocks` for the email body.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},name:{type:"string",description:"Transactional email name."},slug:{type:"string",description:"Optional API slug used when sending by slug, for example `password-reset`. If omitted, Sequenzy generates one from the name."},subject:{type:"string",description:"Email subject line. Optional when `prompt` is provided because the generated subject will be used."},previewText:{type:["string","null"],description:"Email preview text."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks. Use this for editor-compatible content, including conditional and repeat blocks. Repeat blocks use { type: 'repeat', source: 'items', itemAlias: 'item', children: [...] }. Mutually exclusive with `html`.",items:{type:"object"}},prompt:{type:"string",description:"Generate transactional email blocks from a prompt. Mutually exclusive with `html` and `blocks`."},style:{type:"string",description:"Prompt generation style: minimal, branded, promotional. Only used with `prompt`."},tone:{type:"string",description:"Prompt generation tone: professional, casual, friendly. Only used with `prompt`."},enabled:{type:"boolean",description:"Whether this transactional email can be sent immediately. Defaults to true."}},required:["name"],additionalProperties:!1}},{name:"update_transactional_email",description:"Update a transactional email by ID or slug. At least one of `name`, `enabled`, `subject`, `previewText`, `html`, or `blocks` is required. Use `html` or `blocks` to replace the linked email body.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},idOrSlug:{type:"string",description:"Transactional email ID or API slug, for example `welcome-email`."},name:{type:"string",description:"Transactional email name."},enabled:{type:"boolean",description:"Whether this transactional email can be sent."},subject:{type:"string",description:"Email subject line."},previewText:{type:["string","null"],description:"Email preview text."},html:{type:"string",description:"Email HTML content. Mutually exclusive with `blocks`."},blocks:{type:"array",description:"Sequenzy email blocks, including conditional and repeat blocks. Mutually exclusive with `html`.",items:{type:"object"}}},required:["idOrSlug"],additionalProperties:!1}},{name:"send_email",description:"Send a transactional email to a single recipient",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},to:{type:"string",description:"Recipient email address"},subject:{type:"string",description:"Email subject (required if not using templateId)"},html:{type:"string",description:"Email HTML content (required if not using templateId)"},templateId:{type:"string",description:"Template ID to use (alternative to html)"},variables:{type:"object",description:"Variables for template personalization. Nested objects and arrays are supported for repeat blocks, for example { items: [...] }."},subscriberExternalId:{type:"string",description:"Customer-owned subscriber ID for attaching analytics/localization on single-recipient sends."}},required:["to"]}},{name:"get_stats",description:"Get overview statistics for a time period",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},period:{type:"string",description:"Time period: 7d, 30d, or 90d (default: 7d)"}}}},{name:"get_campaign_stats",description:"Get detailed statistics for a campaign",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},campaignId:{type:"string",description:"Campaign ID"}},required:["campaignId"]}},{name:"get_sequence_stats",description:"Get statistics for a sequence, including per-step failed subscribers and failure reasons",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},sequenceId:{type:"string",description:"Sequence ID"}},required:["sequenceId"]}},{name:"get_subscriber_activity",description:"Get recent activity, email stats, and current sequence enrollments for a subscriber",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},email:{type:"string",description:"Subscriber email address. Provide email or externalId to identify the subscriber."},externalId:{type:"string",description:"Customer-owned subscriber ID. Provide email or externalId to identify the subscriber."}},required:[]}},{name:"generate_email",description:"Generate email blocks from a prompt",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},prompt:{type:"string",description:"Description of the email to generate"},style:{type:"string",description:"Style: minimal, branded, promotional"},tone:{type:"string",description:"Tone: professional, casual, friendly"}},required:["prompt"]}},{name:"generate_sequence",description:"[DEPRECATED - Use create_sequence instead] Generate a multi-email sequence from a goal. Note: create_sequence now handles AI generation automatically.",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},goal:{type:"string",description:"Goal of the sequence (e.g., 'onboard new SaaS trial users')"},emailCount:{type:"number",description:"Number of emails in the sequence (default: 5, max: 10)"},durationDays:{type:"number",description:"Total duration in days (default: 14)"}},required:["goal"]}},{name:"generate_subject_lines",description:"Generate A/B test subject line variants",inputSchema:{type:"object",properties:{companyId:{type:"string",description:"Company ID. If not provided, uses the currently selected company."},topic:{type:"string",description:"Topic or context for the subject lines"},count:{type:"number",description:"Number of variants to generate (default: 5)"}},required:["topic"]}}];async function V5(Q,X){try{let Y;switch(Q){case"get_account":{let G=await Z("GET","/api/v1/account"),$=m1();Y={...G,selectedCompanyId:$??G.currentCompanyId};break}case"select_company":{let G=X.companyId,$=await Z("GET","/api/v1/account"),J=$.companies?.find((z)=>z.id===G);if(!J)throw Error(`Company not found. Available companies: ${$.companies?.map((z)=>`${z.name} (${z.id})`).join(", ")??"none"}`);RX(G),Y={success:!0,message:`Switched to company: ${J.name}`,companyId:J.id,companyName:J.name};break}case"get_app_urls":{let G=await F5(X);Y={...K1({companyId:G,campaignId:j(X,"campaignId"),sequenceId:j(X,"sequenceId"),emailId:j(X,"emailId")??j(X,"templateId"),transactionalId:j(X,"transactionalId"),emailSendId:j(X,"emailSendId"),domainId:j(X,"domainId"),status:j(X,"status"),settingsTab:j(X,"settingsTab")}),...G===void 0&&{note:"No company ID is selected. Call get_account, select_company, or pass companyId to get concrete dashboard URLs."}};break}case"create_company":{let G=await Z("POST","/api/v1/companies",{name:X.name,domain:X.domain});if(!G.success)throw Error("Failed to create company");let $=G.company.id,J=6,z=0,H=G.company.status;while(H==="processing"&&z<J){await new Promise((K)=>setTimeout(K,20000)),z++;let A=await Z("GET",`/api/v1/companies/${$}`);if(A.success)H=A.company.status}RX($);let U=await Z("GET",`/api/v1/companies/${$}`);Y={success:!0,company:U.company,message:H==="processing"?"Company created but still processing. You can continue using it while processing completes.":`Company '${U.company.name}' created and ready to use.`,autoSelected:!0};break}case"get_company":{let G=X.companyId;Y=await Z("GET",`/api/v1/companies/${G}`);break}case"create_api_key":{let G=X.companyId;Y=await Z("POST","/api/v1/api-keys",{name:X.name},G);break}case"list_websites":{let G=X.companyId;Y=await Z("GET","/api/v1/websites",void 0,G);break}case"add_website":{let G=X.companyId;Y=await Z("POST","/api/v1/websites",{domain:X.domain},G);break}case"check_website":{let G=X.companyId;Y=await Z("GET",`/api/v1/websites/${X.domain}`,void 0,G);break}case"get_integration_guide":Y=await Z("POST","/api/v1/integration-guide",X);break;case"add_subscriber":{let G=X.companyId,$=u4("add_subscriber",X);Y=await Z("POST","/api/v1/subscribers",{...$,customAttributes:X.attributes,tags:X.tags,lists:X.listIds,...X.status!==void 0&&{status:X.status},...X.optInMode!==void 0&&{optInMode:X.optInMode}},G);break}case"update_subscriber":{let G=X.companyId,$=u4("update_subscriber",X),J=await TX($,G),z=Array.isArray(J.subscriber.tags)?J.subscriber.tags.filter((B)=>typeof B==="string"):[],H=Array.isArray(X.addTags)?X.addTags.filter((B)=>typeof B==="string"&&B.trim()!=="").map(D5):[],U=new Set(Array.isArray(X.removeTags)?X.removeTags.filter((B)=>typeof B==="string"&&B.trim()!=="").map(D5):[]),A=z.filter((B)=>!U.has(B));for(let B of H)if(!A.includes(B))A.push(B);let K={};if($.email&&$.externalId)K.externalId=$.externalId;if(D0(X.attributes))K.customAttributes={...D0(J.subscriber.customAttributes)?J.subscriber.customAttributes:{},...X.attributes};if(X.addTags||X.removeTags)K.tags=A;Y=await Z("PATCH",SX($),K,G);break}case"remove_subscriber":{let G=X.companyId,$=u4("remove_subscriber",X),J=SX($);if(X.hardDelete===!0)Y=await Z("DELETE",J,void 0,G);else Y=await Z("PATCH",J,{status:"unsubscribed"},G);break}case"get_subscriber":{let G=X.companyId,$=u4("get_subscriber",X);Y=await TX($,G);break}case"search_subscribers":{let G=X.companyId;Y=await OM(X,G);break}case"list_tags":{let G=X.companyId;Y=await Z("GET","/api/v1/tags",void 0,G);break}case"list_lists":{let G=X.companyId;Y=await Z("GET","/api/v1/lists",void 0,G);break}case"create_list":{let G=X.companyId;Y=await Z("POST","/api/v1/lists",X,G);break}case"list_segments":{let G=X.companyId;Y=await Z("GET","/api/v1/segments",void 0,G);break}case"create_segment":{UM(X);let G=X.companyId;Y=await Z("POST","/api/v1/segments",{...X,...X.filters!==void 0?{filters:L5(X.filters)}:{},...X.root!==void 0?{root:q5(X.root)}:{}},G);break}case"get_segment_count":{let G=X.companyId;Y=await Z("GET",`/api/v1/segments/${X.segmentId}/count`,void 0,G);break}case"list_templates":{let G=X.companyId,$=new URLSearchParams,J=j(X,"label");if(J)$.set("label",J);Y=await Z("GET",`/api/v1/templates${$.size>0?`?${$}`:""}`,void 0,G);break}case"get_template":{let G=X.companyId;Y=await Z("GET",`/api/v1/templates/${X.templateId}`,void 0,G);break}case"create_template":{let G=X.companyId;N1("create_template",X,{requireContent:!0}),HQ("create_template",X),Y=await Z("POST","/api/v1/templates",X,G);break}case"update_template":{let G=X.companyId,$=new Set(["companyId","templateId","name","subject","html","blocks","labels"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_template\` accepts only \`name\`, \`subject\`, \`html\`, \`blocks\`, and \`labels\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_template",X),HQ("update_template",X),X.name===void 0&&X.subject===void 0&&X.html===void 0&&X.blocks===void 0&&X.labels===void 0)throw Error("Provide at least one of `name`, `subject`, `html`, `blocks`, or `labels` when calling `update_template`.");Y=await Z("PUT",`/api/v1/templates/${X.templateId}`,X,G);break}case"delete_template":{let G=X.companyId;Y=await Z("DELETE",`/api/v1/templates/${X.templateId}`,void 0,G);break}case"list_ab_tests":{let G=X.companyId,$=new URLSearchParams,J=j(X,"sequenceId");if(J)$.set("sequenceId",J);Y=await Z("GET",`/api/v1/ab-tests${$.size>0?`?${$}`:""}`,void 0,G);break}case"get_ab_test":{let G=X.companyId;Y=await Z("GET",`/api/v1/ab-tests/${X.abTestId}`,void 0,G);break}case"get_ab_test_stats":{let G=X.companyId,$=new URLSearchParams,J=j(X,"period"),z=j(X,"start"),H=j(X,"end");if(J)$.set("period",J);if(z)$.set("start",z);if(H)$.set("end",H);Y=await Z("GET",`/api/v1/ab-tests/${X.abTestId}/stats${$.size>0?`?${$}`:""}`,void 0,G);break}case"restart_ab_test":{let G=X.companyId,$=new Set(["companyId","abTestId","sourceVariantId","testType","winnerThreshold","variantCount"]),J=Object.keys(X).filter((A)=>!$.has(A));if(J.length>0)throw Error(`\`restart_ab_test\` accepts only \`sourceVariantId\`, \`testType\`, \`winnerThreshold\`, and \`variantCount\` option fields. Unsupported field${J.length===1?"":"s"}: ${J.map((A)=>`\`${A}\``).join(", ")}.`);let z=j(X,"testType");if(z!==void 0&&z!=="subject"&&z!=="content")throw Error("`restart_ab_test` testType must be `subject` or `content`.");let H=X.winnerThreshold===void 0?void 0:Number(X.winnerThreshold);if(H!==void 0&&(!Number.isInteger(H)||H<10||H>1000))throw Error("`restart_ab_test` winnerThreshold must be an integer from 10 to 1000.");let U=X.variantCount===void 0?void 0:Number(X.variantCount);if(U!==void 0&&(!Number.isInteger(U)||U<2||U>4))throw Error("`restart_ab_test` variantCount must be an integer from 2 to 4.");Y=await Z("POST",`/api/v1/ab-tests/${X.abTestId}/restart`,{sourceVariantId:j(X,"sourceVariantId"),testType:z,winnerThreshold:H,variantCount:U},G);break}case"update_ab_test_variant":{let G=X.companyId,$=new Set(["companyId","abTestId","variantId","subject","previewText","html","blocks"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_ab_test_variant\` accepts only \`subject\`, \`previewText\`, \`html\`, and \`blocks\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_ab_test_variant",X),X.subject===void 0&&X.previewText===void 0&&X.html===void 0&&X.blocks===void 0)throw Error("Provide at least one of `subject`, `previewText`, `html`, or `blocks` when calling `update_ab_test_variant`.");Y=await Z("PATCH",`/api/v1/ab-tests/${X.abTestId}/variants/${X.variantId}`,X,G);break}case"list_campaigns":{let G=X.companyId,$=new URLSearchParams;if(X.status)$.set("status",String(X.status));let J=j(X,"label");if(J)$.set("label",J);Y=await Z("GET",`/api/v1/campaigns?${$}`,void 0,G);break}case"get_campaign":{let G=X.companyId;Y=await Z("GET",`/api/v1/campaigns/${X.campaignId}`,void 0,G);break}case"get_email_send":{let G=X.companyId;Y=await Z("GET",`/api/v1/email-sends/${encodeURIComponent(String(X.emailSendId))}`,void 0,G);break}case"create_campaign":{let G=X.companyId;BM(X);let $=j(X,"prompt");if($!==void 0){let J=await Z("POST","/api/v1/generate/email",{prompt:$,...X.style!==void 0&&{style:X.style},...X.tone!==void 0&&{tone:X.tone}},G),z=j(X,"subject")??(typeof J.subject==="string"&&J.subject.trim()!==""?J.subject.trim():void 0);if(!z)throw Error("`create_campaign` prompt generation did not return a subject. Provide `subject` explicitly.");let H=Array.isArray(J.blocks)&&J.blocks.length>0?J.blocks:void 0,U=typeof J.html==="string"&&J.html.trim()!==""?J.html:void 0;if(H===void 0&&U===void 0)throw Error("`create_campaign` prompt generation did not return email blocks. Try again or provide `html` or `blocks` explicitly.");Y=await Z("POST","/api/v1/campaigns",{name:X.name,subject:z,...H!==void 0?{blocks:H}:{html:U},...X.segmentId!==void 0&&{segmentId:X.segmentId},...X.trackingCode!==void 0&&{trackingCode:X.trackingCode},...X.campaignData!==void 0&&{campaignData:X.campaignData},...X.computedLists!==void 0&&{computedLists:X.computedLists},...X.labels!==void 0&&{labels:X.labels}},G);break}Y=await Z("POST","/api/v1/campaigns",X,G);break}case"update_campaign":{let G=X.companyId,$=new Set(["companyId","campaignId","name","subject","trackingCode","html","blocks","replyTo","replyProfileId","campaignData","computedLists","labels"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`update_campaign\` accepts only \`name\`, \`subject\`, \`trackingCode\`, \`html\`, \`blocks\`, \`replyTo\`, \`replyProfileId\`, \`campaignData\`, \`computedLists\`, and \`labels\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);if(N1("update_campaign",X),HQ("update_campaign",X),X.replyTo!==void 0&&X.replyProfileId!==void 0)throw Error("Provide either `replyTo` or `replyProfileId` when calling `update_campaign`, not both.");if(X.name===void 0&&X.subject===void 0&&X.trackingCode===void 0&&X.html===void 0&&X.blocks===void 0&&X.replyTo===void 0&&X.replyProfileId===void 0&&X.campaignData===void 0&&X.computedLists===void 0&&X.labels===void 0)throw Error("Provide at least one of `name`, `subject`, `trackingCode`, `html`, `blocks`, `replyTo`, `replyProfileId`, `campaignData`, `computedLists`, or `labels` when calling `update_campaign`.");Y=await Z("PUT",`/api/v1/campaigns/${X.campaignId}`,X,G);break}case"schedule_campaign":{let G=X.companyId,$=new Set(["companyId","campaignId","scheduledAt","targetLists","sendTimeOptimization","spreadOverHours"]),J=Object.keys(X).filter((z)=>!$.has(z));if(J.length>0)throw Error(`\`schedule_campaign\` accepts only \`campaignId\`, \`scheduledAt\`, \`targetLists\`, \`sendTimeOptimization\`, and \`spreadOverHours\`. Unsupported field${J.length===1?"":"s"}: ${J.map((z)=>`\`${z}\``).join(", ")}.`);DM(X),Y=await Z("POST",`/api/v1/campaigns/${X.campaignId}/schedule`,{scheduledAt:X.scheduledAt,...X.targetLists!==void 0&&{targetLists:X.targetLists},...X.sendTimeOptimization!==void 0&&{sendTimeOptimization:X.sendTimeOptimization},...X.spreadOverHours!==void 0&&{spreadOverHours:X.spreadOverHours}},G);break}case"send_test_email":{let G=X.companyId;Y=await Z("POST",`/api/v1/campaigns/${X.campaignId}/test`,{to:X.to},G);break}case"list_sequences":{let G=X.companyId;Y=await Z("GET","/api/v1/sequences",void 0,G);break}case"get_sequence":{let G=X.companyId;Y=await Z("GET",`/api/v1/sequences/${X.sequenceId}`,void 0,G);break}case"create_sequence":{let G=X.companyId,$=Array.isArray(X.steps)&&X.steps.length>0,J=await Z("POST","/api/v1/sequences",X,G);if(!J.success){Y=J;break}let z=J.sequence.id;if($){let B=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(B.success)Y={success:!0,sequence:B.sequence,message:`Sequence "${B.sequence.name}" created with explicit steps. Review it before enabling.`};else Y=B;break}let H=6,U=0,A="pending";while(A!=="complete"&&U<H){await new Promise((L)=>setTimeout(L,20000)),U++;let B=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(B.success)A=B.sequence.enrichmentStatus}let K=await Z("GET",`/api/v1/sequences/${z}`,void 0,G);if(K.success)Y={success:!0,sequence:K.sequence,message:K.sequence.enrichmentStatus==="complete"?`Sequence "${K.sequence.name}" created with ${K.sequence.emailCount} AI-generated emails. The sequence is ready to review and enable.`:`Sequence "${K.sequence.name}" created. Email enrichment is still in progress (${K.sequence.enrichedCount}/${K.sequence.emailCount} emails generated). You can check status with get_sequence.`};else Y=K;break}case"update_sequence":{let G=X.companyId,$=AM(X);Y=await Z("PUT",`/api/v1/sequences/${X.sequenceId}`,$,G);break}case"enable_sequence":{let G=X.companyId;Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/enable`,void 0,G);break}case"disable_sequence":{let G=X.companyId;Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/disable`,void 0,G);break}case"cancel_sequence_enrollments":{let G=X.companyId,$=KM(X);Y=await Z("POST",`/api/v1/sequences/${X.sequenceId}/enrollments/cancel`,$,G);break}case"delete_sequence":{let G=X.companyId;Y=await Z("DELETE",`/api/v1/sequences/${X.sequenceId}`,void 0,G);break}case"list_transactional_emails":{let G=X.companyId;Y=await Z("GET","/api/v1/transactional",void 0,G);break}case"get_transactional_email":{let G=X.companyId;Y=await Z("GET",`/api/v1/transactional/${X.idOrSlug}`,void 0,G);break}case"create_transactional_email":{let G=X.companyId,$=new Set(["companyId","name","slug","subject","previewText","html","blocks","prompt","style","tone","enabled"]),J=Object.keys(X).filter((U)=>!$.has(U));if(J.length>0)throw Error(`\`create_transactional_email\` accepts only \`name\`, \`slug\`, \`subject\`, \`previewText\`, \`html\`, \`blocks\`, \`prompt\`, \`style\`, \`tone\`, and \`enabled\` fields. Unsupported field${J.length===1?"":"s"}: ${J.map((U)=>`\`${U}\``).join(", ")}.`);LM(X);let z=j(X,"prompt");if(z!==void 0){let U={companyId:G??m1()??"",name:typeof X.name==="string"&&X.name.trim()!==""?X.name.trim():"",slug:typeof X.slug==="string"&&X.slug.trim()!==""?X.slug.trim():"",promptLength:z.length,style:typeof X.style==="string"?X.style:"",tone:typeof X.tone==="string"?X.tone:""};try{console.error("[mcp:create_transactional_email] generating from prompt",U);let A=await Z("POST","/api/v1/generate/email",{prompt:z,...X.style!==void 0&&{style:X.style},...X.tone!==void 0&&{tone:X.tone}},G);console.error("[mcp:create_transactional_email] prompt generation complete",{...U,subject:A.subject??"",previewTextLength:typeof A.previewText==="string"?A.previewText.length:0,blockCount:Array.isArray(A.blocks)?A.blocks.length:0,htmlLength:typeof A.html==="string"?A.html.length:0});let K=j(X,"subject")??(typeof A.subject==="string"&&A.subject.trim()!==""?A.subject.trim():void 0);if(!K)throw Error("`create_transactional_email` prompt generation did not return a subject. Provide `subject` explicitly.");let B=Array.isArray(A.blocks)&&A.blocks.length>0?A.blocks:void 0,L=typeof A.html==="string"&&A.html.trim()!==""?A.html:void 0,F=j(X,"previewText")??(typeof A.previewText==="string"?A.previewText.trim():void 0);if(B===void 0&&L===void 0)throw Error("`create_transactional_email` prompt generation did not return email blocks. Try again or provide `html` or `blocks` explicitly.");console.error("[mcp:create_transactional_email] creating generated transactional",{...U,subject:K,contentSource:B!==void 0?"blocks":"html",blockCount:B?.length??0,htmlLength:L?.length??0}),Y=await Z("POST","/api/v1/transactional",{name:X.name,...X.slug!==void 0&&{slug:X.slug},subject:K,...F!==void 0&&{previewText:F},...B!==void 0?{blocks:B}:{html:L},...X.enabled!==void 0&&{enabled:X.enabled}},G),console.error("[mcp:create_transactional_email] generated transactional created",U)}catch(A){throw console.error("[mcp:create_transactional_email] prompt-based create failed",{...U,error:A instanceof Error?A.message:String(A)}),A}break}let H=Object.fromEntries(Object.entries(X).filter(([U])=>U!=="companyId"));Y=await Z("POST","/api/v1/transactional",H,G);break}case"update_transactional_email":{let G=X.companyId,$=new Set(["companyId","idOrSlug","name","enabled","subject","previewText","html","blocks"]),J=Object.keys(X).filter((H)=>!$.has(H));if(J.length>0)throw Error(`\`update_transactional_email\` accepts only \`name\`, \`enabled\`, \`subject\`, \`previewText\`, \`html\`, and \`blocks\` update fields. Unsupported field${J.length===1?"":"s"}: ${J.map((H)=>`\`${H}\``).join(", ")}.`);if(N1("update_transactional_email",X),X.name===void 0&&X.enabled===void 0&&X.subject===void 0&&X.previewText===void 0&&X.html===void 0&&X.blocks===void 0)throw Error("Provide at least one of `name`, `enabled`, `subject`, `previewText`, `html`, or `blocks` when calling `update_transactional_email`.");let z=Object.fromEntries(Object.entries(X).filter(([H])=>H!=="companyId"&&H!=="idOrSlug"));Y=await Z("PATCH",`/api/v1/transactional/${X.idOrSlug}`,z,G);break}case"send_email":{let G=X.companyId;Y=await Z("POST","/api/v1/transactional/send",X,G);break}case"get_stats":{let G=X.companyId,$=X.period??"7d";Y=await Z("GET",`/api/v1/metrics?period=${$}`,void 0,G);break}case"get_campaign_stats":{let G=X.companyId;Y=await Z("GET",`/api/v1/metrics/campaigns/${X.campaignId}`,void 0,G);break}case"get_sequence_stats":{let G=X.companyId;Y=await Z("GET",`/api/v1/metrics/sequences/${X.sequenceId}`,void 0,G);break}case"get_subscriber_activity":{let G=X.companyId,$=u4("get_subscriber_activity",X),J=await TX($,G);Y={success:J.success,email:J.subscriber.email,emailStats:J.subscriber.emailStats??null,activity:J.subscriber.activity??[],sequenceEnrollments:J.subscriber.sequenceEnrollments??[]};break}case"generate_email":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/email",X,G);break}case"generate_sequence":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/sequence",X,G);break}case"generate_subject_lines":{let G=X.companyId;Y=await Z("POST","/api/v1/generate/subjects",X,G);break}default:throw Error(`Unknown tool: ${Q}`)}let W=qM(Y);if(W)throw W;return Y=await NM(Q,X,Y),{content:[{type:"text",text:JSON.stringify(Y,null,2)}]}}catch(Y){return{isError:!0,content:[{type:"text",text:Z1(Y)}]}}}var wM=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com",Z5=process.env.SEQUENZY_API_KEY,CX=null;if(!Z5)console.error(Z1(new l1("SEQUENZY_API_KEY environment variable is required",401,void 0,"MCP_AUTH_REQUIRED"))),process.exit(1);function m1(){return CX}function RX(Q){CX=Q}var f4=new PX({name:"sequenzy",version:z5.version},{capabilities:{tools:{},resources:{}}});function N0(Q,X){let Y=Q[X];return typeof Y==="string"&&Y.trim()!==""?Y.trim():void 0}function bM(Q){if(Q===void 0)return;if(typeof Q==="string")return Q.trim()||void 0;return JSON.stringify(Q)}function PM(Q){if(!Q.trim())return{message:"Request failed"};try{let X=JSON.parse(Q);if(typeof X==="string")return{message:X};let Y=typeof X.error==="object"&&X.error!==null?X.error:void 0,W=N0(X,"code")??(Y?N0(Y,"code"):void 0),G=(typeof X.error==="string"?X.error:void 0)??(Y?N0(Y,"message"):void 0)??N0(X,"message")??N0(X,"error")??Q,$=N0(X,"howToFix")??N0(X,"resolution"),J={...N0(X,"title")?{title:N0(X,"title")}:{},...N0(X,"description")?{description:N0(X,"description")}:{},...$?{howToFix:$}:{},...N0(X,"docsUrl")?{docsUrl:N0(X,"docsUrl")}:{}},z=bM(X.details);if(Object.keys(J).length>0||z)return{message:G,...W?{code:W}:{},...z?{details:z}:{},...Object.keys(J).length>0?{context:J}:{}};if(typeof X.error==="string")return{message:X.error,...W?{code:W}:{}};if(Y)return{message:G,...W?{code:W}:{}};return{message:G,...W?{code:W}:{}}}catch{return{message:Q}}}async function Z(Q,X,Y,W){let G={"Content-Type":"application/json",Authorization:`Bearer ${Z5}`},$=W??CX;if($)G["x-company-id"]=$;let J;try{J=await fetch(`${wM}${X}`,{method:Q,headers:G,body:Y?JSON.stringify(Y):void 0})}catch(z){throw new l1(z instanceof Error?z.message:"Failed to reach Sequenzy API",0,void 0,"NETWORK_ERROR")}if(!J.ok){let z=await J.text(),H=PM(z);throw new l1(H.message,J.status,H.details??z,H.code,H.context)}return J.json()}f4.setRequestHandler(K9,async()=>{return{tools:M5}});f4.setRequestHandler(B4,async(Q)=>{let{name:X,arguments:Y}=Q.params;return V5(X,Y??{})});f4.setRequestHandler(G9,async()=>{return{resources:A5}});f4.setRequestHandler(J9,async(Q)=>{let{uri:X}=Q.params;return K5(X)});async function jM(){let Q=new IX;await f4.connect(Q),console.error("Sequenzy MCP server running on stdio")}jM().catch((Q)=>{console.error(Z1(Q)),process.exit(1)});export{RX as setSelectedCompanyId,m1 as getSelectedCompanyId,Z as apiRequest};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenzy/mcp",
3
- "version": "0.0.41",
3
+ "version": "0.0.42",
4
4
  "mcpName": "io.github.sequenzy/mcp",
5
5
  "description": "Sequenzy MCP server for AI-powered email marketing automation",
6
6
  "type": "module",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/Sequenzy/mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.0.41",
9
+ "version": "0.0.42",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@sequenzy/mcp",
14
- "version": "0.0.41",
14
+ "version": "0.0.42",
15
15
  "runtime": "node",
16
16
  "transport": {
17
17
  "type": "stdio"