forgemesh-imagegen 2.2.0 → 2.2.1

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/index.js +11 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -155,9 +155,15 @@ function refusalError(res, paidAttempt) {
155
155
  else if (!paidAttempt) charged = false;
156
156
  else charged = res.headers.get("payment-response") || res.headers.get("x-payment-response") ? true : "unknown (no settlement receipt)";
157
157
  const reason = body && typeof body === "object" ? (body.error || body.reason || body.message || body.invalidReason) : undefined;
158
- const detail = reason ? (typeof reason === "string" ? reason : JSON.stringify(reason)) : res.text.slice(0, 500);
159
158
  const retryAfter = res.headers.get("retry-after");
160
- return new Error(`HTTP ${res.status} (charged:${charged})${retryAfter ? ` retry-after:${retryAfter}s` : ""}: ${detail}`);
159
+ // Fixed message (status, charged, optional short error code); the service body travels only as capped data.
160
+ const code = typeof reason === "string" && /^[a-z0-9_.:-]{1,64}$/i.test(reason) ? `: ${reason}` : "";
161
+ const err = new Error(`HTTP ${res.status} (charged:${charged})${retryAfter ? ` retry-after:${retryAfter}s` : ""}${code}`);
162
+ err.status = res.status;
163
+ err.charged = charged;
164
+ const raw = body && typeof body === "object" ? JSON.stringify(body) : res.text;
165
+ err.upstream = body && typeof body === "object" && raw.length <= 1500 ? body : raw.slice(0, body && typeof body === "object" ? 1500 : 500);
166
+ return err;
161
167
  }
162
168
 
163
169
  // Poll a job's free status_url until it succeeds or fails (up to ~90s).
@@ -268,6 +274,9 @@ async function main() {
268
274
  }],
269
275
  };
270
276
  } catch (e) {
277
+ if (e && e.status !== undefined) {
278
+ return { content: [{ type: "text", text: JSON.stringify({ error: e.message, status: e.status, charged: e.charged, upstream: e.upstream, untrusted: true }) }], isError: true };
279
+ }
271
280
  return { content: [{ type: "text", text: "Error: " + e.message }], isError: true };
272
281
  }
273
282
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgemesh-imagegen",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "mcpName": "io.github.forgemeshlabs/imagegen-mcp",
5
5
  "description": "MCP server for AI image generation — generate, clean (bg removal), HD (4x upscale), Pro. Pay per image in USDC via x402 on Base. No API key needed.",
6
6
  "main": "index.js",