mcp-agents 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +20 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-agents",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "MCP server that wraps AI CLI tools (Claude Code, Gemini CLI, Codex CLI) for use by any MCP client",
5
5
  "type": "module",
6
6
  "bin": {
package/server.js CHANGED
@@ -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 (claude -p) with a prompt.",
33
- buildArgs: (prompt) => ["--no-session-persistence", "-p", prompt],
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
- // Close stdin immediately so the child process doesn't wait for piped input.
201
- // execFile creates a pipe for stdin by default; leaving it open causes
202
- // the child to hang indefinitely waiting for EOF.
203
- child.stdin?.end();
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.buildArgs(prompt, extraOpts);
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, { timeoutMs });
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 || "" }],