Conversation
Prevent commands from hanging the MCP server indefinitely and speed up repeated calls by reusing a single powershell.exe instead of spawning one per command. - Add shared PowerShellManager singleton (src/utils/powershell-manager.js) - Enforce 25s invocation timeout via child-shell's built-in escape hatch - Rebuild the instance after a timeout or fatal error (self-healing) - Isolate workingDirectory with Push-Location/Pop-Location - Truncate oversized output at 100KB - Serialize access with a lock; graceful teardown on SIGINT/SIGTERM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the per-command
new PowerShell()+ps.dispose()pattern with a shared, self-healingPowerShellManagersingleton.Why
The original code creates and destroys a
powershell.exechild process on every tool call (~0.5 s each) and never setsinvocationTimeoutonnode-powershell. A command that hangs the shell (e.g.Format-Table -AutoSizeprobing terminal width in a non-interactive stdio pipe) freezes the MCP server forever — the 30 s client timeout fires, but the server-side promise never resolves, poisoning every subsequent call.Changes
src/utils/powershell-manager.jspowershell.exe, enforces 25 s invocation timeout (child-shellbuilt-in), rebuilds the instance after timeout/fatal error, truncates output at 100 KB, serializes access with a lock, tears down cleanly on SIGINT/SIGTERM.src/tools/powershell-tools.jscreatePowerShellInstance()+ per-call try/catch/dispose. Delegates topsManager.execute().src/tools/system-tools.jspsManager.execute().src/tools/file-tools.jspsManager.execute().src/server.jspsManager; registersSIGINT/SIGTERMhandlers for graceful teardown.Tested
Write-Output/Get-Date— instant return (singleton, no spawn overhead).Get-Process | Select ... | Format-Table -AutoSize— the exact command that previously froze the server indefinitely now returns within 1 s.