@imageconvertit/mcp-server 0.3.1 → 0.3.3

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/README.md CHANGED
@@ -85,11 +85,13 @@ Also: `mcp_status`, legacy `batch_resize_compress` / `batch_amazon_prep`.
85
85
  | Codex / ChatGPT desktop | `~/.codex/config.toml` | `[mcp_servers.imageconvertit]` |
86
86
  | Gemini CLI | `~/.gemini/settings.json` | `mcpServers` JSON |
87
87
 
88
+ **Windows GUI hosts (Claude / Cursor / VS Code):** use `npx.cmd` (not `npx`) so PATH resolves. macOS / Linux: `npx`. Node.js 20+ must be installed and on PATH for GUI apps.
89
+
88
90
  ```json
89
91
  {
90
92
  "mcpServers": {
91
93
  "imageconvertit": {
92
- "command": "npx",
94
+ "command": "npx.cmd",
93
95
  "args": ["-y", "@imageconvertit/mcp-server"],
94
96
  "env": {
95
97
  "ICI_LICENSE_KEY": "YOUR_LEMONSQUEEZY_LICENSE_KEY",
@@ -100,13 +102,15 @@ Also: `mcp_status`, legacy `batch_resize_compress` / `batch_amazon_prep`.
100
102
  }
101
103
  ```
102
104
 
105
+ On macOS / Linux, change `"command"` to `"npx"`. Prefer **Account → MCP** on imageconvertit.com — it emits the OS-correct snippet.
106
+
103
107
  **Do not** put `FAL_API_KEY`, `FASHN_API_KEY`, or `GROQ_API_KEY` in MCP env — they are rejected by design (unused) and must stay on the server.
104
108
 
105
- Codex / ChatGPT desktop TOML:
109
+ Codex / ChatGPT desktop TOML (Windows shown; use `npx` on macOS / Linux):
106
110
 
