@attrkit/mcp 0.4.5 → 0.4.6

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.
Files changed (2) hide show
  1. package/dist/cli.js +17 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -14070,14 +14070,15 @@ async function callApi(config, path, options = {}) {
14070
14070
  clearTimeout(timer);
14071
14071
  }
14072
14072
  }
14073
+ var redact = (text) => text.replace(/\b(?:mk|pk|sk|rk)_[A-Za-z0-9_-]{8,}/g, "[redacted-key]").replace(/\b[Bb]earer\s+[A-Za-z0-9._-]{8,}/g, "Bearer [redacted]").replace(/\bAttriKit-(?:Management|Publishable)\s+\S+/g, "AttriKit-$1 [redacted]").replace(/([?&](?:token|secret|key|password|code|signature)=)[^&\s]+/gi, "$1[redacted]");
14073
14074
  function toToolResult(result) {
14074
14075
  if (!result.ok) {
14075
14076
  const envelope = result.json;
14076
14077
  const code = envelope?.error?.code ?? `http_${result.status}`;
14077
- const message = envelope?.error?.message ? `: ${envelope.error.message}` : "";
14078
+ const rawMessage = envelope?.error?.message;
14079
+ const message = typeof rawMessage === "string" && rawMessage !== "" ? `: ${redact(rawMessage).slice(0, 400)}` : "";
14078
14080
  const retryAfter = result.status === 429 && result.retryAfter ? ` (Retry-After: ${result.retryAfter})` : "";
14079
- const redact = (text) => text.replace(/\b(?:mk|pk|sk|rk)_[A-Za-z0-9_-]{8,}/g, "[redacted-key]").replace(/\b[Bb]earer\s+[A-Za-z0-9._-]{8,}/g, "Bearer [redacted]").replace(/\bAttriKit-(?:Management|Publishable)\s+\S+/g, "AttriKit-$1 [redacted]").replace(/([?&](?:token|secret|key|password|code|signature)=)[^&\s]+/gi, "$1[redacted]");
14080
- const excerpt = !envelope?.error?.message && result.rawBody ? ` — body: ${redact(result.rawBody.replace(/\s+/g, " ").trim()).slice(0, 300)}` : "";
14081
+ const excerpt = typeof rawMessage !== "string" && result.rawBody ? ` — body: ${redact(result.rawBody.replace(/\s+/g, " ").trim()).slice(0, 300)}` : "";
14081
14082
  const hint = result.status === 401 ? " Check ATTRKIT_API_KEY: this is the same error for a missing, wrong, revoked or expired key." : "";
14082
14083
  return {
14083
14084
  content: [{
@@ -14091,12 +14092,21 @@ function toToolResult(result) {
14091
14092
  const isEmptySuccess = result.status === 204 && (result.rawBody === undefined || result.rawBody === "");
14092
14093
  const isJsonEnvelope = result.json !== null && typeof result.json === "object" && !Array.isArray(result.json) && Object.hasOwn(result.json, "data");
14093
14094
  const contentType = (result.contentType ?? "").toLowerCase();
14094
- const looksLikeMarkup = typeof result.json === "string" && /^\s*<(?:!doctype|html|head|body)\b/i.test(result.json);
14095
- const isExpectedText = expectedResponse === "text" && typeof result.json === "string" && !contentType.includes("text/html") && !looksLikeMarkup;
14095
+ const looksLikeCsv = (() => {
14096
+ if (typeof result.json !== "string")
14097
+ return false;
14098
+ const firstLine = result.json.split(`
14099
+ `, 1)[0]?.trim() ?? "";
14100
+ if (!firstLine || firstLine.startsWith("<"))
14101
+ return false;
14102
+ const columns = firstLine.split(",").map((field) => field.trim().replace(/^"(.*)"$/s, "$1"));
14103
+ return columns.length >= 2 && columns.every((field) => /^[A-Za-z][A-Za-z0-9_]*$/.test(field));
14104
+ })();
14105
+ const isExpectedText = expectedResponse === "text" && typeof result.json === "string" && !contentType.includes("text/html") && looksLikeCsv;
14096
14106
  if (!isEmptySuccess && !isJsonEnvelope && !isExpectedText) {
14097
14107
  const reportedContentType = result.contentType ?? "unknown content type";
14098
14108
  const received = result.json === null ? "an empty body" : Array.isArray(result.json) ? "a JSON array" : typeof result.json === "object" ? "a JSON object without a data field" : `a ${typeof result.json} body`;
14099
- const body = result.rawBody ?? (typeof result.json === "string" ? result.json : JSON.stringify(result.json, null, 2));
14109
+ const body = redact(result.rawBody ?? (typeof result.json === "string" ? result.json : JSON.stringify(result.json, null, 2))).slice(0, 600);
14100
14110
  return {
14101
14111
  content: [{
14102
14112
  type: "text",
@@ -14112,7 +14122,7 @@ ${body}`
14112
14122
  structuredContent: structured
14113
14123
  };
14114
14124
  }
14115
- var SERVER_VERSION = "0.4.5";
14125
+ var SERVER_VERSION = "0.4.6";
14116
14126
  var periodSchema = z4.enum(["7d", "30d", "90d", "all"]).describe("Reporting window. Defaults to 30d.").optional();
14117
14127
  var appIdSchema = z4.string().describe("Optional app id to scope the result to one app.").optional();
14118
14128
  var requiredAppIdSchema = z4.string().describe("The AttrKit app id.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attrkit/mcp",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "AttrKit's stdio MCP server for its public Management API",
5
5
  "keywords": [
6
6
  "attrkit",