@simpligen/mcp 0.2.0 → 0.3.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/package.json +1 -1
- package/src/client.js +98 -95
- package/src/tools.js +19 -1
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,95 +1,98 @@
|
|
|
1
|
-
// packages/mcp-server/src/client.js
|
|
2
|
-
// Thin client over the SimpliGen local control API. Resolves base URL + token,
|
|
3
|
-
// does authed fetch calls, throws a structured error on non-2xx.
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { resolveUserDataDir, readDiscoveryPort } from './userdata.js';
|
|
7
|
-
|
|
8
|
-
export class ControlApiError extends Error {
|
|
9
|
-
constructor(status, errorCode, message) {
|
|
10
|
-
super(message || errorCode || `HTTP ${status}`);
|
|
11
|
-
this.name = 'ControlApiError';
|
|
12
|
-
this.status = status;
|
|
13
|
-
this.errorCode = errorCode || null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class ControlApiClient {
|
|
18
|
-
// opts: { baseUrl?, token?, fetchImpl?, env? }. Falls back to discovery file + env.
|
|
19
|
-
constructor(opts = {}) {
|
|
20
|
-
const env = opts.env || process.env;
|
|
21
|
-
this.token = opts.token || env.SIMPLIGEN_TOKEN || null;
|
|
22
|
-
this.fetch = opts.fetchImpl || globalThis.fetch;
|
|
23
|
-
if (opts.baseUrl) {
|
|
24
|
-
this.baseUrl = opts.baseUrl;
|
|
25
|
-
} else {
|
|
26
|
-
const port = env.SIMPLIGEN_API_PORT ? Number(env.SIMPLIGEN_API_PORT) : readDiscoveryPort(resolveUserDataDir(env));
|
|
27
|
-
this.baseUrl = port ? `http://127.0.0.1:${port}` : null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async #req(method, p, body) {
|
|
32
|
-
if (!this.baseUrl) throw new ControlApiError(0, 'app_not_running', 'SimpliGen is not running (no control-API port found). Start the app.');
|
|
33
|
-
if (!this.token) throw new ControlApiError(0, 'missing_token', 'No pairing token. Set SIMPLIGEN_TOKEN (Settings -> Connect an agent).');
|
|
34
|
-
const res = await this.fetch(`${this.baseUrl}${p}`, {
|
|
35
|
-
method,
|
|
36
|
-
headers: { Authorization: `Bearer ${this.token}`, 'Content-Type': 'application/json' },
|
|
37
|
-
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
38
|
-
});
|
|
39
|
-
let json = {};
|
|
40
|
-
try { json = await res.json(); } catch { /* empty body */ }
|
|
41
|
-
if (!res.ok) throw new ControlApiError(res.status, json.errorCode, json.message);
|
|
42
|
-
return json;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getCapabilities() { return this.#req('GET', '/capabilities'); }
|
|
46
|
-
getStatus() { return this.#req('GET', '/status'); }
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
1
|
+
// packages/mcp-server/src/client.js
|
|
2
|
+
// Thin client over the SimpliGen local control API. Resolves base URL + token,
|
|
3
|
+
// does authed fetch calls, throws a structured error on non-2xx.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { resolveUserDataDir, readDiscoveryPort } from './userdata.js';
|
|
7
|
+
|
|
8
|
+
export class ControlApiError extends Error {
|
|
9
|
+
constructor(status, errorCode, message) {
|
|
10
|
+
super(message || errorCode || `HTTP ${status}`);
|
|
11
|
+
this.name = 'ControlApiError';
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.errorCode = errorCode || null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ControlApiClient {
|
|
18
|
+
// opts: { baseUrl?, token?, fetchImpl?, env? }. Falls back to discovery file + env.
|
|
19
|
+
constructor(opts = {}) {
|
|
20
|
+
const env = opts.env || process.env;
|
|
21
|
+
this.token = opts.token || env.SIMPLIGEN_TOKEN || null;
|
|
22
|
+
this.fetch = opts.fetchImpl || globalThis.fetch;
|
|
23
|
+
if (opts.baseUrl) {
|
|
24
|
+
this.baseUrl = opts.baseUrl;
|
|
25
|
+
} else {
|
|
26
|
+
const port = env.SIMPLIGEN_API_PORT ? Number(env.SIMPLIGEN_API_PORT) : readDiscoveryPort(resolveUserDataDir(env));
|
|
27
|
+
this.baseUrl = port ? `http://127.0.0.1:${port}` : null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async #req(method, p, body) {
|
|
32
|
+
if (!this.baseUrl) throw new ControlApiError(0, 'app_not_running', 'SimpliGen is not running (no control-API port found). Start the app.');
|
|
33
|
+
if (!this.token) throw new ControlApiError(0, 'missing_token', 'No pairing token. Set SIMPLIGEN_TOKEN (Settings -> Connect an agent).');
|
|
34
|
+
const res = await this.fetch(`${this.baseUrl}${p}`, {
|
|
35
|
+
method,
|
|
36
|
+
headers: { Authorization: `Bearer ${this.token}`, 'Content-Type': 'application/json' },
|
|
37
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
38
|
+
});
|
|
39
|
+
let json = {};
|
|
40
|
+
try { json = await res.json(); } catch { /* empty body */ }
|
|
41
|
+
if (!res.ok) throw new ControlApiError(res.status, json.errorCode, json.message);
|
|
42
|
+
return json;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getCapabilities() { return this.#req('GET', '/capabilities'); }
|
|
46
|
+
getStatus() { return this.#req('GET', '/status'); }
|
|
47
|
+
startEngine() { return this.#req('POST', '/engine/start'); }
|
|
48
|
+
stopEngine() { return this.#req('POST', '/engine/stop'); }
|
|
49
|
+
restartEngine() { return this.#req('POST', '/engine/restart'); }
|
|
50
|
+
listProjects() { return this.#req('GET', '/projects'); }
|
|
51
|
+
createProject(name) { return this.#req('POST', '/projects', { name }); }
|
|
52
|
+
listLoras() { return this.#req('GET', '/loras'); }
|
|
53
|
+
generate(args) { return this.#req('POST', '/generate', args); }
|
|
54
|
+
getJob(id) { return this.#req('GET', `/jobs/${encodeURIComponent(id)}`); }
|
|
55
|
+
listJobs() { return this.#req('GET', '/jobs'); }
|
|
56
|
+
cancelJob(id) { return this.#req('POST', `/jobs/${encodeURIComponent(id)}/cancel`, {}); }
|
|
57
|
+
preparePreset(args) { return this.#req('POST', '/presets/prepare', args); }
|
|
58
|
+
getActiveDownloads() { return this.#req('GET', '/presets/prepare'); }
|
|
59
|
+
|
|
60
|
+
listCharacters() { return this.#req('GET', '/characters'); }
|
|
61
|
+
getCharacter(id) { return this.#req('GET', `/characters/${encodeURIComponent(id)}`); }
|
|
62
|
+
listCharacterFeatures() { return this.#req('GET', '/character-features'); }
|
|
63
|
+
listCharacterPresets() { return this.#req('GET', '/character-presets'); }
|
|
64
|
+
createCharacter(args) { return this.#req('POST', '/characters', args); }
|
|
65
|
+
generateCharacterImage(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-image`, args); }
|
|
66
|
+
generateCharacterFrame(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-frame`, args); }
|
|
67
|
+
animateCharacter(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/animate`, args); }
|
|
68
|
+
acceptBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/accept-base`, args); }
|
|
69
|
+
setCharacterPreset(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/preset`, args); }
|
|
70
|
+
enhanceCharacterMedia(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/enhance`, args); }
|
|
71
|
+
regenerateCharacterBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/regenerate-base`, args); }
|
|
72
|
+
removeCharacter(id) { return this.#req('DELETE', `/characters/${encodeURIComponent(id)}`); }
|
|
73
|
+
|
|
74
|
+
listRecipeBlocks() { return this.#req('GET', '/recipe-blocks'); }
|
|
75
|
+
composeRecipe(args) { return this.#req('POST', '/recipes', args); }
|
|
76
|
+
validateRecipe(args) { return this.#req('POST', '/recipes/validate', args); }
|
|
77
|
+
listRecipes() { return this.#req('GET', '/recipes'); }
|
|
78
|
+
getRecipe(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}`); }
|
|
79
|
+
publishRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/publish`, args); }
|
|
80
|
+
runRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/run`, args); }
|
|
81
|
+
listRecipeRuns(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}/runs`); }
|
|
82
|
+
getRecipeRun(runId) { return this.#req('GET', `/recipe-runs/${encodeURIComponent(runId)}`); }
|
|
83
|
+
cancelRecipeRun(runId) { return this.#req('POST', `/recipe-runs/${encodeURIComponent(runId)}/cancel`, {}); }
|
|
84
|
+
listSubjects() { return this.#req('GET', '/subjects'); }
|
|
85
|
+
listProducts() { return this.#req('GET', '/products'); }
|
|
86
|
+
createProduct(args) { return this.#req('POST', '/products', args); }
|
|
87
|
+
removeProduct(id) { return this.#req('DELETE', `/products/${encodeURIComponent(id)}`); }
|
|
88
|
+
|
|
89
|
+
async uploadFile(filePath) {
|
|
90
|
+
let buf;
|
|
91
|
+
try {
|
|
92
|
+
buf = fs.readFileSync(filePath);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw new ControlApiError(0, 'file_not_found', `Cannot read file to upload: ${filePath} (${e.code || e.message}).`);
|
|
95
|
+
}
|
|
96
|
+
return this.#req('POST', '/uploads', { filename: path.basename(filePath), dataBase64: buf.toString('base64') });
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/tools.js
CHANGED
|
@@ -6,7 +6,8 @@ import { z } from 'zod';
|
|
|
6
6
|
import { buildResultImageContent } from './resultImage.js';
|
|
7
7
|
|
|
8
8
|
export const TOOL_NAMES = [
|
|
9
|
-
'list_capabilities', 'get_status', '
|
|
9
|
+
'list_capabilities', 'get_status', 'start_engine', 'stop_engine', 'restart_engine',
|
|
10
|
+
'list_projects', 'create_project',
|
|
10
11
|
'upload_file', 'generate', 'list_loras', 'get_job', 'wait_for_result', 'list_jobs',
|
|
11
12
|
'cancel_job', 'prepare_preset', 'get_result_image',
|
|
12
13
|
'list_characters', 'get_character', 'list_character_features', 'list_character_presets',
|
|
@@ -31,6 +32,23 @@ export function registerTools(server, client) {
|
|
|
31
32
|
{ title: 'Get status', description: 'Engine running state, whether cloud is connected, credit balance, and the active project.', inputSchema: {} },
|
|
32
33
|
wrap(() => client.getStatus()));
|
|
33
34
|
|
|
35
|
+
// The engine's lifecycle. get_status could always report it was down and
|
|
36
|
+
// there was nothing an agent could do about it but ask the human to click
|
|
37
|
+
// Start (user report, 2026-09-24). Install, update and repair stay out of
|
|
38
|
+
// reach on purpose: those are multi-GB downloads that belong in front of a
|
|
39
|
+
// person.
|
|
40
|
+
server.registerTool('start_engine',
|
|
41
|
+
{ title: 'Start engine', description: 'Start the local engine if it is not already running. Returns the engine state; a cold boot can outlast the call, in which case engineStarting is true and get_status tells you when it is up. Does nothing if the engine is already running, and will not install one that is missing.', inputSchema: {} },
|
|
42
|
+
wrap(() => client.startEngine()));
|
|
43
|
+
|
|
44
|
+
server.registerTool('stop_engine',
|
|
45
|
+
{ title: 'Stop engine', description: 'Stop the local engine. Frees its VRAM; cloud generation is unaffected.', inputSchema: {} },
|
|
46
|
+
wrap(() => client.stopEngine()));
|
|
47
|
+
|
|
48
|
+
server.registerTool('restart_engine',
|
|
49
|
+
{ title: 'Restart engine', description: 'Restart the local engine. Use it after installing or removing a custom node, or when the engine is wedged.', inputSchema: {} },
|
|
50
|
+
wrap(() => client.restartEngine()));
|
|
51
|
+
|
|
34
52
|
server.registerTool('list_projects',
|
|
35
53
|
{ title: 'List projects', description: 'List projects (output containers).', inputSchema: {} },
|
|
36
54
|
wrap(() => client.listProjects()));
|