pixelate-mcp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -18,6 +18,15 @@ const stripDataUrl = (s) => {
|
|
|
18
18
|
return s.startsWith("data:") && i !== -1 ? s.slice(i + 1) : s;
|
|
19
19
|
};
|
|
20
20
|
const errText = (text) => ({ content: [{ type: "text", text }], isError: true });
|
|
21
|
+
const usd = (cents) => `$${(cents / 100).toFixed(2)}`;
|
|
22
|
+
// One-line billing summary from a /job done response (credits_cents may be null
|
|
23
|
+
// for unlimited subscription keys).
|
|
24
|
+
function billingLine(res) {
|
|
25
|
+
const price = res.price_cents != null ? `${usd(res.price_cents)}/image` : null;
|
|
26
|
+
if (res.credits_cents == null) return price ? ` Plan: unlimited (${price}).` : "";
|
|
27
|
+
const imgs = res.price_cents ? Math.floor(res.credits_cents / res.price_cents) : null;
|
|
28
|
+
return ` Charged ${price}; ${usd(res.credits_cents)} credit left${imgs != null ? ` (~${imgs} images)` : ""}.`;
|
|
29
|
+
}
|
|
21
30
|
|
|
22
31
|
async function jobReq(query, body) {
|
|
23
32
|
const res = await fetch(`${API_URL}/job?${query}`, {
|
|
@@ -33,7 +42,27 @@ async function jobReq(query, body) {
|
|
|
33
42
|
return j;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
const server = new McpServer({ name: "pixelate-mcp", version: "0.
|
|
45
|
+
const server = new McpServer({ name: "pixelate-mcp", version: "0.2.0" });
|
|
46
|
+
|
|
47
|
+
server.tool(
|
|
48
|
+
"pixelate_account",
|
|
49
|
+
"Show your Pixelate Cloud credit balance (how much you have left) and the cost per image.",
|
|
50
|
+
{},
|
|
51
|
+
async () => {
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetch(`${API_URL}/account`, { headers: { "x-api-key": API_KEY } });
|
|
54
|
+
const j = await res.json().catch(() => ({}));
|
|
55
|
+
if (!res.ok || !j.success) return errText(`account error (${res.status}): ${j.error || "unknown"}`);
|
|
56
|
+
const text =
|
|
57
|
+
j.plan === "subscription"
|
|
58
|
+
? `Plan: unlimited subscription. Cost per image: ${usd(j.price_per_image_cents)} (not charged on your plan).`
|
|
59
|
+
: `Balance: $${j.credits_usd} (~${j.images_remaining} images left). Cost per image: $${j.price_per_image_usd}.`;
|
|
60
|
+
return { content: [{ type: "text", text }] };
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return errText(`pixelate-mcp error: ${e?.message || e}`);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
);
|
|
37
66
|
|
|
38
67
|
server.tool(
|
|
39
68
|
"pixelate_image",
|
|
@@ -80,6 +109,7 @@ server.tool(
|
|
|
80
109
|
await writeFile(a.output_path, Buffer.from(res.image_base64, "base64"));
|
|
81
110
|
summary += ` Saved to ${a.output_path}.`;
|
|
82
111
|
}
|
|
112
|
+
summary += billingLine(res);
|
|
83
113
|
return {
|
|
84
114
|
content: [
|
|
85
115
|
{ type: "text", text: summary },
|
package/package.json
CHANGED