pixlora-mcp 0.0.0-stage → 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.
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import readline from "node:readline";
5
+
6
+ const API_KEY = (process.env.PIXLORA_API_KEY || "").trim();
7
+ const BASE_URL = (process.env.PIXLORA_BASE_URL || "https://pixlora.io.vn").replace(/\/+$/, "");
8
+
9
+ const TOOLS = [
10
+ {
11
+ name: "check_credits",
12
+ description: "Kiểm tra thông tin tài khoản PIXLORA và số dư Credit hiện tại.",
13
+ inputSchema: { type: "object", properties: {} },
14
+ },
15
+ {
16
+ name: "generate_pixel_sprite",
17
+ description:
18
+ "Tạo ảnh Pixel Art 2D cho game (character, item, tileset, icon) và tùy chọn lưu thẳng thành file PNG vào dự án.",
19
+ inputSchema: {
20
+ type: "object",
21
+ required: ["prompt"],
22
+ properties: {
23
+ prompt: { type: "string", description: "Mô tả sprite cần tạo (Tiếng Việt hoặc Anh)." },
24
+ preset: {
25
+ type: "string",
26
+ enum: ["character", "item", "tileset", "icon"],
27
+ description: "Loại sprite (mặc định: character).",
28
+ },
29
+ model: {
30
+ type: "string",
31
+ description: 'Model AI, ví dụ "fal-ai/flux/schnell" (1 credit).',
32
+ },
33
+ outputPath: {
34
+ type: "string",
35
+ description: "Đường dẫn lưu file PNG trên máy (VD: assets/sprites/hero.png).",
36
+ },
37
+ },
38
+ },
39
+ },
40
+ {
41
+ name: "generate_game_sfx",
42
+ description:
43
+ "Tạo hiệu ứng âm thanh Game (8-Bit SFX, RPG Combat, UI Click, Loop BGM) và tùy chọn lưu thẳng file MP3.",
44
+ inputSchema: {
45
+ type: "object",
46
+ required: ["prompt"],
47
+ properties: {
48
+ prompt: { type: "string", description: "Mô tả âm thanh cần tạo." },
49
+ preset: {
50
+ type: "string",
51
+ enum: ["8bit-sfx", "rpg-combat", "ui-click", "ambient-loop", "bgm-chiptune"],
52
+ description: "Phong cách âm thanh (mặc định: 8bit-sfx).",
53
+ },
54
+ durationSeconds: {
55
+ type: "number",
56
+ description: "Thời lượng 0.5 – 22 giây (mặc định: 3).",
57
+ },
58
+ loop: { type: "boolean", description: "Bật lặp liền mạch." },
59
+ outputPath: {
60
+ type: "string",
61
+ description: "Đường dẫn lưu file MP3 trên máy (VD: assets/audio/slash.mp3).",
62
+ },
63
+ },
64
+ },
65
+ },
66
+ {
67
+ name: "convert_2d_to_3d",
68
+ description:
69
+ "Chuyển ảnh Sprite/Vật phẩm 2D sang mô hình 3D (.glb) kèm UV texture cho Unity, Godot, Blender.",
70
+ inputSchema: {
71
+ type: "object",
72
+ required: ["imageUrl"],
73
+ properties: {
74
+ imageUrl: { type: "string", description: "URL công khai của ảnh 2D." },
75
+ textureSize: { type: "number", enum: [512, 1024, 2048], description: "Kích thước texture (mặc định: 1024)." },
76
+ outputPath: {
77
+ type: "string",
78
+ description: "Đường dẫn lưu file GLB trên máy (VD: assets/models/sword.glb).",
79
+ },
80
+ },
81
+ },
82
+ },
83
+ {
84
+ name: "remove_background",
85
+ description: "Tách nền ảnh thành PNG trong suốt bằng BiRefNet v2 (0 Credit).",
86
+ inputSchema: {
87
+ type: "object",
88
+ required: ["imageUrl"],
89
+ properties: {
90
+ imageUrl: { type: "string", description: "URL công khai của ảnh." },
91
+ outputPath: {
92
+ type: "string",
93
+ description: "Đường dẫn lưu file PNG đã tách nền.",
94
+ },
95
+ },
96
+ },
97
+ },
98
+ ];
99
+
100
+ function send(msg) {
101
+ process.stdout.write(`${JSON.stringify(msg)}\n`);
102
+ }
103
+
104
+ async function callPixloraApi(endpoint, method = "POST", body = undefined) {
105
+ if (!API_KEY) {
106
+ throw new Error("Thiếu biến môi trường PIXLORA_API_KEY (pk_live_...).");
107
+ }
108
+ const res = await fetch(`${BASE_URL}${endpoint}`, {
109
+ method,
110
+ headers: {
111
+ Authorization: `Bearer ${API_KEY}`,
112
+ ...(body ? { "Content-Type": "application/json" } : {}),
113
+ },
114
+ ...(body ? { body: JSON.stringify(body) } : {}),
115
+ });
116
+ const data = await res.json();
117
+ if (!res.ok) {
118
+ throw new Error(data?.error || `HTTP ${res.status}`);
119
+ }
120
+ return data;
121
+ }
122
+
123
+ async function downloadToPath(url, outputPath) {
124
+ const res = await fetch(url);
125
+ if (!res.ok) throw new Error(`Không thể tải file từ ${url} (HTTP ${res.status})`);
126
+ const buf = Buffer.from(await res.arrayBuffer());
127
+ const absPath = path.resolve(outputPath);
128
+ fs.mkdirSync(path.dirname(absPath), { recursive: true });
129
+ fs.writeFileSync(absPath, buf);
130
+ return absPath;
131
+ }
132
+
133
+ async function handleToolCall(name, args) {
134
+ const outputPath = typeof args?.outputPath === "string" ? args.outputPath.trim() : "";
135
+
136
+ if (name === "check_credits") {
137
+ return await callPixloraApi("/api/auth/me", "GET");
138
+ }
139
+
140
+ if (name === "generate_pixel_sprite") {
141
+ const { outputPath: _omit, ...payload } = args || {};
142
+ const data = await callPixloraApi("/api/generate", "POST", payload);
143
+ if (outputPath && data.imageUrl) {
144
+ data.savedTo = await downloadToPath(data.imageUrl, outputPath);
145
+ }
146
+ return data;
147
+ }
148
+
149
+ if (name === "generate_game_sfx") {
150
+ const { outputPath: _omit, ...payload } = args || {};
151
+ const data = await callPixloraApi("/api/audio", "POST", payload);
152
+ if (outputPath && data.audioUrl) {
153
+ data.savedTo = await downloadToPath(data.audioUrl, outputPath);
154
+ }
155
+ return data;
156
+ }
157
+
158
+ if (name === "convert_2d_to_3d") {
159
+ const { outputPath: _omit, ...payload } = args || {};
160
+ const data = await callPixloraApi("/api/3d", "POST", payload);
161
+ if (outputPath && data.glbUrl) {
162
+ data.savedTo = await downloadToPath(data.glbUrl, outputPath);
163
+ }
164
+ return data;
165
+ }
166
+
167
+ if (name === "remove_background") {
168
+ const { outputPath: _omit, ...payload } = args || {};
169
+ const data = await callPixloraApi("/api/remove-bg", "POST", payload);
170
+ if (outputPath && data.imageUrl) {
171
+ data.savedTo = await downloadToPath(data.imageUrl, outputPath);
172
+ }
173
+ return data;
174
+ }
175
+
176
+ throw new Error(`Unknown tool: ${name}`);
177
+ }
178
+
179
+ const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
180
+
181
+ rl.on("line", async (line) => {
182
+ const trimmed = line.trim();
183
+ if (!trimmed) return;
184
+ let req;
185
+ try {
186
+ req = JSON.parse(trimmed);
187
+ } catch {
188
+ return;
189
+ }
190
+
191
+ const { id, method, params } = req;
192
+
193
+ if (method === "initialize") {
194
+ send({
195
+ jsonrpc: "2.0",
196
+ id,
197
+ result: {
198
+ protocolVersion: "2024-11-05",
199
+ capabilities: { tools: {} },
200
+ serverInfo: { name: "pixlora-mcp", version: "1.0.0" },
201
+ },
202
+ });
203
+ return;
204
+ }
205
+
206
+ if (method === "notifications/initialized") {
207
+ return;
208
+ }
209
+
210
+ if (method === "ping") {
211
+ send({ jsonrpc: "2.0", id, result: {} });
212
+ return;
213
+ }
214
+
215
+ if (method === "tools/list") {
216
+ send({ jsonrpc: "2.0", id, result: { tools: TOOLS } });
217
+ return;
218
+ }
219
+
220
+ if (method === "tools/call") {
221
+ const toolName = String(params?.name || "");
222
+ const args = params?.arguments || {};
223
+ try {
224
+ const result = await handleToolCall(toolName, args);
225
+ send({
226
+ jsonrpc: "2.0",
227
+ id,
228
+ result: {
229
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
230
+ },
231
+ });
232
+ } catch (err) {
233
+ send({
234
+ jsonrpc: "2.0",
235
+ id,
236
+ result: {
237
+ isError: true,
238
+ content: [
239
+ {
240
+ type: "text",
241
+ text: JSON.stringify({
242
+ error: err instanceof Error ? err.message : "Tool execution failed",
243
+ }),
244
+ },
245
+ ],
246
+ },
247
+ });
248
+ }
249
+ return;
250
+ }
251
+
252
+ if (id !== undefined && id !== null) {
253
+ send({
254
+ jsonrpc: "2.0",
255
+ id,
256
+ error: { code: -32601, message: `Method not found: ${method}` },
257
+ });
258
+ }
259
+ });
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "pixlora-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Official local MCP (stdio) server for PIXLORA — generate 2D Pixel Art, Game SFX, and 3D .glb directly into your game project.",
5
+ "type": "module",
6
+ "bin": {
7
+ "pixlora-mcp": "bin/pixlora-mcp.mjs"
8
+ },
9
+ "files": [
10
+ "bin/"
11
+ ],
12
+ "engines": {
13
+ "node": ">=18.0.0"
14
+ },
15
+ "license": "MIT"
16
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.