upres-cli 0.1.1 → 0.3.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.
- package/README.md +79 -37
- package/dist/cli.cjs +381 -251
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +383 -251
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +27 -13
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +5 -1
- package/dist/client.d.ts +5 -1
- package/dist/client.js +25 -12
- package/dist/client.js.map +1 -1
- package/dist/mcp.cjs +310 -0
- package/dist/mcp.cjs.map +1 -0
- package/dist/mcp.d.cts +6 -0
- package/dist/mcp.d.ts +6 -0
- package/dist/mcp.js +283 -0
- package/dist/mcp.js.map +1 -0
- package/dist/models.cjs +51 -214
- package/dist/models.cjs.map +1 -1
- package/dist/models.d.cts +5 -3
- package/dist/models.d.ts +5 -3
- package/dist/models.js +49 -214
- package/dist/models.js.map +1 -1
- package/dist/types.cjs +0 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +0 -0
- package/package.json +54 -12
- package/scripts/check-mcp-registry.sh +51 -0
- package/scripts/ensure-dist.mjs +15 -0
package/dist/mcp.cjs
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/mcp.ts
|
|
22
|
+
var mcp_exports = {};
|
|
23
|
+
__export(mcp_exports, {
|
|
24
|
+
handleMessage: () => handleMessage,
|
|
25
|
+
startStdio: () => startStdio
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(mcp_exports);
|
|
28
|
+
|
|
29
|
+
// src/models.ts
|
|
30
|
+
function scaleParam(maxScale) {
|
|
31
|
+
if (maxScale <= 1) return [];
|
|
32
|
+
const options = [];
|
|
33
|
+
for (let step = 2; step <= maxScale; step *= 2) options.push(step);
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
name: "scale",
|
|
37
|
+
type: "integer",
|
|
38
|
+
required: false,
|
|
39
|
+
default: 4,
|
|
40
|
+
options,
|
|
41
|
+
description: "Scale multiplier. Ignored when the alias does not enlarge."
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
function model(id, name, description, category, inputTypes, maxScale) {
|
|
46
|
+
const fileParam = category.startsWith("video") ? { name: "video", type: "string", required: true, description: "Video URL or file" } : category.startsWith("audio") ? { name: "audio", type: "string", required: true, description: "Audio URL or file" } : { name: "image", type: "string", required: true, description: "Image URL or file" };
|
|
47
|
+
return {
|
|
48
|
+
id,
|
|
49
|
+
name,
|
|
50
|
+
description,
|
|
51
|
+
category,
|
|
52
|
+
price: "One credit per stage that runs",
|
|
53
|
+
inputTypes,
|
|
54
|
+
params: [fileParam, ...scaleParam(maxScale)]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var MODELS = [
|
|
58
|
+
model("flare", "Flare", "Everyday photos, 2x-4x. Fastest and cheapest. Does not invent detail.", "image-upscale", ["image/*"], 4),
|
|
59
|
+
model("prism", "Prism", "Text, logos, screenshots and product shots. Keeps edges true, does not invent detail.", "image-upscale", ["image/*"], 4),
|
|
60
|
+
model("lumen", "Lumen", "Maximum detail recovery for print, up to 8x. Slower and dearer than Flare.", "image-upscale", ["image/*"], 8),
|
|
61
|
+
model("mirage", "Mirage", "Invents plausible new detail rather than recovering what was there. Good for art, wrong for documents.", "image-upscale", ["image/*"], 8),
|
|
62
|
+
model("hush", "Hush", "Faithful denoise. Same size as the source, nothing invented.", "image-clean", ["image/*"], 1),
|
|
63
|
+
model("keen", "Keen", "Deblur and sharpen. Same size as the source, does not invent texture.", "image-restore", ["image/*"], 1),
|
|
64
|
+
model("visage", "Visage", "Restores faces and leaves the rest of the frame alone. Does not enlarge.", "image-restore", ["image/*"], 1),
|
|
65
|
+
model("atelier", "Atelier", "Hush, then Visage if the photo looks like a portrait, then Lumen. A skipped face stage is free.", "image-studio", ["image/*"], 8),
|
|
66
|
+
model("motion", "Motion", "Fast 4K finish for AI-generated video. Frame-consistent, does not invent faces.", "video-upscale", ["video/*"], 4),
|
|
67
|
+
model("motion-x", "Motion X", "Cinema-grade video upscale. Noticeably slower and dearer per second than Motion.", "video-upscale", ["video/*"], 4),
|
|
68
|
+
model("still", "Still", "Temporal video denoise. Resolution stays put.", "video-clean", ["video/*"], 1),
|
|
69
|
+
model("cadence", "Cadence", "Frame interpolation. Does not enlarge the picture.", "video-restore", ["video/*"], 1),
|
|
70
|
+
model("atelier-x", "Atelier X", "Still, then Motion X. Two credits.", "video-studio", ["video/*"], 4),
|
|
71
|
+
model("voice", "Voice", "Speech denoise and bandwidth extension to 48 kHz. Not for music.", "audio-clean", ["audio/*"], 1)
|
|
72
|
+
];
|
|
73
|
+
var IMAGE_MODELS = MODELS.filter((m) => m.category.startsWith("image"));
|
|
74
|
+
var VIDEO_MODELS = MODELS.filter((m) => m.category.startsWith("video"));
|
|
75
|
+
var AUDIO_MODELS = MODELS.filter((m) => m.category.startsWith("audio"));
|
|
76
|
+
|
|
77
|
+
// src/mcp.ts
|
|
78
|
+
var VERSION = "0.3.0";
|
|
79
|
+
var DEFAULT_BASE_URL = "https://api.upres.ai/v1";
|
|
80
|
+
function apiKey() {
|
|
81
|
+
return process.env.UPRES_API_KEY ?? "";
|
|
82
|
+
}
|
|
83
|
+
function baseUrl() {
|
|
84
|
+
return process.env.UPRES_BASE_URL ?? DEFAULT_BASE_URL;
|
|
85
|
+
}
|
|
86
|
+
async function api(method, endpoint, body) {
|
|
87
|
+
const key = apiKey();
|
|
88
|
+
if (!key) {
|
|
89
|
+
throw new Error("UPRES_API_KEY is not set. Get a key at https://upres.ai/account/api-keys");
|
|
90
|
+
}
|
|
91
|
+
const res = await fetch(`${baseUrl()}${endpoint}`, {
|
|
92
|
+
method,
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: `Bearer ${key}`,
|
|
95
|
+
...body ? { "Content-Type": "application/json" } : {}
|
|
96
|
+
},
|
|
97
|
+
body: body ? JSON.stringify(body) : void 0
|
|
98
|
+
});
|
|
99
|
+
const data = await res.json().catch(() => ({}));
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
var TOOLS = [
|
|
106
|
+
{
|
|
107
|
+
name: "upres_list_models",
|
|
108
|
+
description: "List the 14 public UpRes aliases for image, video, and speech.",
|
|
109
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "upres_get_credits",
|
|
113
|
+
description: "Show recent job count for the authenticated UpRes API key as a quota proxy.",
|
|
114
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "upres_upscale_image",
|
|
118
|
+
description: "Submit an image job from a public URL. Upscale: flare, prism, lumen, mirage. Restore: hush, keen, visage, atelier. Scale is ignored when the alias does not enlarge.",
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: {
|
|
122
|
+
image_url: { type: "string", description: "Public HTTPS URL of the image" },
|
|
123
|
+
model: {
|
|
124
|
+
type: "string",
|
|
125
|
+
enum: IMAGE_MODELS.map((m) => m.id),
|
|
126
|
+
description: "Image alias. Default flare."
|
|
127
|
+
},
|
|
128
|
+
scale: { type: "integer", enum: [2, 4, 8], description: "Scale multiplier. Default 4. Ignored for hush, keen, and visage." }
|
|
129
|
+
},
|
|
130
|
+
required: ["image_url"],
|
|
131
|
+
additionalProperties: false
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "upres_upscale_video",
|
|
136
|
+
description: "Submit a video job from a public URL. motion and motion-x upscale. still denoises, cadence interpolates frames, atelier-x runs still then motion-x.",
|
|
137
|
+
inputSchema: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
video_url: { type: "string", description: "Public HTTPS URL of the video" },
|
|
141
|
+
model: {
|
|
142
|
+
type: "string",
|
|
143
|
+
enum: VIDEO_MODELS.map((m) => m.id),
|
|
144
|
+
description: "Video alias. Default motion."
|
|
145
|
+
},
|
|
146
|
+
scale: { type: "integer", enum: [2, 4], description: "Scale multiplier. Default 4. Ignored for still and cadence." }
|
|
147
|
+
},
|
|
148
|
+
required: ["video_url"],
|
|
149
|
+
additionalProperties: false
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "upres_enhance_audio",
|
|
154
|
+
description: "Submit a speech job from a public URL. voice denoises speech and extends it to 48 kHz. Music is not supported.",
|
|
155
|
+
inputSchema: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
audio_url: { type: "string", description: "Public HTTPS URL of wav, mp3, m4a, or flac speech" },
|
|
159
|
+
model: {
|
|
160
|
+
type: "string",
|
|
161
|
+
enum: AUDIO_MODELS.map((m) => m.id),
|
|
162
|
+
description: "Audio alias. Default voice."
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
required: ["audio_url"],
|
|
166
|
+
additionalProperties: false
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "upres_get_job",
|
|
171
|
+
description: "Get status and result_url of an UpRes job by id.",
|
|
172
|
+
inputSchema: {
|
|
173
|
+
type: "object",
|
|
174
|
+
properties: {
|
|
175
|
+
job_id: { type: "string", description: "Job UUID returned by an upscale tool" }
|
|
176
|
+
},
|
|
177
|
+
required: ["job_id"],
|
|
178
|
+
additionalProperties: false
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
];
|
|
182
|
+
function ok(id, result) {
|
|
183
|
+
return { jsonrpc: "2.0", id, result };
|
|
184
|
+
}
|
|
185
|
+
function fail(id, code, message) {
|
|
186
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
187
|
+
}
|
|
188
|
+
function text(obj) {
|
|
189
|
+
return { content: [{ type: "text", text: JSON.stringify(obj, null, 2) }] };
|
|
190
|
+
}
|
|
191
|
+
async function callTool(name, args) {
|
|
192
|
+
switch (name) {
|
|
193
|
+
case "upres_list_models":
|
|
194
|
+
return text(
|
|
195
|
+
MODELS.map((m) => ({
|
|
196
|
+
id: m.id,
|
|
197
|
+
name: m.name,
|
|
198
|
+
category: m.category,
|
|
199
|
+
description: m.description
|
|
200
|
+
}))
|
|
201
|
+
);
|
|
202
|
+
case "upres_get_credits": {
|
|
203
|
+
const jobs = await api("GET", "/jobs?limit=100");
|
|
204
|
+
const data = jobs.data ?? [];
|
|
205
|
+
return text({
|
|
206
|
+
recent_jobs: data.length,
|
|
207
|
+
completed: data.filter((j) => j.status === "completed").length,
|
|
208
|
+
pricing: "https://upres.ai/pricing"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
case "upres_upscale_image": {
|
|
212
|
+
const image_url = String(args.image_url ?? "");
|
|
213
|
+
if (!image_url) throw new Error("image_url is required");
|
|
214
|
+
const job = await api("POST", "/jobs", {
|
|
215
|
+
image_url,
|
|
216
|
+
model: args.model ?? "flare",
|
|
217
|
+
scale: args.scale ?? 4
|
|
218
|
+
});
|
|
219
|
+
return text(job);
|
|
220
|
+
}
|
|
221
|
+
case "upres_upscale_video": {
|
|
222
|
+
const video_url = String(args.video_url ?? "");
|
|
223
|
+
if (!video_url) throw new Error("video_url is required");
|
|
224
|
+
const job = await api("POST", "/jobs", {
|
|
225
|
+
image_url: video_url,
|
|
226
|
+
model: args.model ?? "motion",
|
|
227
|
+
scale: args.scale ?? 4
|
|
228
|
+
});
|
|
229
|
+
return text(job);
|
|
230
|
+
}
|
|
231
|
+
case "upres_enhance_audio": {
|
|
232
|
+
const audio_url = String(args.audio_url ?? "");
|
|
233
|
+
if (!audio_url) throw new Error("audio_url is required");
|
|
234
|
+
const job = await api("POST", "/jobs", {
|
|
235
|
+
image_url: audio_url,
|
|
236
|
+
model: args.model ?? "voice"
|
|
237
|
+
});
|
|
238
|
+
return text(job);
|
|
239
|
+
}
|
|
240
|
+
case "upres_get_job": {
|
|
241
|
+
const job_id = String(args.job_id ?? "");
|
|
242
|
+
if (!job_id) throw new Error("job_id is required");
|
|
243
|
+
const job = await api("GET", `/jobs/${job_id}`);
|
|
244
|
+
return text(job);
|
|
245
|
+
}
|
|
246
|
+
default:
|
|
247
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function handle(msg) {
|
|
251
|
+
const id = msg.id;
|
|
252
|
+
const method = String(msg.method ?? "");
|
|
253
|
+
if (msg.jsonrpc !== "2.0") return fail(id, -32600, "Invalid Request");
|
|
254
|
+
if (method === "initialize") {
|
|
255
|
+
return ok(id, {
|
|
256
|
+
protocolVersion: "2024-11-05",
|
|
257
|
+
capabilities: { tools: {} },
|
|
258
|
+
serverInfo: { name: "upres", version: VERSION }
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (method === "notifications/initialized" || method === "initialized") return null;
|
|
262
|
+
if (method === "ping") return ok(id, {});
|
|
263
|
+
if (method === "tools/list") return ok(id, { tools: TOOLS });
|
|
264
|
+
if (method === "tools/call") {
|
|
265
|
+
const params = msg.params ?? {};
|
|
266
|
+
const name = String(params.name ?? "");
|
|
267
|
+
const args = params.arguments ?? {};
|
|
268
|
+
try {
|
|
269
|
+
return ok(id, await callTool(name, args));
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return ok(id, {
|
|
272
|
+
isError: true,
|
|
273
|
+
content: [{ type: "text", text: e.message }]
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (id === void 0) return null;
|
|
278
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
279
|
+
}
|
|
280
|
+
async function handleMessage(msg) {
|
|
281
|
+
return handle(msg);
|
|
282
|
+
}
|
|
283
|
+
function startStdio() {
|
|
284
|
+
let buf = "";
|
|
285
|
+
process.stdin.setEncoding("utf8");
|
|
286
|
+
process.stdin.on("data", async (chunk) => {
|
|
287
|
+
buf += chunk;
|
|
288
|
+
while (true) {
|
|
289
|
+
const nl = buf.indexOf("\n");
|
|
290
|
+
if (nl < 0) break;
|
|
291
|
+
const line = buf.slice(0, nl).trim();
|
|
292
|
+
buf = buf.slice(nl + 1);
|
|
293
|
+
if (!line) continue;
|
|
294
|
+
let msg;
|
|
295
|
+
try {
|
|
296
|
+
msg = JSON.parse(line);
|
|
297
|
+
} catch {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const reply = await handle(msg);
|
|
301
|
+
if (reply) process.stdout.write(JSON.stringify(reply) + "\n");
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
306
|
+
0 && (module.exports = {
|
|
307
|
+
handleMessage,
|
|
308
|
+
startStdio
|
|
309
|
+
});
|
|
310
|
+
//# sourceMappingURL=mcp.cjs.map
|
package/dist/mcp.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp.ts","../src/models.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * UpRes MCP stdio server. Speaks JSON-RPC over stdin/stdout so Claude,\n * Cursor, and Hermes can upscale without a browser.\n *\n * UPRES_API_KEY=upres_... npx upres-cli mcp\n * claude mcp add upres -- npx -y upres-cli mcp\n */\nimport { AUDIO_MODELS, IMAGE_MODELS, MODELS, VIDEO_MODELS } from \"./models.js\";\n\nconst VERSION = \"0.3.0\";\nconst DEFAULT_BASE_URL = \"https://api.upres.ai/v1\";\n\ntype Json = Record<string, unknown>;\n\nfunction apiKey(): string {\n return process.env.UPRES_API_KEY ?? \"\";\n}\n\nfunction baseUrl(): string {\n return process.env.UPRES_BASE_URL ?? DEFAULT_BASE_URL;\n}\n\nasync function api<T>(method: string, endpoint: string, body?: unknown): Promise<T> {\n const key = apiKey();\n if (!key) {\n throw new Error(\"UPRES_API_KEY is not set. Get a key at https://upres.ai/account/api-keys\");\n }\n const res = await fetch(`${baseUrl()}${endpoint}`, {\n method,\n headers: {\n Authorization: `Bearer ${key}`,\n ...(body ? { \"Content-Type\": \"application/json\" } : {}),\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n const data = (await res.json().catch(() => ({}))) as T & { error?: string };\n if (!res.ok) {\n throw new Error(data.error ?? `HTTP ${res.status}`);\n }\n return data;\n}\n\nconst TOOLS = [\n {\n name: \"upres_list_models\",\n description: \"List the 14 public UpRes aliases for image, video, and speech.\",\n inputSchema: { type: \"object\", properties: {}, additionalProperties: false },\n },\n {\n name: \"upres_get_credits\",\n description: \"Show recent job count for the authenticated UpRes API key as a quota proxy.\",\n inputSchema: { type: \"object\", properties: {}, additionalProperties: false },\n },\n {\n name: \"upres_upscale_image\",\n description:\n \"Submit an image job from a public URL. Upscale: flare, prism, lumen, mirage. Restore: hush, keen, visage, atelier. Scale is ignored when the alias does not enlarge.\",\n inputSchema: {\n type: \"object\",\n properties: {\n image_url: { type: \"string\", description: \"Public HTTPS URL of the image\" },\n model: {\n type: \"string\",\n enum: IMAGE_MODELS.map((m) => m.id),\n description: \"Image alias. Default flare.\",\n },\n scale: { type: \"integer\", enum: [2, 4, 8], description: \"Scale multiplier. Default 4. Ignored for hush, keen, and visage.\" },\n },\n required: [\"image_url\"],\n additionalProperties: false,\n },\n },\n {\n name: \"upres_upscale_video\",\n description:\n \"Submit a video job from a public URL. motion and motion-x upscale. still denoises, cadence interpolates frames, atelier-x runs still then motion-x.\",\n inputSchema: {\n type: \"object\",\n properties: {\n video_url: { type: \"string\", description: \"Public HTTPS URL of the video\" },\n model: {\n type: \"string\",\n enum: VIDEO_MODELS.map((m) => m.id),\n description: \"Video alias. Default motion.\",\n },\n scale: { type: \"integer\", enum: [2, 4], description: \"Scale multiplier. Default 4. Ignored for still and cadence.\" },\n },\n required: [\"video_url\"],\n additionalProperties: false,\n },\n },\n {\n name: \"upres_enhance_audio\",\n description: \"Submit a speech job from a public URL. voice denoises speech and extends it to 48 kHz. Music is not supported.\",\n inputSchema: {\n type: \"object\",\n properties: {\n audio_url: { type: \"string\", description: \"Public HTTPS URL of wav, mp3, m4a, or flac speech\" },\n model: {\n type: \"string\",\n enum: AUDIO_MODELS.map((m) => m.id),\n description: \"Audio alias. Default voice.\",\n },\n },\n required: [\"audio_url\"],\n additionalProperties: false,\n },\n },\n {\n name: \"upres_get_job\",\n description: \"Get status and result_url of an UpRes job by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n job_id: { type: \"string\", description: \"Job UUID returned by an upscale tool\" },\n },\n required: [\"job_id\"],\n additionalProperties: false,\n },\n },\n];\n\nfunction ok(id: unknown, result: unknown) {\n return { jsonrpc: \"2.0\", id, result };\n}\n\nfunction fail(id: unknown, code: number, message: string) {\n return { jsonrpc: \"2.0\", id, error: { code, message } };\n}\n\nfunction text(obj: unknown) {\n return { content: [{ type: \"text\", text: JSON.stringify(obj, null, 2) }] };\n}\n\nasync function callTool(name: string, args: Json): Promise<unknown> {\n switch (name) {\n case \"upres_list_models\":\n return text(\n MODELS.map((m) => ({\n id: m.id,\n name: m.name,\n category: m.category,\n description: m.description,\n })),\n );\n case \"upres_get_credits\": {\n const jobs = await api<{ data: { status: string }[] }>(\"GET\", \"/jobs?limit=100\");\n const data = jobs.data ?? [];\n return text({\n recent_jobs: data.length,\n completed: data.filter((j) => j.status === \"completed\").length,\n pricing: \"https://upres.ai/pricing\",\n });\n }\n case \"upres_upscale_image\": {\n const image_url = String(args.image_url ?? \"\");\n if (!image_url) throw new Error(\"image_url is required\");\n const job = await api(\"POST\", \"/jobs\", {\n image_url,\n model: args.model ?? \"flare\",\n scale: args.scale ?? 4,\n });\n return text(job);\n }\n case \"upres_upscale_video\": {\n const video_url = String(args.video_url ?? \"\");\n if (!video_url) throw new Error(\"video_url is required\");\n const job = await api(\"POST\", \"/jobs\", {\n image_url: video_url,\n model: args.model ?? \"motion\",\n scale: args.scale ?? 4,\n });\n return text(job);\n }\n case \"upres_enhance_audio\": {\n const audio_url = String(args.audio_url ?? \"\");\n if (!audio_url) throw new Error(\"audio_url is required\");\n const job = await api(\"POST\", \"/jobs\", {\n image_url: audio_url,\n model: args.model ?? \"voice\",\n });\n return text(job);\n }\n case \"upres_get_job\": {\n const job_id = String(args.job_id ?? \"\");\n if (!job_id) throw new Error(\"job_id is required\");\n const job = await api(\"GET\", `/jobs/${job_id}`);\n return text(job);\n }\n default:\n throw new Error(`Unknown tool: ${name}`);\n }\n}\n\nasync function handle(msg: Json): Promise<Json | null> {\n const id = msg.id;\n const method = String(msg.method ?? \"\");\n if (msg.jsonrpc !== \"2.0\") return fail(id, -32600, \"Invalid Request\");\n\n if (method === \"initialize\") {\n return ok(id, {\n protocolVersion: \"2024-11-05\",\n capabilities: { tools: {} },\n serverInfo: { name: \"upres\", version: VERSION },\n });\n }\n if (method === \"notifications/initialized\" || method === \"initialized\") return null;\n if (method === \"ping\") return ok(id, {});\n if (method === \"tools/list\") return ok(id, { tools: TOOLS });\n if (method === \"tools/call\") {\n const params = (msg.params ?? {}) as Json;\n const name = String(params.name ?? \"\");\n const args = (params.arguments ?? {}) as Json;\n try {\n return ok(id, await callTool(name, args));\n } catch (e) {\n return ok(id, {\n isError: true,\n content: [{ type: \"text\", text: (e as Error).message }],\n });\n }\n }\n if (id === undefined) return null;\n return fail(id, -32601, `Method not found: ${method}`);\n}\n\nexport async function handleMessage(msg: Json): Promise<Json | null> {\n return handle(msg);\n}\n\nexport function startStdio(): void {\n let buf = \"\";\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", async (chunk: string) => {\n buf += chunk;\n while (true) {\n const nl = buf.indexOf(\"\\n\");\n if (nl < 0) break;\n const line = buf.slice(0, nl).trim();\n buf = buf.slice(nl + 1);\n if (!line) continue;\n let msg: Json;\n try {\n msg = JSON.parse(line) as Json;\n } catch {\n continue;\n }\n const reply = await handle(msg);\n if (reply) process.stdout.write(JSON.stringify(reply) + \"\\n\");\n }\n });\n}\n","import type { ModelDefinition } from \"./types.js\";\n\n// Synced with the public aliases in upres.ai server/contract/models.ts.\n// A job names one alias. Which backend serves it is ours to choose and can\n// change without notice — that is how a failing vendor stops being your outage.\n// Aliases with max scale 1 do not enlarge; the API stores scale 1 for them.\n\nfunction scaleParam(maxScale: number): ModelDefinition[\"params\"] {\n if (maxScale <= 1) return [];\n const options: number[] = [];\n for (let step = 2; step <= maxScale; step *= 2) options.push(step);\n return [\n {\n name: \"scale\",\n type: \"integer\",\n required: false,\n default: 4,\n options,\n description: \"Scale multiplier. Ignored when the alias does not enlarge.\",\n },\n ];\n}\n\nfunction model(\n id: string,\n name: string,\n description: string,\n category: ModelDefinition[\"category\"],\n inputTypes: string[],\n maxScale: number,\n): ModelDefinition {\n const fileParam =\n category.startsWith(\"video\")\n ? { name: \"video\", type: \"string\" as const, required: true, description: \"Video URL or file\" }\n : category.startsWith(\"audio\")\n ? { name: \"audio\", type: \"string\" as const, required: true, description: \"Audio URL or file\" }\n : { name: \"image\", type: \"string\" as const, required: true, description: \"Image URL or file\" };\n return {\n id,\n name,\n description,\n category,\n price: \"One credit per stage that runs\",\n inputTypes,\n params: [fileParam, ...scaleParam(maxScale)],\n };\n}\n\nexport const MODELS: ModelDefinition[] = [\n model(\"flare\", \"Flare\", \"Everyday photos, 2x-4x. Fastest and cheapest. Does not invent detail.\", \"image-upscale\", [\"image/*\"], 4),\n model(\"prism\", \"Prism\", \"Text, logos, screenshots and product shots. Keeps edges true, does not invent detail.\", \"image-upscale\", [\"image/*\"], 4),\n model(\"lumen\", \"Lumen\", \"Maximum detail recovery for print, up to 8x. Slower and dearer than Flare.\", \"image-upscale\", [\"image/*\"], 8),\n model(\"mirage\", \"Mirage\", \"Invents plausible new detail rather than recovering what was there. Good for art, wrong for documents.\", \"image-upscale\", [\"image/*\"], 8),\n model(\"hush\", \"Hush\", \"Faithful denoise. Same size as the source, nothing invented.\", \"image-clean\", [\"image/*\"], 1),\n model(\"keen\", \"Keen\", \"Deblur and sharpen. Same size as the source, does not invent texture.\", \"image-restore\", [\"image/*\"], 1),\n model(\"visage\", \"Visage\", \"Restores faces and leaves the rest of the frame alone. Does not enlarge.\", \"image-restore\", [\"image/*\"], 1),\n model(\"atelier\", \"Atelier\", \"Hush, then Visage if the photo looks like a portrait, then Lumen. A skipped face stage is free.\", \"image-studio\", [\"image/*\"], 8),\n model(\"motion\", \"Motion\", \"Fast 4K finish for AI-generated video. Frame-consistent, does not invent faces.\", \"video-upscale\", [\"video/*\"], 4),\n model(\"motion-x\", \"Motion X\", \"Cinema-grade video upscale. Noticeably slower and dearer per second than Motion.\", \"video-upscale\", [\"video/*\"], 4),\n model(\"still\", \"Still\", \"Temporal video denoise. Resolution stays put.\", \"video-clean\", [\"video/*\"], 1),\n model(\"cadence\", \"Cadence\", \"Frame interpolation. Does not enlarge the picture.\", \"video-restore\", [\"video/*\"], 1),\n model(\"atelier-x\", \"Atelier X\", \"Still, then Motion X. Two credits.\", \"video-studio\", [\"video/*\"], 4),\n model(\"voice\", \"Voice\", \"Speech denoise and bandwidth extension to 48 kHz. Not for music.\", \"audio-clean\", [\"audio/*\"], 1),\n];\n\nexport const IMAGE_MODELS = MODELS.filter((m) => m.category.startsWith(\"image\"));\nexport const VIDEO_MODELS = MODELS.filter((m) => m.category.startsWith(\"video\"));\nexport const AUDIO_MODELS = MODELS.filter((m) => m.category.startsWith(\"audio\"));\nexport const DEFAULT_IMAGE_MODEL = \"flare\";\nexport const DEFAULT_VIDEO_MODEL = \"motion\";\nexport const DEFAULT_AUDIO_MODEL = \"voice\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,SAAS,WAAW,UAA6C;AAC/D,MAAI,YAAY,EAAG,QAAO,CAAC;AAC3B,QAAM,UAAoB,CAAC;AAC3B,WAAS,OAAO,GAAG,QAAQ,UAAU,QAAQ,EAAG,SAAQ,KAAK,IAAI;AACjE,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,MACT;AAAA,MACA,aAAa;AAAA,IACf;AAAA,EACF;AACF;AAEA,SAAS,MACP,IACA,MACA,aACA,UACA,YACA,UACiB;AACjB,QAAM,YACJ,SAAS,WAAW,OAAO,IACvB,EAAE,MAAM,SAAS,MAAM,UAAmB,UAAU,MAAM,aAAa,oBAAoB,IAC3F,SAAS,WAAW,OAAO,IACzB,EAAE,MAAM,SAAS,MAAM,UAAmB,UAAU,MAAM,aAAa,oBAAoB,IAC3F,EAAE,MAAM,SAAS,MAAM,UAAmB,UAAU,MAAM,aAAa,oBAAoB;AACnG,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,QAAQ,CAAC,WAAW,GAAG,WAAW,QAAQ,CAAC;AAAA,EAC7C;AACF;AAEO,IAAM,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aleParam(maxScale) {
|
|
5
|
+
if (maxScale <= 1) return [];
|
|
6
|
+
const options = [];
|
|
7
|
+
for (let step = 2; step <= maxScale; step *= 2) options.push(step);
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "scale",
|
|
11
|
+
type: "integer",
|
|
12
|
+
required: false,
|
|
13
|
+
default: 4,
|
|
14
|
+
options,
|
|
15
|
+
description: "Scale multiplier. Ignored when the alias does not enlarge."
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
function model(id, name, description, category, inputTypes, maxScale) {
|
|
20
|
+
const fileParam = category.startsWith("video") ? { name: "video", type: "string", required: true, description: "Video URL or file" } : category.startsWith("audio") ? { name: "audio", type: "string", required: true, description: "Audio URL or file" } : { name: "image", type: "string", required: true, description: "Image URL or file" };
|
|
21
|
+
return {
|
|
22
|
+
id,
|
|
23
|
+
name,
|
|
24
|
+
description,
|
|
25
|
+
category,
|
|
26
|
+
price: "One credit per stage that runs",
|
|
27
|
+
inputTypes,
|
|
28
|
+
params: [fileParam, ...scaleParam(maxScale)]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var MODELS = [
|
|
32
|
+
model("flare", "Flare", "Everyday photos, 2x-4x. Fastest and cheapest. Does not invent detail.", "image-upscale", ["image/*"], 4),
|
|
33
|
+
model("prism", "Prism", "Text, logos, screenshots and product shots. Keeps edges true, does not invent detail.", "image-upscale", ["image/*"], 4),
|
|
34
|
+
model("lumen", "Lumen", "Maximum detail recovery for print, up to 8x. Slower and dearer than Flare.", "image-upscale", ["image/*"], 8),
|
|
35
|
+
model("mirage", "Mirage", "Invents plausible new detail rather than recovering what was there. Good for art, wrong for documents.", "image-upscale", ["image/*"], 8),
|
|
36
|
+
model("hush", "Hush", "Faithful denoise. Same size as the source, nothing invented.", "image-clean", ["image/*"], 1),
|
|
37
|
+
model("keen", "Keen", "Deblur and sharpen. Same size as the source, does not invent texture.", "image-restore", ["image/*"], 1),
|
|
38
|
+
model("visage", "Visage", "Restores faces and leaves the rest of the frame alone. Does not enlarge.", "image-restore", ["image/*"], 1),
|
|
39
|
+
model("atelier", "Atelier", "Hush, then Visage if the photo looks like a portrait, then Lumen. A skipped face stage is free.", "image-studio", ["image/*"], 8),
|
|
40
|
+
model("motion", "Motion", "Fast 4K finish for AI-generated video. Frame-consistent, does not invent faces.", "video-upscale", ["video/*"], 4),
|
|
41
|
+
model("motion-x", "Motion X", "Cinema-grade video upscale. Noticeably slower and dearer per second than Motion.", "video-upscale", ["video/*"], 4),
|
|
42
|
+
model("still", "Still", "Temporal video denoise. Resolution stays put.", "video-clean", ["video/*"], 1),
|
|
43
|
+
model("cadence", "Cadence", "Frame interpolation. Does not enlarge the picture.", "video-restore", ["video/*"], 1),
|
|
44
|
+
model("atelier-x", "Atelier X", "Still, then Motion X. Two credits.", "video-studio", ["video/*"], 4),
|
|
45
|
+
model("voice", "Voice", "Speech denoise and bandwidth extension to 48 kHz. Not for music.", "audio-clean", ["audio/*"], 1)
|
|
46
|
+
];
|
|
47
|
+
var IMAGE_MODELS = MODELS.filter((m) => m.category.startsWith("image"));
|
|
48
|
+
var VIDEO_MODELS = MODELS.filter((m) => m.category.startsWith("video"));
|
|
49
|
+
var AUDIO_MODELS = MODELS.filter((m) => m.category.startsWith("audio"));
|
|
50
|
+
|
|
51
|
+
// src/mcp.ts
|
|
52
|
+
var VERSION = "0.3.0";
|
|
53
|
+
var DEFAULT_BASE_URL = "https://api.upres.ai/v1";
|
|
54
|
+
function apiKey() {
|
|
55
|
+
return process.env.UPRES_API_KEY ?? "";
|
|
56
|
+
}
|
|
57
|
+
function baseUrl() {
|
|
58
|
+
return process.env.UPRES_BASE_URL ?? DEFAULT_BASE_URL;
|
|
59
|
+
}
|
|
60
|
+
async function api(method, endpoint, body) {
|
|
61
|
+
const key = apiKey();
|
|
62
|
+
if (!key) {
|
|
63
|
+
throw new Error("UPRES_API_KEY is not set. Get a key at https://upres.ai/account/api-keys");
|
|
64
|
+
}
|
|
65
|
+
const res = await fetch(`${baseUrl()}${endpoint}`, {
|
|
66
|
+
method,
|
|
67
|
+
headers: {
|
|
68
|
+
Authorization: `Bearer ${key}`,
|
|
69
|
+
...body ? { "Content-Type": "application/json" } : {}
|
|
70
|
+
},
|
|
71
|
+
body: body ? JSON.stringify(body) : void 0
|
|
72
|
+
});
|
|
73
|
+
const data = await res.json().catch(() => ({}));
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
76
|
+
}
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
var TOOLS = [
|
|
80
|
+
{
|
|
81
|
+
name: "upres_list_models",
|
|
82
|
+
description: "List the 14 public UpRes aliases for image, video, and speech.",
|
|
83
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "upres_get_credits",
|
|
87
|
+
description: "Show recent job count for the authenticated UpRes API key as a quota proxy.",
|
|
88
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "upres_upscale_image",
|
|
92
|
+
description: "Submit an image job from a public URL. Upscale: flare, prism, lumen, mirage. Restore: hush, keen, visage, atelier. Scale is ignored when the alias does not enlarge.",
|
|
93
|
+
inputSchema: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
image_url: { type: "string", description: "Public HTTPS URL of the image" },
|
|
97
|
+
model: {
|
|
98
|
+
type: "string",
|
|
99
|
+
enum: IMAGE_MODELS.map((m) => m.id),
|
|
100
|
+
description: "Image alias. Default flare."
|
|
101
|
+
},
|
|
102
|
+
scale: { type: "integer", enum: [2, 4, 8], description: "Scale multiplier. Default 4. Ignored for hush, keen, and visage." }
|
|
103
|
+
},
|
|
104
|
+
required: ["image_url"],
|
|
105
|
+
additionalProperties: false
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "upres_upscale_video",
|
|
110
|
+
description: "Submit a video job from a public URL. motion and motion-x upscale. still denoises, cadence interpolates frames, atelier-x runs still then motion-x.",
|
|
111
|
+
inputSchema: {
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: {
|
|
114
|
+
video_url: { type: "string", description: "Public HTTPS URL of the video" },
|
|
115
|
+
model: {
|
|
116
|
+
type: "string",
|
|
117
|
+
enum: VIDEO_MODELS.map((m) => m.id),
|
|
118
|
+
description: "Video alias. Default motion."
|
|
119
|
+
},
|
|
120
|
+
scale: { type: "integer", enum: [2, 4], description: "Scale multiplier. Default 4. Ignored for still and cadence." }
|
|
121
|
+
},
|
|
122
|
+
required: ["video_url"],
|
|
123
|
+
additionalProperties: false
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "upres_enhance_audio",
|
|
128
|
+
description: "Submit a speech job from a public URL. voice denoises speech and extends it to 48 kHz. Music is not supported.",
|
|
129
|
+
inputSchema: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
audio_url: { type: "string", description: "Public HTTPS URL of wav, mp3, m4a, or flac speech" },
|
|
133
|
+
model: {
|
|
134
|
+
type: "string",
|
|
135
|
+
enum: AUDIO_MODELS.map((m) => m.id),
|
|
136
|
+
description: "Audio alias. Default voice."
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
required: ["audio_url"],
|
|
140
|
+
additionalProperties: false
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "upres_get_job",
|
|
145
|
+
description: "Get status and result_url of an UpRes job by id.",
|
|
146
|
+
inputSchema: {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: {
|
|
149
|
+
job_id: { type: "string", description: "Job UUID returned by an upscale tool" }
|
|
150
|
+
},
|
|
151
|
+
required: ["job_id"],
|
|
152
|
+
additionalProperties: false
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
function ok(id, result) {
|
|
157
|
+
return { jsonrpc: "2.0", id, result };
|
|
158
|
+
}
|
|
159
|
+
function fail(id, code, message) {
|
|
160
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
161
|
+
}
|
|
162
|
+
function text(obj) {
|
|
163
|
+
return { content: [{ type: "text", text: JSON.stringify(obj, null, 2) }] };
|
|
164
|
+
}
|
|
165
|
+
async function callTool(name, args) {
|
|
166
|
+
switch (name) {
|
|
167
|
+
case "upres_list_models":
|
|
168
|
+
return text(
|
|
169
|
+
MODELS.map((m) => ({
|
|
170
|
+
id: m.id,
|
|
171
|
+
name: m.name,
|
|
172
|
+
category: m.category,
|
|
173
|
+
description: m.description
|
|
174
|
+
}))
|
|
175
|
+
);
|
|
176
|
+
case "upres_get_credits": {
|
|
177
|
+
const jobs = await api("GET", "/jobs?limit=100");
|
|
178
|
+
const data = jobs.data ?? [];
|
|
179
|
+
return text({
|
|
180
|
+
recent_jobs: data.length,
|
|
181
|
+
completed: data.filter((j) => j.status === "completed").length,
|
|
182
|
+
pricing: "https://upres.ai/pricing"
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
case "upres_upscale_image": {
|
|
186
|
+
const image_url = String(args.image_url ?? "");
|
|
187
|
+
if (!image_url) throw new Error("image_url is required");
|
|
188
|
+
const job = await api("POST", "/jobs", {
|
|
189
|
+
image_url,
|
|
190
|
+
model: args.model ?? "flare",
|
|
191
|
+
scale: args.scale ?? 4
|
|
192
|
+
});
|
|
193
|
+
return text(job);
|
|
194
|
+
}
|
|
195
|
+
case "upres_upscale_video": {
|
|
196
|
+
const video_url = String(args.video_url ?? "");
|
|
197
|
+
if (!video_url) throw new Error("video_url is required");
|
|
198
|
+
const job = await api("POST", "/jobs", {
|
|
199
|
+
image_url: video_url,
|
|
200
|
+
model: args.model ?? "motion",
|
|
201
|
+
scale: args.scale ?? 4
|
|
202
|
+
});
|
|
203
|
+
return text(job);
|
|
204
|
+
}
|
|
205
|
+
case "upres_enhance_audio": {
|
|
206
|
+
const audio_url = String(args.audio_url ?? "");
|
|
207
|
+
if (!audio_url) throw new Error("audio_url is required");
|
|
208
|
+
const job = await api("POST", "/jobs", {
|
|
209
|
+
image_url: audio_url,
|
|
210
|
+
model: args.model ?? "voice"
|
|
211
|
+
});
|
|
212
|
+
return text(job);
|
|
213
|
+
}
|
|
214
|
+
case "upres_get_job": {
|
|
215
|
+
const job_id = String(args.job_id ?? "");
|
|
216
|
+
if (!job_id) throw new Error("job_id is required");
|
|
217
|
+
const job = await api("GET", `/jobs/${job_id}`);
|
|
218
|
+
return text(job);
|
|
219
|
+
}
|
|
220
|
+
default:
|
|
221
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function handle(msg) {
|
|
225
|
+
const id = msg.id;
|
|
226
|
+
const method = String(msg.method ?? "");
|
|
227
|
+
if (msg.jsonrpc !== "2.0") return fail(id, -32600, "Invalid Request");
|
|
228
|
+
if (method === "initialize") {
|
|
229
|
+
return ok(id, {
|
|
230
|
+
protocolVersion: "2024-11-05",
|
|
231
|
+
capabilities: { tools: {} },
|
|
232
|
+
serverInfo: { name: "upres", version: VERSION }
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (method === "notifications/initialized" || method === "initialized") return null;
|
|
236
|
+
if (method === "ping") return ok(id, {});
|
|
237
|
+
if (method === "tools/list") return ok(id, { tools: TOOLS });
|
|
238
|
+
if (method === "tools/call") {
|
|
239
|
+
const params = msg.params ?? {};
|
|
240
|
+
const name = String(params.name ?? "");
|
|
241
|
+
const args = params.arguments ?? {};
|
|
242
|
+
try {
|
|
243
|
+
return ok(id, await callTool(name, args));
|
|
244
|
+
} catch (e) {
|
|
245
|
+
return ok(id, {
|
|
246
|
+
isError: true,
|
|
247
|
+
content: [{ type: "text", text: e.message }]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (id === void 0) return null;
|
|
252
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
253
|
+
}
|
|
254
|
+
async function handleMessage(msg) {
|
|
255
|
+
return handle(msg);
|
|
256
|
+
}
|
|
257
|
+
function startStdio() {
|
|
258
|
+
let buf = "";
|
|
259
|
+
process.stdin.setEncoding("utf8");
|
|
260
|
+
process.stdin.on("data", async (chunk) => {
|
|
261
|
+
buf += chunk;
|
|
262
|
+
while (true) {
|
|
263
|
+
const nl = buf.indexOf("\n");
|
|
264
|
+
if (nl < 0) break;
|
|
265
|
+
const line = buf.slice(0, nl).trim();
|
|
266
|
+
buf = buf.slice(nl + 1);
|
|
267
|
+
if (!line) continue;
|
|
268
|
+
let msg;
|
|
269
|
+
try {
|
|
270
|
+
msg = JSON.parse(line);
|
|
271
|
+
} catch {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const reply = await handle(msg);
|
|
275
|
+
if (reply) process.stdout.write(JSON.stringify(reply) + "\n");
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
export {
|
|
280
|
+
handleMessage,
|
|
281
|
+
startStdio
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=mcp.js.map
|