@sequenzy/mcp 0.0.140 → 0.0.142
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 +24 -18
- package/dist/runtime.js +1 -1
- package/dist/server.js +22 -16
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var L=Object.create;var{getPrototypeOf:K,defineProperty:G,getOwnPropertyNames:O}=Object;var C=Object.prototype.hasOwnProperty;function T(B){return this[B]}var b,h,A=(B,j,V)=>{var J=B!=null&&typeof B==="object";if(J){var Q=j?b??=new WeakMap:h??=new WeakMap,W=Q.get(B);if(W)return W}V=B!=null?L(K(B)):{};let X=j||!B||!B.__esModule?G(V,"default",{value:B,enumerable:!0}):V;for(let Y of O(B))if(!C.call(X,Y))G(X,Y,{get:T.bind(B,Y),enumerable:!0});if(J)Q.set(B,X);return X};var E=(B,j)=>()=>(j||B((j={exports:{}}).exports,j),j.exports);var U=(B)=>B;function x(B,j){this[B]=U.bind(null,j)}var y=(B,j)=>{for(var V in j)G(B,V,{get:j[V],enumerable:!0,configurable:!0,set:x.bind(j,V)})};import{AsyncLocalStorage as z}from"node:async_hooks";class $ extends Error{statusCode;rawDetails;code;context;constructor(B,j,V,J,Q){super(B);this.statusCode=j;this.rawDetails=V;this.code=J;this.context=Q;this.name="McpApiError"}}function F(B){if(B instanceof $)return{message:B.message,statusCode:B.statusCode,code:B.code,rawDetails:B.rawDetails,context:B.context};if(B instanceof Error)return{message:B.message};return{message:String(B)}}function I(B){let j=B.match(/api key is missing required scopes?:\s*(.+)$/i);if(!j?.[1])return[];return[...new Set(j[1].match(/[a-z_]+:[a-z_]+/gi)??[])]}function v(B){let j=F(B),V=j.message.trim()||"Unknown error",J=V.toLowerCase(),Q=j.rawDetails?.trim()||V;if(j.context?.title||j.context?.description||j.context?.howToFix||j.context?.docsUrl)return{title:j.context.title??(j.statusCode===409?"Request conflict":"API request failed"),description:j.context.description??V,howToFix:j.context.howToFix??"Review the details below, adjust the tool input, and retry.",docsUrl:j.context.docsUrl??"https://docs.sequenzy.com/concepts/mcp",details:Q};if(j.code==="MCP_AUTH_REQUIRED"||J.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:Q};if(j.statusCode===401||j.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:Q};let W=I(V);if(W.length>0){let X=W.map((N)=>`\`${N}\``).join(", "),Y=W.every((N)=>N.endsWith(":read"))?"the Read-only or Safer agent access preset":"Safer agent access when it covers the task, or Custom permissions";return{title:"API key permission required",description:`The current API key is valid, but this operation requires the missing ${W.length===1?"scope":"scopes"}: ${X}.`,howToFix:`
|
|
1
|
+
var L=Object.create;var{getPrototypeOf:K,defineProperty:G,getOwnPropertyNames:O}=Object;var C=Object.prototype.hasOwnProperty;function T(B){return this[B]}var b,h,A=(B,j,V)=>{var J=B!=null&&typeof B==="object";if(J){var Q=j?b??=new WeakMap:h??=new WeakMap,W=Q.get(B);if(W)return W}V=B!=null?L(K(B)):{};let X=j||!B||!B.__esModule?G(V,"default",{value:B,enumerable:!0}):V;for(let Y of O(B))if(!C.call(X,Y))G(X,Y,{get:T.bind(B,Y),enumerable:!0});if(J)Q.set(B,X);return X};var E=(B,j)=>()=>(j||B((j={exports:{}}).exports,j),j.exports);var U=(B)=>B;function x(B,j){this[B]=U.bind(null,j)}var y=(B,j)=>{for(var V in j)G(B,V,{get:j[V],enumerable:!0,configurable:!0,set:x.bind(j,V)})};import{AsyncLocalStorage as z}from"node:async_hooks";class $ extends Error{statusCode;rawDetails;code;context;constructor(B,j,V,J,Q){super(B);this.statusCode=j;this.rawDetails=V;this.code=J;this.context=Q;this.name="McpApiError"}}function F(B){if(B instanceof $)return{message:B.message,statusCode:B.statusCode,code:B.code,rawDetails:B.rawDetails,context:B.context};if(B instanceof Error)return{message:B.message};return{message:String(B)}}function I(B){let j=B.match(/api key is missing required scopes?:\s*(.+)$/i);if(!j?.[1])return[];return[...new Set(j[1].match(/[a-z_]+:[a-z_]+/gi)??[])]}function v(B){let j=F(B),V=j.message.trim()||"Unknown error",J=V.toLowerCase(),Q=j.rawDetails?.trim()||V;if(j.context?.title||j.context?.description||j.context?.howToFix||j.context?.docsUrl)return{title:j.context.title??(j.statusCode===409?"Request conflict":"API request failed"),description:j.context.description??V,howToFix:j.context.howToFix??"Review the details below, adjust the tool input, and retry.",docsUrl:j.context.docsUrl??"https://docs.sequenzy.com/concepts/mcp",details:Q};if(j.code==="MCP_AUTH_REQUIRED"||J.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:Q};if(j.statusCode===401||j.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:Q};let W=I(V);if(W.length>0){let X=W.map((N)=>`\`${N}\``).join(", "),Y=W.every((N)=>N.endsWith(":read"))?"the Read-only or Safer agent access preset":"Safer agent access when it covers the task, or Custom permissions";return{title:"API key permission required",description:`The current API key is valid, but this operation requires the missing ${W.length===1?"scope":"scopes"}: ${X}.`,howToFix:`Permissions can be widened on the key you are already using - no replacement key and no client restart. Call \`get_account\` to read \`apiKeyPermissions\`, then have the key owner open \`apiKeyPermissions.manageUrl\`, edit the key identified by \`apiKeyPermissions.activeKey\`, and enable ${X}. The URL opens Account → API Keys for a \`personal\` key and workspace Settings → API Keys for a \`company\` key. If \`get_account\` also requires \`account:read\`, open ${"https://sequenzy.com/dashboard"} directly and choose the matching API Keys page. When \`apiKeyPermissions.activeKey.type\` is \`company\` and the key holds \`api_keys:manage\`, the agent can instead call \`update_api_key\` with \`apiKeyId\` from \`apiKeyPermissions.activeKey.id\`. Personal keys cannot be changed through \`update_api_key\`. \`scopes\` and \`preset\` REPLACE the whole selection, so pass every scope in \`apiKeyPermissions.scopes\` plus ${X}, or a preset covering all of them (${Y}). Then retry the same tool call - the API reloads the key's permissions on a denied request, so the retry succeeds without reconnecting. Issuing a replacement key and swapping \`SEQUENZY_API_KEY\`, or reauthorizing a hosted OAuth connection with wider permissions, also works but is not required.`,docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:Q}}if(j.statusCode===403||J.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:Q};if(J.includes("no company available")||J.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:Q};if(j.statusCode===404||J.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:Q};if(J.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:Q};if(j.statusCode===409)return{title:"Request conflict",description:"Sequenzy rejected this request because the resource changed or an operation is already in progress.",howToFix:"Refresh the resource state, choose the lifecycle action allowed by its current status, and retry at most once.",docsUrl:"https://docs.sequenzy.com/concepts/mcp",details:Q};if(j.statusCode===429||J.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:Q};if(j.code==="NETWORK_ERROR"||J.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:Q};if(J.includes("unknown tool")||J.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:Q};if(J.includes("is required")||J.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:Q};if(j.statusCode&&j.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:Q};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:Q}}function k(B){let j=v(B);return[`Sequenzy MCP error: ${j.title}`,`Description: ${j.description}`,`How to fix: ${j.howToFix}`,`Docs: ${j.docsUrl}`,`Details: ${j.details}`].join(`
|
|
2
2
|
`)}var u="https://api.sequenzy.com",M=new Set(["/api/v1/media/upload-bytes","/v1/media/upload-bytes"]),R=new z,D=!1;function l(){D=!0}function p(){return D}var H=null;function w(){let B=R.getStore();if(B)return B.selectedCompanyId??null;return H}function i(B){let j=R.getStore();if(j){j.selectedCompanyId=B;return}H=B}function t(B,j){return R.run(B,j)}function q(){return R.getStore()?.apiUrl??process.env.SEQUENZY_API_URL??u}function P(){return R.getStore()?.apiKey??process.env.SEQUENZY_API_KEY}function _(B,j){let V=P();if(!V)throw new $("SEQUENZY_API_KEY environment variable is required",401,void 0,"MCP_AUTH_REQUIRED");let J={"Content-Type":B,Authorization:`Bearer ${V}`},Q=j??w();if(Q)J["x-company-id"]=Q;return J}function d(){if(P())return;console.error(k(new $("SEQUENZY_API_KEY environment variable is required",401,void 0,"MCP_AUTH_REQUIRED"))),process.exit(1)}function Z(B,j){let V=B[j];return typeof V==="string"&&V.trim()!==""?V.trim():void 0}function S(B){if(B===void 0)return;if(typeof B==="string")return B.trim()||void 0;return JSON.stringify(B)}function f(B){if(!B.trim())return{message:"Request failed"};try{let j=JSON.parse(B);if(typeof j==="string")return{message:j};let V=typeof j.error==="object"&&j.error!==null?j.error:void 0,J=Z(j,"code")??(V?Z(V,"code"):void 0),Q=(typeof j.error==="string"?j.error:void 0)??(V?Z(V,"message"):void 0)??Z(j,"message")??Z(j,"error")??B,W=Z(j,"howToFix")??Z(j,"resolution"),X={...Z(j,"title")?{title:Z(j,"title")}:{},...Z(j,"description")?{description:Z(j,"description")}:{},...W?{howToFix:W}:{},...Z(j,"docsUrl")?{docsUrl:Z(j,"docsUrl")}:{}},Y=S(j.details);if(Object.keys(X).length>0||Y)return{message:Q,...J?{code:J}:{},...Y?{details:Y}:{},...Object.keys(X).length>0?{context:X}:{}};if(typeof j.error==="string")return{message:j.error,...J?{code:J}:{}};if(V)return{message:Q,...J?{code:J}:{}};return{message:Q,...J?{code:J}:{}}}catch{return{message:B}}}async function s(B,j,V,J){let Q=_("application/json",J),W;try{W=await fetch(`${q()}${j}`,{method:B,headers:Q,body:V?JSON.stringify(V):void 0})}catch(X){throw new $(X instanceof Error?X.message:"Failed to reach Sequenzy API",0,void 0,"NETWORK_ERROR")}if(!W.ok){let X=await W.text(),Y=f(X);throw new $(Y.message,W.status,Y.details??X,Y.code,Y.context)}return W.json()}async function a(B,j,V,J){let Q=new URL(q()).origin,W=new URL(B,`${Q}/`);if(W.origin!==Q){if(!M.has(W.pathname))throw new $("The image upload URL did not point to the configured Sequenzy API.",500,void 0,"INVALID_UPLOAD_URL");W=new URL(`${W.pathname}${W.search}`,`${Q}/`)}let X;try{X=await fetch(W,{method:"PUT",headers:_(V,J),body:j})}catch(Y){throw new $(Y instanceof Error?Y.message:"Failed to upload image bytes",0,void 0,"NETWORK_ERROR")}if(!X.ok){let Y=await X.text(),N=f(Y);throw new $(N.message,X.status,N.details??Y,N.code,N.context)}}export{t as withMcpRequestContext,i as setSelectedCompanyId,w as getSelectedCompanyId,l as enableLocalFileUploads,d as assertConfiguredApiKey,p as areLocalFileUploadsEnabled,a as apiUploadRequest,s as apiRequest};
|