mcp-agents 0.4.0 → 0.5.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/package.json +1 -1
- package/server.js +21 -10
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -18,7 +18,7 @@ const VERSION = JSON.parse(
|
|
|
18
18
|
readFileSync(join(__dirname, "package.json"), "utf8"),
|
|
19
19
|
).version;
|
|
20
20
|
|
|
21
|
-
const DEFAULT_TIMEOUT_MS =
|
|
21
|
+
const DEFAULT_TIMEOUT_MS = 300_000;
|
|
22
22
|
const MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
23
23
|
|
|
24
24
|
// ---------------------------------------------------------------------------
|
|
@@ -29,14 +29,16 @@ const CLI_BACKENDS = {
|
|
|
29
29
|
claude: {
|
|
30
30
|
command: "claude",
|
|
31
31
|
toolName: "claude_code",
|
|
32
|
-
description: "Run Claude Code CLI
|
|
33
|
-
|
|
32
|
+
description: "Run Claude Code CLI with a prompt (via stdin).",
|
|
33
|
+
stdinPrompt: true,
|
|
34
|
+
buildArgs: () => ["--no-session-persistence", "-p"],
|
|
34
35
|
extraProperties: {},
|
|
35
36
|
},
|
|
36
37
|
gemini: {
|
|
37
38
|
command: "gemini",
|
|
38
39
|
toolName: "gemini",
|
|
39
40
|
description: "Run Gemini CLI (gemini -p) with a prompt.",
|
|
41
|
+
stdinPrompt: false,
|
|
40
42
|
buildArgs: (prompt, opts) => {
|
|
41
43
|
const args = [];
|
|
42
44
|
if (opts.sandbox === true) args.push("-s");
|
|
@@ -164,11 +166,12 @@ function parseArgs() {
|
|
|
164
166
|
* Run a CLI command and return stdout (or stderr if stdout is empty).
|
|
165
167
|
* @param {string} command
|
|
166
168
|
* @param {string[]} args
|
|
167
|
-
* @param {{ timeoutMs?: number }} [opts]
|
|
169
|
+
* @param {{ timeoutMs?: number, stdinData?: string }} [opts]
|
|
168
170
|
* @returns {Promise<string>}
|
|
169
171
|
*/
|
|
170
172
|
function runCli(command, args, opts = {}) {
|
|
171
173
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
174
|
+
const stdinData = opts.stdinData;
|
|
172
175
|
|
|
173
176
|
return new Promise((resolve, reject) => {
|
|
174
177
|
const child = execFile(
|
|
@@ -197,10 +200,13 @@ function runCli(command, args, opts = {}) {
|
|
|
197
200
|
},
|
|
198
201
|
);
|
|
199
202
|
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
// Pipe prompt via stdin to avoid arg-quoting issues, then close.
|
|
204
|
+
child.stdin?.on("error", () => {}); // ignore EPIPE if child exits early
|
|
205
|
+
if (stdinData != null) {
|
|
206
|
+
child.stdin?.end(stdinData, "utf8");
|
|
207
|
+
} else {
|
|
208
|
+
child.stdin?.end();
|
|
209
|
+
}
|
|
204
210
|
|
|
205
211
|
child.on("error", (err) => {
|
|
206
212
|
reject(new Error(`Failed to start ${command}: ${err.message}`));
|
|
@@ -346,11 +352,16 @@ async function main() {
|
|
|
346
352
|
extraOpts[key] = params.arguments?.[key] ?? backend.extraProperties[key].default;
|
|
347
353
|
}
|
|
348
354
|
|
|
349
|
-
const cliArgs = backend.
|
|
355
|
+
const cliArgs = backend.stdinPrompt
|
|
356
|
+
? backend.buildArgs(extraOpts)
|
|
357
|
+
: backend.buildArgs(prompt, extraOpts);
|
|
358
|
+
const cliOpts = backend.stdinPrompt
|
|
359
|
+
? { timeoutMs, stdinData: prompt }
|
|
360
|
+
: { timeoutMs };
|
|
350
361
|
|
|
351
362
|
logErr(`[mcp-agents] tools/call: running ${backend.command} …`);
|
|
352
363
|
try {
|
|
353
|
-
const output = await runCli(backend.command, cliArgs,
|
|
364
|
+
const output = await runCli(backend.command, cliArgs, cliOpts);
|
|
354
365
|
logErr("[mcp-agents] tools/call: done");
|
|
355
366
|
return {
|
|
356
367
|
content: [{ type: "text", text: output || "" }],
|