unity-mcp-cli 0.70.0 → 0.72.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/CHANGELOG.md +31 -0
- package/README.md +14 -1
- package/dist/commands/open.d.ts +13 -0
- package/dist/commands/open.js +55 -0
- package/dist/commands/open.js.map +1 -1
- package/dist/commands/run-system-tool.d.ts +1 -2
- package/dist/commands/run-system-tool.js +11 -130
- package/dist/commands/run-system-tool.js.map +1 -1
- package/dist/commands/run-tool-builder.d.ts +25 -0
- package/dist/commands/run-tool-builder.js +125 -0
- package/dist/commands/run-tool-builder.js.map +1 -0
- package/dist/commands/run-tool.d.ts +1 -2
- package/dist/commands/run-tool.js +11 -130
- package/dist/commands/run-tool.js.map +1 -1
- package/dist/lib/open.d.ts +48 -1
- package/dist/lib/open.js +158 -0
- package/dist/lib/open.js.map +1 -1
- package/dist/lib/run-tool.d.ts +15 -0
- package/dist/lib/run-tool.js +228 -0
- package/dist/lib/run-tool.js.map +1 -0
- package/dist/lib/types.d.ts +158 -2
- package/dist/lib.d.ts +2 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/utils/launch-error-dismiss.d.ts +159 -0
- package/dist/utils/launch-error-dismiss.js +440 -0
- package/dist/utils/launch-error-dismiss.js.map +1 -0
- package/dist/utils/unity-editor.js +33 -6
- package/dist/utils/unity-editor.js.map +1 -1
- package/dist/utils/unity-hub.js +20 -4
- package/dist/utils/unity-hub.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ All notable changes to `unity-mcp-cli` will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`runTool` / `runSystemTool` library functions.** The HTTP-tool
|
|
13
|
+
invocation paths previously available only as the `run-tool` /
|
|
14
|
+
`run-system-tool` CLI commands are now first-class library exports:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { runTool, runSystemTool } from 'unity-mcp-cli';
|
|
18
|
+
|
|
19
|
+
const result = await runTool({
|
|
20
|
+
toolName: 'tool-list',
|
|
21
|
+
unityProjectPath: '/path/to/Unity/project',
|
|
22
|
+
input: { regexSearch: 'gameobject', includeDescription: true },
|
|
23
|
+
});
|
|
24
|
+
if (result.kind === 'success') {
|
|
25
|
+
// result.data === parsed JSON body from the Unity plugin
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Same URL/token resolution priority as the CLI commands (explicit
|
|
30
|
+
override → project config → deterministic localhost port). Returns
|
|
31
|
+
a discriminated `{ kind: 'success' | 'failure', ... }` union; never
|
|
32
|
+
throws past the public boundary; emits no console output.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **`run-tool` / `run-system-tool` commands** now delegate to the new
|
|
37
|
+
library functions internally. CLI behaviour is unchanged.
|
|
38
|
+
|
|
8
39
|
## [0.67.0] - 2026-04-21
|
|
9
40
|
|
|
10
41
|
### Added
|
package/README.md
CHANGED
|
@@ -255,8 +255,21 @@ cd ./MyGame && unity-mcp-cli open
|
|
|
255
255
|
| `--tools <names>` | `UNITY_MCP_TOOLS` | No | Comma-separated list of tools to enable |
|
|
256
256
|
| `--transport <method>` | `UNITY_MCP_TRANSPORT` | No | Transport method: `streamableHttp` or `stdio` |
|
|
257
257
|
| `--start-server <value>` | `UNITY_MCP_START_SERVER` | No | Set to `true` or `false` to control MCP server auto-start |
|
|
258
|
+
| `--no-auto-dismiss-launch-errors` | — | No | Disable auto-dismissal of the Unity Editor "compile errors at launch" dialog (default: enabled) |
|
|
259
|
+
| `--launch-dismiss-timeout-ms <ms>` | — | No | Overall timeout (milliseconds) for the launch-errors auto-dismiss polling loop (default: `30000`) |
|
|
260
|
+
| `--launch-dismiss-poll-interval-ms <ms>` | — | No | Polling tick interval (milliseconds) for the launch-errors auto-dismiss loop (default: `1500`) |
|
|
258
261
|
|
|
259
|
-
The editor process is spawned in detached mode — the
|
|
262
|
+
The editor process is spawned in detached mode. By default, after spawning the editor, `open` polls for Unity's "compile errors at launch" dialog (`"Enter Safe Mode?"` on Unity 2020.2+, `"Hold On" / "Compiler Errors"` on older releases) and clicks `Ignore` so the editor finishes initialising — without this, any in-Editor automation that needs to run after a state where Unity itself can't compile (e.g. the NuGet dependency resolver) cannot self-heal. The dialog is surfaced after Unity has booted, connected to Package Manager, and started compiling — empirically ~6s on a fast machine and longer on a slow one — so the polling loop has a grace window after which it exits early if no dialog has been seen. The grace window has to cover Unity's full startup phase or the loop bails out before the dialog ever appears (issue #737); it never runs the full `--launch-dismiss-timeout-ms` in the no-dialog case. If the dialog is observed (and successfully dismissed), polling continues until the overall timeout so a re-appearing dialog (resolver fixes one error → dialog re-surfaces with the next) is dismissed again. Library-mode callers can supply an `AbortSignal` (`launchDismissAbortSignal` on `OpenProjectOptions`) to abort the loop the instant their own readiness signal fires.
|
|
263
|
+
|
|
264
|
+
### Auto-dismiss platform requirements
|
|
265
|
+
|
|
266
|
+
| Platform | Requirement | Notes |
|
|
267
|
+
|---|---|---|
|
|
268
|
+
| **Windows** | Built-in (Win32 API) | Uses `EnumWindows` / `EnumChildWindows` / `SendMessageW(BM_CLICK)` driven from PowerShell. No extra setup required. |
|
|
269
|
+
| **macOS** | **Accessibility permission** must be granted to the terminal (or `unity-mcp-cli` binary). System Settings → Privacy & Security → Accessibility. | Implemented via AppleScript / `osascript`. Without this permission, `osascript` reports an error every poll tick and the dialog cannot be dismissed. |
|
|
270
|
+
| **Linux/X11** | `xdotool` on `PATH` (e.g. `sudo apt-get install xdotool`). | Wayland is **not** supported in the first cut — track upstream issues for Wayland support. |
|
|
271
|
+
|
|
272
|
+
To opt out entirely, pass `--no-auto-dismiss-launch-errors`.
|
|
260
273
|
|
|
261
274
|
**Example — open with MCP connection:**
|
|
262
275
|
|
package/dist/commands/open.d.ts
CHANGED
|
@@ -16,4 +16,17 @@ export interface ResolveProjectPathResult {
|
|
|
16
16
|
export declare function resolveOpenProjectPath(positionalPath: string | undefined, optionPath: string | undefined, cwd: string): ResolveProjectPathResult;
|
|
17
17
|
/** Re-export for backward compatibility with existing tests. */
|
|
18
18
|
export declare const isUnityProjectDir: typeof libIsUnityProjectDir;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a `--xxx <ms>` style commander option as a positive integer.
|
|
21
|
+
* Commander stores the raw string (including the literal default
|
|
22
|
+
* supplied to `.option()`), so a parse-and-validate step is required
|
|
23
|
+
* before the value can flow into the library. Exits with code 1 on
|
|
24
|
+
* a non-numeric / non-positive value — matches the CLI's existing
|
|
25
|
+
* error-handling pattern for malformed flag values (`--auth`,
|
|
26
|
+
* `--transport`, `--start-server`).
|
|
27
|
+
*
|
|
28
|
+
* Exported for unit tests; the CLI wrapper is the only production
|
|
29
|
+
* caller.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parsePositiveIntFlag(raw: string | undefined, flagName: string, fallback: number): number;
|
|
19
32
|
export declare const openCommand: Command;
|
package/dist/commands/open.js
CHANGED
|
@@ -14,6 +14,38 @@ export function resolveOpenProjectPath(positionalPath, optionPath, cwd) {
|
|
|
14
14
|
}
|
|
15
15
|
/** Re-export for backward compatibility with existing tests. */
|
|
16
16
|
export const isUnityProjectDir = libIsUnityProjectDir;
|
|
17
|
+
/**
|
|
18
|
+
* Parse a `--xxx <ms>` style commander option as a positive integer.
|
|
19
|
+
* Commander stores the raw string (including the literal default
|
|
20
|
+
* supplied to `.option()`), so a parse-and-validate step is required
|
|
21
|
+
* before the value can flow into the library. Exits with code 1 on
|
|
22
|
+
* a non-numeric / non-positive value — matches the CLI's existing
|
|
23
|
+
* error-handling pattern for malformed flag values (`--auth`,
|
|
24
|
+
* `--transport`, `--start-server`).
|
|
25
|
+
*
|
|
26
|
+
* Exported for unit tests; the CLI wrapper is the only production
|
|
27
|
+
* caller.
|
|
28
|
+
*/
|
|
29
|
+
export function parsePositiveIntFlag(raw, flagName, fallback) {
|
|
30
|
+
if (raw === undefined)
|
|
31
|
+
return fallback;
|
|
32
|
+
const trimmed = String(raw).trim();
|
|
33
|
+
if (trimmed === '')
|
|
34
|
+
return fallback;
|
|
35
|
+
// Reject scientific notation, fractions, and explicit signs — the
|
|
36
|
+
// ms value MUST be a positive whole number for the polling loop's
|
|
37
|
+
// bookkeeping to be sane.
|
|
38
|
+
if (!/^\d+$/.test(trimmed)) {
|
|
39
|
+
ui.error(`${flagName} must be a positive integer (got: "${raw}")`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const parsed = parseInt(trimmed, 10);
|
|
43
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
44
|
+
ui.error(`${flagName} must be a positive integer (got: "${raw}")`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
return parsed;
|
|
48
|
+
}
|
|
17
49
|
/**
|
|
18
50
|
* Print actionable help when a required Unity Editor version is not found.
|
|
19
51
|
* Lists installed editors and suggests install or override commands. Lives
|
|
@@ -63,6 +95,9 @@ export const openCommand = new Command('open')
|
|
|
63
95
|
.option('--keep-connected', 'Force keep connected (sets UNITY_MCP_KEEP_CONNECTED=true)')
|
|
64
96
|
.option('--transport <method>', 'Transport method: streamableHttp or stdio (sets UNITY_MCP_TRANSPORT)')
|
|
65
97
|
.option('--start-server <value>', 'Set to true/false to control server auto-start (sets UNITY_MCP_START_SERVER)', undefined)
|
|
98
|
+
.option('--no-auto-dismiss-launch-errors', 'Disable auto-dismissal of the Unity Editor "compile errors at launch" dialog (default: enabled). On macOS, requires Accessibility permission for the terminal / unity-mcp-cli binary. On Linux/X11, requires `xdotool` on PATH (Wayland not supported).')
|
|
99
|
+
.option('--launch-dismiss-timeout-ms <ms>', 'Overall timeout (milliseconds) for the launch-errors auto-dismiss polling loop (default: 30000)', '30000')
|
|
100
|
+
.option('--launch-dismiss-poll-interval-ms <ms>', 'Polling tick interval (milliseconds) for the launch-errors auto-dismiss loop (default: 1500)', '1500')
|
|
66
101
|
.action(async (positionalPath, options) => {
|
|
67
102
|
// Resolve the path the same way the library does, but also
|
|
68
103
|
// validate the existence + Unity-project shape up front so we
|
|
@@ -111,6 +146,16 @@ export const openCommand = new Command('open')
|
|
|
111
146
|
}
|
|
112
147
|
startServerBool = val === 'true';
|
|
113
148
|
}
|
|
149
|
+
// --launch-dismiss-timeout-ms / --launch-dismiss-poll-interval-ms
|
|
150
|
+
// are commander string options with numeric defaults. Parse and
|
|
151
|
+
// validate here so the failure mode is a clear CLI error rather
|
|
152
|
+
// than a silent NaN that disables the polling loop.
|
|
153
|
+
const launchDismissTimeoutMs = parsePositiveIntFlag(options.launchDismissTimeoutMs, '--launch-dismiss-timeout-ms', 30000);
|
|
154
|
+
const launchDismissPollIntervalMs = parsePositiveIntFlag(options.launchDismissPollIntervalMs, '--launch-dismiss-poll-interval-ms', 1500);
|
|
155
|
+
// Commander's `--no-auto-dismiss-launch-errors` produces
|
|
156
|
+
// `autoDismissLaunchErrors: false`; the absence of the flag
|
|
157
|
+
// produces `undefined` (which `openProject` treats as the default
|
|
158
|
+
// `true`). No additional parsing needed.
|
|
114
159
|
// Pre-flight already-running check so we don't flash the
|
|
115
160
|
// "Locating Unity Editor..." spinner when Unity is already open
|
|
116
161
|
// for this project. The lib does its own check too (single
|
|
@@ -132,6 +177,9 @@ export const openCommand = new Command('open')
|
|
|
132
177
|
keepConnected: options.keepConnected,
|
|
133
178
|
transport: options.transport,
|
|
134
179
|
startServer: startServerBool,
|
|
180
|
+
autoDismissLaunchErrors: options.autoDismissLaunchErrors !== false,
|
|
181
|
+
launchDismissTimeoutMs,
|
|
182
|
+
launchDismissPollIntervalMs,
|
|
135
183
|
onProgress: (event) => {
|
|
136
184
|
switch (event.phase) {
|
|
137
185
|
case 'detecting-editor-version': {
|
|
@@ -184,6 +232,13 @@ export const openCommand = new Command('open')
|
|
|
184
232
|
ui.success(`Launched Unity Editor (PID: ${event.pid ?? 'unknown'})`);
|
|
185
233
|
break;
|
|
186
234
|
}
|
|
235
|
+
case 'launch-errors-dismissed': {
|
|
236
|
+
// Single info-level log line on dismissal — exact format
|
|
237
|
+
// is part of the issue's acceptance contract. Keep in
|
|
238
|
+
// sync with `launch-error-dismiss.ts` if changed.
|
|
239
|
+
ui.info(`[open] dismissed Unity launch-errors dialog (button=${event.button}, platform=${event.platform})`);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
187
242
|
default:
|
|
188
243
|
break;
|
|
189
244
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open.js","sourceRoot":"","sources":["../../src/commands/open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EACL,WAAW,EACX,kBAAkB,IAAI,qBAAqB,EAC3C,iBAAiB,IAAI,oBAAoB,GAC1C,MAAM,gBAAgB,CAAC;AAiBxB,MAAM,UAAU,sBAAsB,CACpC,cAAkC,EAClC,UAA8B,EAC9B,GAAW;IAEX,qEAAqE;IACrE,oEAAoE;IACpE,kDAAkD;IAClD,MAAM,QAAQ,GAAG,cAAc,IAAI,UAAU,CAAC;IAC9C,OAAO,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAEtD;;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AAkB;QAClB,IACE,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,cAAc,CAAC;YAC9C,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACjD,CAAC;YACD,uBAAuB,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,MAAM,CAAC,YAAY,KAAK,wBAAwB,EAAE,CAAC;YAC5D,uBAAuB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,6DAA6D;IAC7D,8DAA8D;IAC9D,oBAAoB;IACpB,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,EAAE,CAAC,OAAO,CAAC,oDAAoD,MAAM,CAAC,SAAS,IAAI,SAAS,GAAG,CAAC,CAAC;QACjG,EAAE,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,6DAA6D;IAC7D,0CAA0C;IAC1C,OAAO,CAAC,0BAA0B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const runSystemToolCommand: Command;
|
|
1
|
+
export declare const runSystemToolCommand: import("commander").Command;
|
|
@@ -1,132 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.option('--token <token>', 'Bearer token override (bypasses config)')
|
|
13
|
-
.option('--input <json>', 'JSON string of tool arguments')
|
|
14
|
-
.option('--input-file <file>', 'Read JSON arguments from file')
|
|
15
|
-
.option('--raw', 'Output raw JSON (no formatting)')
|
|
16
|
-
.option('--timeout <ms>', 'Request timeout in milliseconds (default: 60000)', '60000')
|
|
17
|
-
.action(async (toolName, positionalPath, options) => {
|
|
18
|
-
const projectPath = resolveAndValidateProjectPath(positionalPath, options);
|
|
19
|
-
const { url: baseUrl, token } = resolveConnection(projectPath, options);
|
|
20
|
-
const body = parseInput(options);
|
|
21
|
-
const endpoint = `${baseUrl}/api/system-tools/${encodeURIComponent(toolName)}`;
|
|
22
|
-
verbose(`System tool: ${toolName}`);
|
|
23
|
-
verbose(`Endpoint: ${endpoint}`);
|
|
24
|
-
verbose(`Body: ${body}`);
|
|
25
|
-
const headers = {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
};
|
|
28
|
-
if (token) {
|
|
29
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
30
|
-
verbose(`Authorization header set (source: ${options.token ? '--token flag' : 'config'})`);
|
|
31
|
-
}
|
|
32
|
-
const authSource = options.token ? '--token flag' : 'config';
|
|
33
|
-
if (!options.raw) {
|
|
34
|
-
ui.heading('Run System Tool');
|
|
35
|
-
ui.label('Tool', toolName);
|
|
36
|
-
ui.label('URL', endpoint);
|
|
37
|
-
if (token) {
|
|
38
|
-
ui.label('Auth', `from ${authSource}`);
|
|
39
|
-
}
|
|
40
|
-
ui.divider();
|
|
41
|
-
}
|
|
42
|
-
const spinner = options.raw ? null : ui.startSpinner(`Calling ${toolName}...`);
|
|
43
|
-
const timeoutMs = parseInt(options.timeout ?? '60000', 10);
|
|
44
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
45
|
-
ui.error(`Invalid --timeout value: "${options.timeout}". Must be a positive integer (milliseconds).`);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
const controller = new AbortController();
|
|
49
|
-
const fetchTimeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
50
|
-
try {
|
|
51
|
-
const response = await fetch(endpoint, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers,
|
|
54
|
-
body,
|
|
55
|
-
signal: controller.signal,
|
|
56
|
-
});
|
|
57
|
-
const responseText = await response.text();
|
|
58
|
-
let responseData;
|
|
59
|
-
try {
|
|
60
|
-
responseData = JSON.parse(responseText);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
responseData = responseText;
|
|
64
|
-
}
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
spinner?.stop();
|
|
67
|
-
if (options.raw) {
|
|
68
|
-
process.stdout.write(responseText);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
ui.error(`HTTP ${response.status}: ${response.statusText}`);
|
|
72
|
-
if (responseData) {
|
|
73
|
-
ui.info(typeof responseData === 'string'
|
|
74
|
-
? responseData
|
|
75
|
-
: JSON.stringify(responseData, null, 2));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
spinner?.success(`${toolName} completed`);
|
|
81
|
-
if (options.raw) {
|
|
82
|
-
process.stdout.write(responseText);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
ui.success('Response:');
|
|
86
|
-
console.log(typeof responseData === 'string'
|
|
87
|
-
? responseData
|
|
88
|
-
: JSON.stringify(responseData, null, 2));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
spinner?.stop();
|
|
93
|
-
const isTimeout = err instanceof Error && err.name === 'AbortError';
|
|
94
|
-
const cause = err instanceof Error && 'cause' in err ? err.cause : null;
|
|
95
|
-
const causeCode = cause?.code ?? '';
|
|
96
|
-
const rootMessage = cause?.message || causeCode || (err instanceof Error ? err.message : String(err));
|
|
97
|
-
const errorSignature = `${rootMessage} ${causeCode}`;
|
|
98
|
-
const isConnectionRefused = errorSignature.includes('ECONNREFUSED');
|
|
99
|
-
const isConnectionReset = errorSignature.includes('ECONNRESET');
|
|
100
|
-
const isNetworkError = errorSignature.includes('EAI_AGAIN') || errorSignature.includes('ENOTFOUND');
|
|
101
|
-
let displayMessage;
|
|
102
|
-
if (isTimeout) {
|
|
103
|
-
displayMessage = `System tool call timed out after ${timeoutMs / 1000} seconds: ${toolName}`;
|
|
104
|
-
}
|
|
105
|
-
else if (isConnectionRefused) {
|
|
106
|
-
displayMessage = `Connection refused at ${endpoint}. Is the MCP server running? Start Unity Editor with the MCP plugin first.`;
|
|
107
|
-
}
|
|
108
|
-
else if (isConnectionReset) {
|
|
109
|
-
displayMessage = `Connection was reset by the server at ${endpoint}. The server may have crashed or restarted.`;
|
|
110
|
-
}
|
|
111
|
-
else if (isNetworkError) {
|
|
112
|
-
displayMessage = `Cannot reach ${endpoint}. Check your network connection and server URL.`;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
displayMessage = `${rootMessage}`;
|
|
116
|
-
if (cause && cause.message !== rootMessage) {
|
|
117
|
-
displayMessage += ` (${cause.message})`;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (options.raw) {
|
|
121
|
-
process.stderr.write(displayMessage + '\n');
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
ui.error(`Failed to call system tool: ${displayMessage}`);
|
|
125
|
-
}
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
clearTimeout(fetchTimeout);
|
|
130
|
-
}
|
|
1
|
+
import { runSystemTool } from '../lib/run-tool.js';
|
|
2
|
+
import { buildRunToolCommand } from './run-tool-builder.js';
|
|
3
|
+
export const runSystemToolCommand = buildRunToolCommand({
|
|
4
|
+
name: 'run-system-tool',
|
|
5
|
+
description: 'Execute a system tool via the HTTP API (not exposed to MCP clients)',
|
|
6
|
+
argDescription: 'Name of the system tool to execute',
|
|
7
|
+
routePrefix: '/api/system-tools',
|
|
8
|
+
verboseLabel: 'System tool',
|
|
9
|
+
headingLabel: 'Run System Tool',
|
|
10
|
+
errorNoun: 'system tool',
|
|
11
|
+
invoke: runSystemTool,
|
|
131
12
|
});
|
|
132
13
|
//# sourceMappingURL=run-system-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-system-tool.js","sourceRoot":"","sources":["../../src/commands/run-system-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"run-system-tool.js","sourceRoot":"","sources":["../../src/commands/run-system-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;IACtD,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,qEAAqE;IAClF,cAAc,EAAE,oCAAoC;IACpD,WAAW,EAAE,mBAAmB;IAChC,YAAY,EAAE,aAAa;IAC3B,YAAY,EAAE,iBAAiB;IAC/B,SAAS,EAAE,aAAa;IACxB,MAAM,EAAE,aAAa;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import type { RunToolOptions, RunToolResult } from '../lib/types.js';
|
|
3
|
+
interface BuilderOptions {
|
|
4
|
+
/** CLI subcommand name, e.g. `'run-tool'`. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** `description()` text for the commander command. */
|
|
7
|
+
description: string;
|
|
8
|
+
/** Description shown next to the `<tool-name>` argument. */
|
|
9
|
+
argDescription: string;
|
|
10
|
+
/** URL path prefix the lib function targets, e.g. `'/api/tools'`. */
|
|
11
|
+
routePrefix: string;
|
|
12
|
+
/** Verbose-log label, e.g. `'Tool'` or `'System tool'`. */
|
|
13
|
+
verboseLabel: string;
|
|
14
|
+
/** Heading printed by `ui.heading`, e.g. `'Run Tool'`. */
|
|
15
|
+
headingLabel: string;
|
|
16
|
+
/**
|
|
17
|
+
* Lower-case noun used in user-facing failure copy:
|
|
18
|
+
* `Failed to call <noun>:` and `<Capitalized> call timed out…`.
|
|
19
|
+
*/
|
|
20
|
+
errorNoun: string;
|
|
21
|
+
/** Library function — `runTool` or `runSystemTool`. */
|
|
22
|
+
invoke: (opts: RunToolOptions) => Promise<RunToolResult>;
|
|
23
|
+
}
|
|
24
|
+
export declare function buildRunToolCommand(cfg: BuilderOptions): Command;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import * as ui from '../utils/ui.js';
|
|
3
|
+
import { verbose } from '../utils/ui.js';
|
|
4
|
+
import { resolveAndValidateProjectPath, resolveConnection } from '../utils/connection.js';
|
|
5
|
+
import { parseInput } from '../utils/input.js';
|
|
6
|
+
export function buildRunToolCommand(cfg) {
|
|
7
|
+
return new Command(cfg.name)
|
|
8
|
+
.description(cfg.description)
|
|
9
|
+
.argument('<tool-name>', cfg.argDescription)
|
|
10
|
+
.argument('[path]', 'Unity project path (used for config and auto port detection)')
|
|
11
|
+
.option('--path <path>', 'Unity project path (config and auto port detection)')
|
|
12
|
+
.option('--url <url>', 'Direct server URL override (bypasses config)')
|
|
13
|
+
.option('--token <token>', 'Bearer token override (bypasses config)')
|
|
14
|
+
.option('--input <json>', 'JSON string of tool arguments')
|
|
15
|
+
.option('--input-file <file>', 'Read JSON arguments from file')
|
|
16
|
+
.option('--raw', 'Output raw JSON (no formatting)')
|
|
17
|
+
.option('--timeout <ms>', 'Request timeout in milliseconds (default: 60000)', '60000')
|
|
18
|
+
.action(async (toolName, positionalPath, options) => {
|
|
19
|
+
// Validate --timeout first so a bad value short-circuits before
|
|
20
|
+
// we read --input-file or hit the network.
|
|
21
|
+
const timeoutMs = parseInt(options.timeout, 10);
|
|
22
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
23
|
+
ui.error(`Invalid --timeout value: "${options.timeout}". Must be a positive integer (milliseconds).`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
// Resolve path + connection up front so the heading and verbose
|
|
27
|
+
// output reflect the final endpoint before the HTTP call fires.
|
|
28
|
+
const projectPath = resolveAndValidateProjectPath(positionalPath, options);
|
|
29
|
+
const { url: baseUrl, token } = resolveConnection(projectPath, options);
|
|
30
|
+
const body = parseInput(options);
|
|
31
|
+
const endpoint = `${baseUrl}${cfg.routePrefix}/${encodeURIComponent(toolName)}`;
|
|
32
|
+
const authSource = options.token ? '--token flag' : 'config';
|
|
33
|
+
verbose(`${cfg.verboseLabel}: ${toolName}`);
|
|
34
|
+
verbose(`Endpoint: ${endpoint}`);
|
|
35
|
+
verbose(`Body: ${body}`);
|
|
36
|
+
if (token)
|
|
37
|
+
verbose(`Authorization header set (source: ${authSource})`);
|
|
38
|
+
if (!options.raw) {
|
|
39
|
+
ui.heading(cfg.headingLabel);
|
|
40
|
+
ui.label('Tool', toolName);
|
|
41
|
+
ui.label('URL', endpoint);
|
|
42
|
+
if (token)
|
|
43
|
+
ui.label('Auth', `from ${authSource}`);
|
|
44
|
+
ui.divider();
|
|
45
|
+
}
|
|
46
|
+
const spinner = options.raw ? null : ui.startSpinner(`Calling ${toolName}...`);
|
|
47
|
+
// The CLI already resolved url/token, so passing them explicitly
|
|
48
|
+
// makes the lib's resolver a no-op rather than re-reading config.
|
|
49
|
+
const result = await cfg.invoke({
|
|
50
|
+
toolName,
|
|
51
|
+
url: baseUrl,
|
|
52
|
+
...(token ? { token } : {}),
|
|
53
|
+
input: body,
|
|
54
|
+
timeoutMs,
|
|
55
|
+
});
|
|
56
|
+
if (result.kind === 'success') {
|
|
57
|
+
spinner?.success(`${toolName} completed`);
|
|
58
|
+
if (options.raw) {
|
|
59
|
+
process.stdout.write(stringifyForRaw(result.data));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
ui.success('Response:');
|
|
63
|
+
console.log(typeof result.data === 'string'
|
|
64
|
+
? result.data
|
|
65
|
+
: JSON.stringify(result.data, null, 2));
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
spinner?.stop();
|
|
70
|
+
handleFailure(result, {
|
|
71
|
+
toolName,
|
|
72
|
+
endpoint,
|
|
73
|
+
raw: options.raw,
|
|
74
|
+
timeoutMs,
|
|
75
|
+
errorNoun: cfg.errorNoun,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function stringifyForRaw(data) {
|
|
80
|
+
if (typeof data === 'string')
|
|
81
|
+
return data;
|
|
82
|
+
if (data === undefined)
|
|
83
|
+
return '';
|
|
84
|
+
return JSON.stringify(data);
|
|
85
|
+
}
|
|
86
|
+
function handleFailure(failure, ctx) {
|
|
87
|
+
if (failure.reason === 'http-error') {
|
|
88
|
+
if (ctx.raw) {
|
|
89
|
+
process.stdout.write(stringifyForRaw(failure.data));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
ui.error(`HTTP ${failure.httpStatus}: ${failure.message}`);
|
|
93
|
+
if (failure.data !== undefined) {
|
|
94
|
+
ui.info(typeof failure.data === 'string'
|
|
95
|
+
? failure.data
|
|
96
|
+
: JSON.stringify(failure.data, null, 2));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const message = buildFailureMessage(failure, ctx);
|
|
102
|
+
if (ctx.raw)
|
|
103
|
+
process.stderr.write(message + '\n');
|
|
104
|
+
else
|
|
105
|
+
ui.error(`Failed to call ${ctx.errorNoun}: ${message}`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
function buildFailureMessage(failure, ctx) {
|
|
109
|
+
switch (failure.reason) {
|
|
110
|
+
case 'timeout':
|
|
111
|
+
return `${capitalize(ctx.errorNoun)} call timed out after ${ctx.timeoutMs / 1000} seconds: ${ctx.toolName}`;
|
|
112
|
+
case 'connection-refused':
|
|
113
|
+
return `Connection refused at ${ctx.endpoint}. Is the MCP server running? Start Unity Editor with the MCP plugin first.`;
|
|
114
|
+
case 'connection-reset':
|
|
115
|
+
return `Connection was reset by the server at ${ctx.endpoint}. The server may have crashed or restarted.`;
|
|
116
|
+
case 'network-error':
|
|
117
|
+
return `Cannot reach ${ctx.endpoint}. Check your network connection and server URL.`;
|
|
118
|
+
default:
|
|
119
|
+
return failure.message;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function capitalize(s) {
|
|
123
|
+
return s.length === 0 ? s : s.charAt(0).toUpperCase() + s.slice(1);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=run-tool-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tool-builder.js","sourceRoot":"","sources":["../../src/commands/run-tool-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AA2C/C,MAAM,UAAU,mBAAmB,CAAC,GAAmB;IACrD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;SACzB,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC;SAC5B,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,cAAc,CAAC;SAC3C,QAAQ,CAAC,QAAQ,EAAE,8DAA8D,CAAC;SAClF,MAAM,CAAC,eAAe,EAAE,qDAAqD,CAAC;SAC9E,MAAM,CAAC,aAAa,EAAE,8CAA8C,CAAC;SACrE,MAAM,CAAC,iBAAiB,EAAE,yCAAyC,CAAC;SACpE,MAAM,CAAC,gBAAgB,EAAE,+BAA+B,CAAC;SACz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