Skip to content

Commit 5b3ae35

Browse files
yotsudaclaude
andcommitted
fix(naming): set window title when get_current_location claims an unowned console
GetCurrentLocation discarded FindReadyPipeAsync's consoleSwitched flag with `_`, so when an AI's first tool call after the user's Import-Module PowerShell.MCP happened to be get_current_location (rather than invoke_expression / start_console, which both honor the flag), the proxy claimed the console without ever calling SetConsoleTitleAsync. The window title was left at the OnImport placeholder "#PID ____" until some other tool that handles consoleSwitched ran later — which made the symptom appear intermittent depending on tool-call ordering. The fix captures consoleSwitched and routes through SetConsoleTitleAsync on the same tight path InvokeExpression and StartConsole already use. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 983dcae commit 5b3ae35

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static async Task<string> GetCurrentLocation(
9797
return error;
9898

9999
// Find a ready pipe
100-
var (readyPipeName, _, closedConsoleMessages, allPipesStatusInfo) = await FindReadyPipeAsync(pipeDiscoveryService, agentId, cancellationToken);
100+
var (readyPipeName, consoleSwitched, closedConsoleMessages, allPipesStatusInfo) = await FindReadyPipeAsync(pipeDiscoveryService, agentId, cancellationToken);
101101

102102
if (readyPipeName == null)
103103
{
@@ -108,6 +108,15 @@ public static async Task<string> GetCurrentLocation(
108108

109109
try
110110
{
111+
// Set console window title if this was a newly claimed (unowned) console.
112+
// Without this, get_current_location as the first tool call after the user
113+
// ran Import-Module PowerShell.MCP would leave the title as the placeholder
114+
// "#PID ____" until some other tool that handles consoleSwitched runs.
115+
if (consoleSwitched)
116+
{
117+
await SetConsoleTitleAsync(powerShellService, readyPipeName, cancellationToken);
118+
}
119+
111120
// Get location (DLL will include its own cached outputs automatically)
112121
var result = await powerShellService.GetCurrentLocationFromPipeAsync(readyPipeName, cancellationToken);
113122

0 commit comments

Comments
 (0)