Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

McpToolset hangs silently for ~5 minutes per retry (3 retries) when stdio command is an npm shim ("npx") on Windows

Offen
#1,686 4 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@hemasekhar-p arbeitet bereits daran.

Seit 22.10.2026.

  • #1691 von @pinqionghongbai — offen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

needs review

Description

The examples/mcpfilesystem sample — and any McpToolset built with
command("npx") — appears to hang indefinitely on Windows. No error is
printed and no node.exe process is ever spawned; the caller just blocks
inside McpToolset.getTools().

After digging into it, the "hang" is actually a very slow failure loop:
each initialization attempt waits out the full default
initializationTimeout (5 minutes), and the sync retry logic re-runs the
same doomed initialization, so the program stays silent for a measured
900 seconds (~15 minutes: 3 attempts x 5-minute timeout) before a
McpToolLoadingException (wrapped
Client failed to initialize by explicit API call) finally surfaces —
and even that is invisible unless an SLF4J provider is on the classpath,
which the samples don't include by default.

Environment

  • OS: Windows 11 Home (10.0.26200)
  • JDK: Oracle 21.0.5
  • google-adk: 1.13.0
  • Maven: 3.9.8
  • Node.js: 24.15.0 (npx 11.12.1, standard npm-for-Windows install with
    npx.cmd shim)

Root cause

On Windows, npm installs command shims as batch scripts (npx.cmd), not
executables. Java's ProcessBuilder cannot execute a bare npx command
(it is not a PE executable and is not resolved through PATHEXT), so the
stdio subprocess never starts.

A plain new ProcessBuilder("npx", "-v").start() on the same machine
fails immediately with CreateProcess error=2, which confirms the
JVM/OS-level cause. Inside ADK, however, the failure is masked by:

  1. McpSessionManager.initializeSession(...) defaults the
    initializationTimeout to 5 minutes
    (core/src/main/java/com/google/adk/tools/mcp/McpSessionManager.java,
    the Duration.ofMinutes(5) fallback), so client.initialize() waits
    for a response from a process that never started.
  2. The sync McpToolset.getTools() retry logic (MAX_RETRIES = 3,
    100 ms delay) then re-runs the same doomed initialization.
  3. Without an SLF4J provider (the default for the samples), even the
    retry ERROR logs are swallowed, leaving zero output on the console.

Observed log once an SLF4J provider is added (full run, timestamps from
the measured repro):

ERROR com.google.adk.tools.mcp.McpToolset - Unexpected error during tool loading, retry attempt 1
java.lang.RuntimeException: Client failed to initialize by explicit API call
    at io.modelcontextprotocol.client.LifecycleInitializer...
ERROR ... retry attempt 2
ERROR ... retry attempt 3
ERROR com.google.adk.tools.mcp.McpToolset - Failed to load tools after multiple retries due to unexpected error.
com.google.adk.tools.mcp.McpToolsetException$McpToolLoadingException
    (total elapsed: 900,857 ms)

Minimal reproduction (public API only)

StdioServerParameters params = StdioServerParameters.builder()
    .command("npx")   // hangs; "npx.cmd" works
    .args(ImmutableList.of(
        "-y", "@modelcontextprotocol/server-filesystem", "<some-dir>"))
    .build();

McpToolset toolset = new McpToolset(params.toServerParameters());
List<BaseTool> tools = toolset.getTools(null).toList().blockingGet();
// blocks: ~5 min per attempt, up to 3 retries, then throws

Observed behavior

command result
npx silent block, measured 900 s (~15 min) total, then McpToolLoadingException; no node.exe ever spawned
npx.cmd OK in ~3.5 s, 14 tools loaded

Workaround

Use the .cmd extension explicitly on Windows:

.command("npx.cmd")

Suggestions

  1. Add a Windows note to examples/mcpfilesystem/README.md (lowest
    effort, immediate relief for new users).
  2. Optionally, fail fast with a clear error when the configured command
    cannot be executed at all (e.g. probe with ProcessBuilder.start()
    before the 5-minute timeout), or auto-map well-known npm shims
    (npx / npm / node) to their .cmd variants on Windows.

ReproToolset.java

Happy to send a PR for either suggestion. Thanks!

Vorherrschende Sprache
Java
Sterne
1.8k
Forks
440
Ø Merge
3 T. 13 Std.
Gemergte PRs (30 T.)
95

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus google/adk-java

Alle Issues in google/adk-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.