@simpligen/mcp 0.2.0 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpligen/mcp",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "MCP server for SimpliGen -- drive local/cloud AI image & video generation from an agent.",
5
5
  "type": "module",
6
6
  "license": "MIT",
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
- listProjects() { return this.#req('GET', '/projects'); }
48
- createProject(name) { return this.#req('POST', '/projects', { name }); }
49
- listLoras() { return this.#req('GET', '/loras'); }
50
- generate(args) { return this.#req('POST', '/generate', args); }
51
- getJob(id) { return this.#req('GET', `/jobs/${encodeURIComponent(id)}`); }
52
- listJobs() { return this.#req('GET', '/jobs'); }
53
- cancelJob(id) { return this.#req('POST', `/jobs/${encodeURIComponent(id)}/cancel`, {}); }
54
- preparePreset(args) { return this.#req('POST', '/presets/prepare', args); }
55
- getActiveDownloads() { return this.#req('GET', '/presets/prepare'); }
56
-
57
- listCharacters() { return this.#req('GET', '/characters'); }
58
- getCharacter(id) { return this.#req('GET', `/characters/${encodeURIComponent(id)}`); }
59
- listCharacterFeatures() { return this.#req('GET', '/character-features'); }
60
- listCharacterPresets() { return this.#req('GET', '/character-presets'); }
61
- createCharacter(args) { return this.#req('POST', '/characters', args); }
62
- generateCharacterImage(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-image`, args); }
63
- generateCharacterFrame(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/generate-frame`, args); }
64
- animateCharacter(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/animate`, args); }
65
- acceptBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/accept-base`, args); }
66
- setCharacterPreset(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/preset`, args); }
67
- enhanceCharacterMedia(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/enhance`, args); }
68
- regenerateCharacterBase(id, args) { return this.#req('POST', `/characters/${encodeURIComponent(id)}/regenerate-base`, args); }
69
- removeCharacter(id) { return this.#req('DELETE', `/characters/${encodeURIComponent(id)}`); }
70
-
71
- listRecipeBlocks() { return this.#req('GET', '/recipe-blocks'); }
72
- composeRecipe(args) { return this.#req('POST', '/recipes', args); }
73
- validateRecipe(args) { return this.#req('POST', '/recipes/validate', args); }
74
- listRecipes() { return this.#req('GET', '/recipes'); }
75
- getRecipe(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}`); }
76
- publishRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/publish`, args); }
77
- runRecipe(id, args) { return this.#req('POST', `/recipes/${encodeURIComponent(id)}/run`, args); }
78
- listRecipeRuns(id) { return this.#req('GET', `/recipes/${encodeURIComponent(id)}/runs`); }
79
- getRecipeRun(runId) { return this.#req('GET', `/recipe-runs/${encodeURIComponent(runId)}`); }
80
- cancelRecipeRun(runId) { return this.#req('POST', `/recipe-runs/${encodeURIComponent(runId)}/cancel`, {}); }
81
- listSubjects() { return this.#req('GET', '/subjects'); }
82
- listProducts() { return this.#req('GET', '/products'); }
83
- createProduct(args) { return this.#req('POST', '/products', args); }
84
- removeProduct(id) { return this.#req('DELETE', `/products/${encodeURIComponent(id)}`); }
85
-
86
- async uploadFile(filePath) {
87
- let buf;
88
- try {
89
- buf = fs.readFileSync(filePath);
90
- } catch (e) {
91
- throw new ControlApiError(0, 'file_not_found', `Cannot read file to upload: ${filePath} (${e.code || e.message}).`);
92
- }
93
- return this.#req('POST', '/uploads', { filename: path.basename(filePath), dataBase64: buf.toString('base64') });
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', 'list_projects', 'create_project',
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()));
@@ -51,8 +69,45 @@ export function registerTools(server, client) {
51
69
  packId: z.string().optional(), backend: z.enum(['local', 'cloud', 'auto']).optional(),
52
70
  negativePrompt: z.string().optional(), project: z.string().optional(),
53
71
  image: z.string().optional().describe('upload_file handle'),
54
- referenceImages: z.array(z.string()).optional().describe('upload_file handles'),
72
+ // A bare handle still works, so every agent written against the old
73
+ // schema keeps working. The object form carries the per-image label,
74
+ // which is the DESCRIPTION the app asks for when list_capabilities says
75
+ // inputs.referenceImages.requiresDescriptions is true (LTX 2.5
76
+ // Multi-Reference builds one appearance line per subject from it).
77
+ // Sending images without it on such a preset runs, but the subjects
78
+ // blur together, which is indistinguishable from the model being bad.
79
+ referenceImages: z.array(z.union([
80
+ z.string(),
81
+ z.object({
82
+ handle: z.string().describe('upload_file handle'),
83
+ label: z.string().optional().describe('What this reference IS, e.g. "a woman with red hair". Required in spirit when the preset reports requiresDescriptions.'),
84
+ }),
85
+ ])).optional().describe('upload_file handles, or {handle, label} when the preset wants a description per reference'),
55
86
  video: z.string().optional().describe('upload_file handle (driving video)'),
87
+ // The App has accepted these three since 1.58.0; this schema never
88
+ // offered them, so no agent could drive an audio preset at all: the
89
+ // error said needs_audio and there was nowhere to put a sound
90
+ // (mavr1k_, 2026-10-01). Passing it inside `options` does not work
91
+ // either, since preflight reads the top level.
92
+ audio: z.string().optional().describe('upload_file handle for the PRIMARY audio track (lip-sync / audio-to-video presets). Required when list_capabilities reports inputs.acceptsAudio true, optional when it reports "optional".'),
93
+ referenceAudios: z.array(z.union([
94
+ z.string(),
95
+ z.object({ handle: z.string(), durationSeconds: z.number().optional() }),
96
+ ])).optional().describe('upload_file handles for reference SOUNDS (a voice per subject, where the preset pairs them with references).'),
97
+ referenceVideos: z.array(z.union([
98
+ z.string(),
99
+ z.object({
100
+ handle: z.string(),
101
+ soundtrackMode: z.enum(['own', 'file', 'none']).optional().describe("Where this clip's sound comes from; defaults to 'own'."),
102
+ durationSeconds: z.number().optional(),
103
+ }),
104
+ ])).optional().describe('upload_file handles for reference CLIPS (MiniMax H3 scene chaining chains on a clip).'),
105
+ // Appended to the prompt by the app's own dialogue formatter, so the
106
+ // wording matches what the preset was tuned on. MiniMax H3 lip-syncs
107
+ // to it; sending it to a preset that does not declare supportsDialogue
108
+ // changes nothing.
109
+ dialogue: z.string().optional().describe('A spoken line for the character, when list_capabilities reports inputs.supportsDialogue.'),
110
+ dialogueDelivery: z.string().optional().describe('How the line is delivered, e.g. "urgent", "whispered". Only meaningful with dialogue.'),
56
111
  loras: z.array(z.object({ name: z.string().describe('LoRA display name from list_loras'), weight: z.number().optional().describe('Strength; defaults to the LoRA default') })).optional().describe('LoRAs to apply. Local backend only, and only for presets where inputs.supportsLoras is true. Use the LoRA trigger words in the prompt so it activates.'),
57
112
  // .passthrough(), not the zod default: a plain z.object STRIPS every key it
58
113
  // does not name, silently. The App's /generate accepts any Advanced