nuwax-mcp-stdio-proxy 1.1.4 → 1.2.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/dist/customStdio.js +39 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +23342 -148
- package/dist/transport.js +1 -0
- package/package.json +8 -6
package/dist/customStdio.js
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
import { spawn } from 'child_process';
|
|
13
13
|
import { PassThrough } from 'stream';
|
|
14
14
|
import { serializeMessage } from '@modelcontextprotocol/sdk/shared/stdio.js';
|
|
15
|
+
import * as fs from 'fs';
|
|
16
|
+
import * as path from 'path';
|
|
17
|
+
function logDebug(msg) {
|
|
18
|
+
process.stderr.write(`[customStdio] ${msg}\n`);
|
|
19
|
+
}
|
|
15
20
|
export class CustomStdioClientTransport {
|
|
16
21
|
_process;
|
|
17
22
|
_readBuffer = new ReadBuffer();
|
|
@@ -31,13 +36,41 @@ export class CustomStdioClientTransport {
|
|
|
31
36
|
throw new Error('StdioClientTransport already started!');
|
|
32
37
|
}
|
|
33
38
|
return new Promise((resolve, reject) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const mergedEnv = {
|
|
40
|
+
...getDefaultEnvironment(),
|
|
41
|
+
...this._serverParams.env,
|
|
42
|
+
};
|
|
43
|
+
logDebug(`Starting "${this._serverParams.command}" with PATH: ${(mergedEnv.PATH || '').split(';').slice(0, 3).join(';')}...`);
|
|
44
|
+
// On Windows, resolve .cmd/.bat files if command not found directly
|
|
45
|
+
let command = this._serverParams.command;
|
|
46
|
+
let useShell = false;
|
|
47
|
+
const isWindows = process.platform === 'win32';
|
|
48
|
+
const cmdExtensions = ['.cmd', '.bat', '.exe'];
|
|
49
|
+
if (isWindows && !cmdExtensions.some(ext => command.toLowerCase().endsWith(ext))) {
|
|
50
|
+
// Try to find the command with .cmd extension in PATH
|
|
51
|
+
const pathDirs = (mergedEnv.PATH || '').split(';');
|
|
52
|
+
for (const dir of pathDirs) {
|
|
53
|
+
for (const ext of cmdExtensions) {
|
|
54
|
+
const fullPath = path.join(dir, command + ext);
|
|
55
|
+
if (fs.existsSync(fullPath)) {
|
|
56
|
+
command = fullPath;
|
|
57
|
+
logDebug(`Resolved "${this._serverParams.command}" to "${command}"`);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (command !== this._serverParams.command)
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// For .cmd/.bat files on Windows, we need shell: true
|
|
66
|
+
if (isWindows && (command.toLowerCase().endsWith('.cmd') || command.toLowerCase().endsWith('.bat'))) {
|
|
67
|
+
useShell = true;
|
|
68
|
+
logDebug(`Using shell: true for ${command}`);
|
|
69
|
+
}
|
|
70
|
+
this._process = spawn(command, this._serverParams.args ?? [], {
|
|
71
|
+
env: mergedEnv,
|
|
39
72
|
stdio: ['pipe', 'pipe', this._serverParams.stderr ?? 'inherit'],
|
|
40
|
-
shell:
|
|
73
|
+
shell: useShell,
|
|
41
74
|
windowsHide: true,
|
|
42
75
|
cwd: this._serverParams.cwd,
|
|
43
76
|
});
|
package/dist/index.d.ts
CHANGED