forgemesh-imagegen 1.0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -0
  3. package/index.js +176 -0
  4. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CoinOpAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # forgemesh-imagegen
2
+
3
+ **MCP server for AI image generation.** Generate images, remove backgrounds, upscale to 4x HD — all from a single MCP tool call. Payments handled automatically in USDC on Base mainnet via x402. No API key. No subscription. Pay per image.
4
+
5
+ Part of the [ForgeMesh](https://github.com/forgemeshlabs/forgemesh) ecosystem — infrastructure for autonomous agents.
6
+
7
+ ---
8
+
9
+ ## Tools
10
+
11
+ | Tool | What it does | Price |
12
+ |---|---|---|
13
+ | `generate_image` | Text-to-image generation | $0.10 USDC |
14
+ | `generate_clean` | Generate + background removal | $0.15 USDC |
15
+ | `generate_hd` | Generate + 4x upscale (HD) | $0.20 USDC |
16
+ | `generate_pro` | Generate + bg removal + 4x upscale | $0.30 USDC |
17
+
18
+ All tools accept `prompt` (required) and `aspect` (optional: `1:1`, `16:9`, `9:16`, `4:3`).
19
+
20
+ ---
21
+
22
+ ## Install
23
+
24
+ ### Claude Desktop
25
+
26
+ Add to `claude_desktop_config.json`:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "forgemesh-imagegen": {
32
+ "command": "npx",
33
+ "args": ["-y", "forgemesh-imagegen"],
34
+ "env": {
35
+ "WALLET_PRIVATE_KEY": "0x..."
36
+ }
37
+ }
38
+ }
39
+ }
40
+ ```
41
+
42
+ ### Claude Code
43
+
44
+ ```bash
45
+ claude mcp add forgemesh-imagegen -- npx -y forgemesh-imagegen
46
+ ```
47
+
48
+ Then set the env var:
49
+ ```bash
50
+ export WALLET_PRIVATE_KEY=0x...
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Requirements
56
+
57
+ - A Base mainnet wallet private key with USDC
58
+ - $1 USDC ≈ 10 base images, 6 clean, 5 HD, or 3 pro
59
+ - No other API keys needed
60
+
61
+ Get USDC on Base: [Coinbase](https://coinbase.com) → Bridge to Base, or buy directly on Base.
62
+
63
+ ---
64
+
65
+ ## Example usage
66
+
67
+ ```
68
+ generate_image(prompt="a red panda in a spacesuit", aspect="1:1")
69
+ → { image_url: "https://...", prompt: "...", aspect: "1:1", tier: "image" }
70
+
71
+ generate_clean(prompt="a product photo of a ceramic mug")
72
+ → { image_url: "https://...", tier: "clean" } // transparent PNG
73
+
74
+ generate_hd(prompt="a futuristic city at night, cyberpunk style")
75
+ → { image_url: "https://...", tier: "hd" } // 4096x4096
76
+
77
+ generate_pro(prompt="a logo mark, geometric eagle")
78
+ → { image_url: "https://...", tier: "pro" } // transparent + HD
79
+ ```
80
+
81
+ ---
82
+
83
+ ## How it works
84
+
85
+ Each tool call makes an HTTP request to the ForgeMesh imagegen service gated by the [x402 protocol](https://x402.org). If payment is required, the MCP automatically signs and broadcasts a USDC transfer from your wallet on Base mainnet — then retries the request. You see the result, your wallet is charged, no manual steps.
86
+
87
+ - Network: Base mainnet (eip155:8453)
88
+ - Token: USDC
89
+ - Facilitator: Coinbase CDP
90
+
91
+ ---
92
+
93
+ ## Links
94
+
95
+ - [ForgeMesh](https://forgemesh.io) — ecosystem overview
96
+ - [GitHub](https://github.com/forgemeshlabs/forgemesh-imagegen)
97
+ - [x402 Protocol](https://x402.org)
98
+
99
+ ---
100
+
101
+ ## License
102
+
103
+ MIT © ForgeMesh Labs
package/index.js ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { Server } = require("@modelcontextprotocol/sdk/server/index.js");
5
+ const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
6
+ const { CallToolRequestSchema, ListToolsRequestSchema } = require("@modelcontextprotocol/sdk/types.js");
7
+ const { x402Client, x402HTTPClient } = require("@x402/core/client");
8
+ const { ExactEvmScheme } = require("@x402/evm/exact/client");
9
+ const { toClientEvmSigner } = require("@x402/evm");
10
+ const { privateKeyToAccount } = require("viem/accounts");
11
+
12
+ const BASE_URL = "https://imagegen.coinopai.com";
13
+ const VALID_ASPECTS = ["1:1", "16:9", "9:16", "4:3"];
14
+
15
+ const TOOLS = [
16
+ {
17
+ name: "generate_image",
18
+ description: "Generate an AI image from a text prompt. Returns a PNG image URL. Costs $0.10 USDC on Base mainnet — paid automatically.",
19
+ inputSchema: {
20
+ type: "object",
21
+ properties: {
22
+ prompt: { type: "string", description: "Text description of the image to generate" },
23
+ aspect: { type: "string", enum: VALID_ASPECTS, description: "Aspect ratio — 1:1 (default), 16:9, 9:16, 4:3" },
24
+ },
25
+ required: ["prompt"],
26
+ },
27
+ },
28
+ {
29
+ name: "generate_clean",
30
+ description: "Generate an AI image with the background removed. Returns a transparent PNG URL. Costs $0.15 USDC on Base mainnet.",
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {
34
+ prompt: { type: "string", description: "Text description of the subject (background will be removed)" },
35
+ aspect: { type: "string", enum: VALID_ASPECTS, description: "Aspect ratio — 1:1 (default), 16:9, 9:16, 4:3" },
36
+ },
37
+ required: ["prompt"],
38
+ },
39
+ },
40
+ {
41
+ name: "generate_hd",
42
+ description: "Generate an AI image upscaled to 4x resolution. Returns a high-resolution image URL. Costs $0.20 USDC on Base mainnet.",
43
+ inputSchema: {
44
+ type: "object",
45
+ properties: {
46
+ prompt: { type: "string", description: "Text description of the image to generate" },
47
+ aspect: { type: "string", enum: VALID_ASPECTS, description: "Aspect ratio — 1:1 (default), 16:9, 9:16, 4:3" },
48
+ },
49
+ required: ["prompt"],
50
+ },
51
+ },
52
+ {
53
+ name: "generate_pro",
54
+ description: "Generate an AI image with background removed AND upscaled 4x HD. The full pipeline. Costs $0.30 USDC on Base mainnet.",
55
+ inputSchema: {
56
+ type: "object",
57
+ properties: {
58
+ prompt: { type: "string", description: "Text description of the subject (background removed, then upscaled)" },
59
+ aspect: { type: "string", enum: VALID_ASPECTS, description: "Aspect ratio — 1:1 (default), 16:9, 9:16, 4:3" },
60
+ },
61
+ required: ["prompt"],
62
+ },
63
+ },
64
+ ];
65
+
66
+ const TOOL_ENDPOINTS = {
67
+ generate_image: { path: "/generate", price: "$0.10" },
68
+ generate_clean: { path: "/generate/clean", price: "$0.15" },
69
+ generate_hd: { path: "/generate/hd", price: "$0.20" },
70
+ generate_pro: { path: "/generate/pro", price: "$0.30" },
71
+ };
72
+
73
+ function buildHttpClient() {
74
+ const key = process.env.WALLET_PRIVATE_KEY;
75
+ if (!key) {
76
+ throw new Error(
77
+ "WALLET_PRIVATE_KEY required — set a Base wallet private key funded with USDC.\n" +
78
+ " generate_image = $0.10 | generate_clean = $0.15 | generate_hd = $0.20 | generate_pro = $0.30"
79
+ );
80
+ }
81
+ const pk = key.startsWith("0x") ? key : "0x" + key;
82
+ const account = privateKeyToAccount(pk);
83
+ const signer = toClientEvmSigner(account);
84
+ const coreClient = new x402Client().register("eip155:*", new ExactEvmScheme(signer));
85
+ return new x402HTTPClient(coreClient);
86
+ }
87
+
88
+ async function callPaid(httpClient, path, params) {
89
+ const url = new URL(BASE_URL + path);
90
+ if (params) Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
91
+
92
+ const res = await fetch(url.toString());
93
+
94
+ if (res.status === 402) {
95
+ let body;
96
+ try { body = await res.clone().json(); } catch (_) {}
97
+ const paymentRequired = httpClient.getPaymentRequiredResponse(
98
+ (name) => res.headers.get(name),
99
+ body
100
+ );
101
+ const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
102
+ const paidRes = await fetch(url.toString(), {
103
+ headers: httpClient.encodePaymentSignatureHeader(paymentPayload),
104
+ });
105
+ if (!paidRes.ok) {
106
+ const errBody = await paidRes.text().catch(() => paidRes.statusText);
107
+ throw new Error(`Payment failed — HTTP ${paidRes.status}: ${errBody.slice(0, 200)}`);
108
+ }
109
+ return paidRes.json();
110
+ }
111
+
112
+ if (!res.ok) {
113
+ const errBody = await res.text().catch(() => res.statusText);
114
+ throw new Error(`HTTP ${res.status}: ${errBody.slice(0, 200)}`);
115
+ }
116
+ return res.json();
117
+ }
118
+
119
+ async function main() {
120
+ let httpClient;
121
+ try {
122
+ httpClient = buildHttpClient();
123
+ } catch (e) {
124
+ process.stderr.write("[forgemesh-imagegen] " + e.message + "\n");
125
+ process.exit(1);
126
+ }
127
+
128
+ const server = new Server(
129
+ { name: "forgemesh-imagegen", version: "1.0.0" },
130
+ { capabilities: { tools: {} } }
131
+ );
132
+
133
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
134
+
135
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
136
+ const { name, arguments: args } = req.params;
137
+ try {
138
+ const endpoint = TOOL_ENDPOINTS[name];
139
+ if (!endpoint) throw new Error("Unknown tool: " + name);
140
+
141
+ if (!args.prompt || typeof args.prompt !== "string" || !args.prompt.trim()) {
142
+ throw new Error("prompt is required and must be a non-empty string");
143
+ }
144
+
145
+ const aspect = args.aspect || "1:1";
146
+ if (!VALID_ASPECTS.includes(aspect)) {
147
+ throw new Error(`Invalid aspect ratio '${aspect}'. Valid: ${VALID_ASPECTS.join(", ")}`);
148
+ }
149
+
150
+ const data = await callPaid(httpClient, endpoint.path, {
151
+ prompt: args.prompt.trim(),
152
+ aspect,
153
+ });
154
+
155
+ return {
156
+ content: [{
157
+ type: "text",
158
+ text: JSON.stringify({
159
+ image_url: data.image_url,
160
+ prompt: data.prompt,
161
+ aspect: data.aspect,
162
+ tier: name.replace("generate_", "") || "base",
163
+ generated_at: data.generated_at || new Date().toISOString(),
164
+ }, null, 2),
165
+ }],
166
+ };
167
+ } catch (e) {
168
+ return { content: [{ type: "text", text: "Error: " + e.message }], isError: true };
169
+ }
170
+ });
171
+
172
+ const transport = new StdioServerTransport();
173
+ await server.connect(transport);
174
+ }
175
+
176
+ main();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "forgemesh-imagegen",
3
+ "version": "1.0.0",
4
+ "mcpName": "io.github.forgemeshlabs/imagegen-mcp",
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
+ "main": "index.js",
7
+ "bin": {
8
+ "forgemesh-imagegen": "index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "start": "node index.js"
16
+ },
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "keywords": [
21
+ "mcp",
22
+ "model-context-protocol",
23
+ "imagegen",
24
+ "imagegen-mcp",
25
+ "image-generation",
26
+ "ai-image",
27
+ "image-upscaling",
28
+ "background-removal",
29
+ "forgemesh",
30
+ "x402",
31
+ "usdc",
32
+ "base",
33
+ "micropayments",
34
+ "agent-commerce",
35
+ "claude",
36
+ "ai-agents",
37
+ "generative-ai",
38
+ "text-to-image"
39
+ ],
40
+ "author": "ForgeMesh Labs",
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/forgemeshlabs/forgemesh-imagegen.git"
45
+ },
46
+ "homepage": "https://github.com/forgemeshlabs/forgemesh-imagegen",
47
+ "bugs": {
48
+ "url": "https://github.com/forgemeshlabs/forgemesh-imagegen/issues"
49
+ },
50
+ "dependencies": {
51
+ "@modelcontextprotocol/sdk": "^1.10.1",
52
+ "@x402/core": "^2.11.0",
53
+ "@x402/evm": "^2.11.0",
54
+ "viem": "^2.0.0"
55
+ }
56
+ }