Windows: gemini-mcp-tool 'Cannot use both a positional prompt and the --prompt flag'
In gemini-mcp-tool v1.1.4 used as an MCP server in Claude Code on Windows 11, every multi-word ask-gemini call fails with "Cannot use both a positional prompt and the --prompt (-p) flag together". What causes this and how do I fix it?
Originally asked on GitHub: https://github.com/jamubc/gemini-mcp-tool/issues/62
4 answers
Status: fixed upstream — the maintainer merged PRs #76/#77 (every argument quoted for cmd.exe, with complex prompts sent via stdin) and closed the issue. The root cause was in how Node's
spawnhandled the prompt on Windows. Withshell: true, Node built a command likecmd.exe /d /s /c "gemini -p prompt text with spaces"; cmd.exe word-splits that line, so-preceives only the first word and the remaining words become positionalqueryargs, which yargs rejects. Withshell: falsein v1.1.4, spawninggeminidirectly failed because it is a.cmdfile, not an.exe(ENOENT).While waiting for the fix, the thread offers three workarounds:
-
Apply the comment-1 patch to
dist/utils/geminiExecutor.js(both the main path and the flash-fallback path): quote the prompt wheneverprocess.platform === 'win32'or the prompt contains@, escaping embedded double-quotes. This replaces the previous@-only quoting logic. -
Use the issue body's suggested approach: spawn
nodeviaprocess.execPathwith the resolved path to@google/gemini-cli/bundle/gemini.jsandshell: false, so arguments are passed directly without cmd.exe parsing. -
Use the comment-2 alternative: rewrite the functionality with the
@google/genaiSDK instead of shelling out to thegeminiCLI, which removes the wholeshell: truequoting bug class. The commenter published this as@qmediat.io/gemini-code-context-mcpwith a migration guide.
As general advice, upgrading to the released fixed version of gemini-mcp-tool is the cleanest option once it is available.
Did this work for you?-
What a GitHub user tried on GitHub (Outcome unclear)
Reporter reproduced on Windows 11 with gemini-mcp-tool v1.1.4, Gemini CLI v0.36.0, Node v24.13.0. They traced the error to spawn arg joining with
shell: trueand proposed spawning Node viaprocess.execPathplus the resolved gemini bundle JS withshell: false.Source: https://github.com/jamubc/gemini-mcp-tool/issues/62 (opens external site)
Did this work for you?What @xceza7 tried on GitHub (Outcome unclear)
Commenter confirmed the root cause on Gemini CLI v0.37.2 and proposed a patch that quotes prompts whenever
process.platform === 'win32'or the prompt contains@, escaping internal double-quotes, in both the main and flash-fallback paths.Source: https://github.com/jamubc/gemini-mcp-tool/issues/62#issuecomment-4245947682 (opens external site)
Did this work for you?What @qmt tried on GitHub (Worked)
Commenter reported they rewrote the functionality to use the
@google/genaiSDK directly instead of calling the gemini CLI subprocess, which avoids the shell/cmd.exe quoting problem entirely on Windows, macOS, and Linux.Source: https://github.com/jamubc/gemini-mcp-tool/issues/62#issuecomment-4300028157 (opens external site)
Did this work for you?
Related questions
- How to fix gemini-mcp-tool ask-gemini timeouts on large codebases?
- How do I fix "Gemini was thinking but got cut off" with gemini-mcp-tool in Claude Code?
- gemini-mcp-tool ask-gemini fails on Windows 11: Error: spawn gemini ENOENT
- How do I set the model for gemini-mcp-tool to gemini-3-pro-preview?
- gemini-mcp-tool on Windows: spawn gemini ENOENT error in Claude Code