107
111
  ```toml
108
112
  [mcp_servers.imageconvertit]
109
- command = "npx"
113
+ command = "npx.cmd"
110
114
  args = ["-y", "@imageconvertit/mcp-server"]
111
115
 
112
116
  [mcp_servers.imageconvertit.env]
@@ -123,6 +127,7 @@ cd packages/mcp-server && npm run smoke
123
127
  ## Notes
124
128
 
125
129
  - **One package, two meters** — Core = Automation files; Cloud AI = credits
130
+ - Paths only for Core — use **absolute** `inputDir` / `outputDir` (client cwd is often wrong)
126
131
  - Paths only for Core — never send image bytes through the model
127
132
  - Cloud AI: MCP reads the file locally, POSTs to `/api/run-ai`, writes the result path
128
133
  - Max 50 files/pages per Core authorize call · concurrency ≤ 3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imageconvertit/mcp-server",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "ImageConvertIt local MCP — Core (E-Commerce + Format, Automation file meter) + Cloud AI (12 tools, website credit wallet). Provider keys never leave the server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,8 @@
20
20
  "scripts": {
21
21
  "start": "node ./src/index.js",
22
22
  "smoke": "node ./scripts/smoke-ops.mjs",
23
- "audit:cloud-ai": "node ./scripts/audit-cloud-ai.mjs"
23
+ "audit:cloud-ai": "node ./scripts/audit-cloud-ai.mjs",
24
+ "e2e:paid": "node ./scripts/paid-e2e-checklist.mjs"
24
25
  },
25
26
  "dependencies": {
26
27
  "@imgly/background-removal-node": "^1.4.5",
package/src/authorize.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Call ImageConvertIt /api/mcp/authorize before each Core batch.
3
3
  * Supports charge (default), status, and refund (failed files after charge).
4
+ * Refunds require charge_id from the matching charge response.
4
5
  */
5
6
 
6
7
  const DEFAULT_BASE = 'https://imageconvertit.com';
@@ -11,6 +12,7 @@ const DEFAULT_BASE = 'https://imageconvertit.com';
11
12
  * fileCount?: number,
12
13
  * apiBase?: string,
13
14
  * action?: 'charge'|'status'|'refund',
15
+ * chargeId?: string,
14
16
  * }} opts
15
17
  * @returns {Promise<{
16
18
  * allowed: boolean,
@@ -20,6 +22,7 @@ const DEFAULT_BASE = 'https://imageconvertit.com';
20
22
  * plan?: string,
21
23
  * used?: number,
22
24
  * month?: string,
25
+ * charge_id?: string,
23
26
  * }>}
24
27
  */
25
28
  export async function authorizeBatch({
@@ -27,22 +30,30 @@ export async function authorizeBatch({
27
30
  fileCount = 1,
28
31
  apiBase = DEFAULT_BASE,
29
32
  action = 'charge',
33
+ chargeId,
30
34
  }) {
31
35
  if (!licenseKey || typeof licenseKey !== 'string') {
32
36
  return { allowed: false, error: 'ICI_LICENSE_KEY is required (MCP plan).' };
33
37
  }
34
38
  const base = (apiBase || DEFAULT_BASE).replace(/\/$/, '');
35
39
  const act = action === 'status' || action === 'refund' ? action : 'charge';
40
+ if (act === 'refund' && (!chargeId || typeof chargeId !== 'string')) {
41
+ return { allowed: false, error: 'charge_id is required to refund MCP files.' };
42
+ }
36
43
  let res;
37
44
  try {
45
+ const body = {
46
+ license_key: licenseKey.trim(),
47
+ action: act,
48
+ file_count: Math.min(50, Math.max(1, Number(fileCount) || 1)),
49
+ };
50
+ if (act === 'refund' && chargeId) {
51
+ body.charge_id = String(chargeId).trim();
52
+ }
38
53
  res = await fetch(`${base}/api/mcp/authorize`, {
39
54
  method: 'POST',
40
55
  headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
41
- body: JSON.stringify({
42
- license_key: licenseKey.trim(),
43
- action: act,
44
- file_count: Math.min(50, Math.max(1, Number(fileCount) || 1)),
45
- }),
56
+ body: JSON.stringify(body),
46
57
  });
47
58
  } catch (e) {
48
59
  return { allowed: false, error: `Network error: ${e?.message ?? e}` };
@@ -70,5 +81,6 @@ export async function authorizeBatch({
70
81
  plan: json.plan,
71
82
  month: json.month,
72
83
  used: json.used,
84
+ charge_id: typeof json.charge_id === 'string' ? json.charge_id : undefined,
73
85
  };
74
86
  }
package/src/index.js CHANGED
@@ -14,12 +14,35 @@
14
14
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
15
15
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
16
16
  import { z } from 'zod';
17
+ import { createRequire } from 'node:module';
17
18
 
18
- import * as format from './tools/format.js';
19
- import * as ecom from './tools/ecommerce.js';
20
- import * as ai from './tools/ai.js';
19
+ /**
20
+ * Lazy tool modules — sharp / rembg / onnx stay off the cold-start path so
21
+ * clients can list tools before native deps finish loading.
22
+ * Call shape stays `await format.batchResize(env, args)`.
23
+ */
24
+ function lazyToolMod(specifier) {
25
+ let modPromise;
26
+ return new Proxy({}, {
27
+ get(_target, prop) {
28
+ return async (...args) => {
29
+ modPromise ||= import(specifier);
30
+ const mod = await modPromise;
31
+ const fn = mod[prop];
32
+ if (typeof fn !== 'function') {
33
+ throw new Error(`MCP tool export missing: ${String(prop)}`);
34
+ }
35
+ return fn(...args);
36
+ };
37
+ },
38
+ });
39
+ }
40
+
41
+ const format = lazyToolMod('./tools/format.js');
42
+ const ecom = lazyToolMod('./tools/ecommerce.js');
43
+ const ai = lazyToolMod('./tools/ai.js');
21
44
 
22
- const PKG_VERSION = '0.3.1';
45
+ const PKG_VERSION = createRequire(import.meta.url)('../package.json').version;
23
46
 
24
47
  const env = {
25
48
  ICI_LICENSE_KEY: process.env.ICI_LICENSE_KEY || '',
package/src/lib/batch.js CHANGED
@@ -70,7 +70,7 @@ export async function runFolderBatch(env, opts) {
70
70
  };
71
71
  }
72
72
 
73
- let auth = { allowed: true, remaining: null, limit: null, plan: null };
73
+ let auth = { allowed: true, remaining: null, limit: null, plan: null, charge_id: null };
74
74
  if (!opts.skipAuthorize) {
75
75
  auth = await authorizeBatch({
76
76
  licenseKey: env.ICI_LICENSE_KEY,
@@ -102,15 +102,16 @@ export async function runFolderBatch(env, opts) {
102
102
  const ok = results.filter((r) => r && r.out);
103
103
  const failed = results.filter((r) => r && r.error);
104
104
 
105
- // Refund meter for files that failed after charge-first authorize
105
+ // Refund meter for files that failed after charge-first authorize (requires charge_id)
106
106
  let remaining = auth.remaining;
107
- if (!opts.skipAuthorize && failed.length > 0) {
107
+ if (!opts.skipAuthorize && failed.length > 0 && auth.charge_id) {
108
108
  try {
109
109
  const refund = await authorizeBatch({
110
110
  licenseKey: env.ICI_LICENSE_KEY,
111
111
  fileCount: failed.length,
112
112
  apiBase: env.ICI_API_BASE,
113
113
  action: 'refund',
114
+ chargeId: auth.charge_id,
114
115
  });
115
116
  if (refund.allowed && typeof refund.remaining === 'number') {
116
117
  remaining = refund.remaining;