Skip to content

Commit b23ace8

Browse files
committed
Shorten Named Pipe name to fix macOS 104-char UNIX socket path limit
Rename pipe prefix from 'PowerShell.MCP.Communication' to 'PSMCP'. macOS TMPDIR (/var/folders/...) + CoreFxPipe_ prefix consumes ~62 chars, leaving only 42 chars for the pipe name. The old name was 50 chars for claimed pipes, exceeding the limit and causing silent failures.
1 parent 00a1ace commit b23ace8

10 files changed

Lines changed: 491 additions & 25 deletions

File tree

.github/workflows/cross-platform-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ jobs:
312312
Write-Host "=== Testing Named Pipe Communication ===" -ForegroundColor Cyan
313313
314314
# Clean up any existing Named Pipe socket files (Linux/macOS)
315-
$pipeName = "PowerShell.MCP.Communication"
315+
$pipeName = "PSMCP"
316316
if (-not $IsWindows) {
317317
# Check both /tmp and $TMPDIR (macOS uses $TMPDIR)
318318
$pipeLocations = @("/tmp/CoreFxPipe_$pipeName")

.github/workflows/macos-terminal-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# Wait for Named Pipe to appear
6363
echo "Waiting for Named Pipe..."
6464
for i in $(seq 1 60); do
65-
PIPE=$(find /tmp -name "CoreFxPipe_PowerShell.MCP.*" 2>/dev/null | head -1)
65+
PIPE=$(find /tmp -name "CoreFxPipe_PSMCP.*" 2>/dev/null | head -1)
6666
if [ -n "$PIPE" ]; then
6767
echo "Named Pipe found: $PIPE (after ${i}s)"
6868
break
@@ -86,12 +86,12 @@ jobs:
8686
$ErrorActionPreference = "Stop"
8787
8888
# Find the Named Pipe
89-
$pipes = Get-ChildItem /tmp/CoreFxPipe_PowerShell.MCP.* -ErrorAction SilentlyContinue
89+
$pipes = Get-ChildItem /tmp/CoreFxPipe_PSMCP.* -ErrorAction SilentlyContinue
9090
if (-not $pipes) {
9191
# Also check TMPDIR
9292
$tmpdir = $env:TMPDIR
9393
if ($tmpdir) {
94-
$pipes = Get-ChildItem "$tmpdir/CoreFxPipe_PowerShell.MCP.*" -ErrorAction SilentlyContinue
94+
$pipes = Get-ChildItem "$tmpdir/CoreFxPipe_PSMCP.*" -ErrorAction SilentlyContinue
9595
}
9696
}
9797
if (-not $pipes) { throw "No Named Pipe found" }

PowerShell.MCP.Proxy/Services/ConsoleSessionManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ConsoleSessionManager
1717
/// <summary>
1818
/// Base pipe name prefix for PowerShell.MCP
1919
/// </summary>
20-
public const string DefaultPipeName = "PowerShell.MCP.Communication";
20+
public const string DefaultPipeName = "PSMCP";
2121

2222
/// <summary>
2323
/// Error message when module is not imported
@@ -283,8 +283,8 @@ public void ClearDeadPipe(string agentId, string pipeName)
283283
/// <summary>
284284
/// Enumerates PowerShell.MCP Named Pipes lazily by scanning the file system.
285285
/// Uses yield return for lazy evaluation - stops scanning when caller stops iterating.
286-
/// Windows: \\.\pipe\PowerShell.MCP.Communication.*
287-
/// Linux/macOS: /tmp/CoreFxPipe_PowerShell.MCP.Communication.*
286+
/// Windows: \\.\pipe\PSMCP.*
287+
/// Linux/macOS: /tmp/CoreFxPipe_PSMCP.*
288288
/// </summary>
289289
/// <param name="proxyPid">If specified, only returns pipes owned by this proxy</param>
290290
/// <param name="agentId">If specified with proxyPid, only returns pipes for this agent (format: {name}.{proxyPid}.{agentId}.*)</param>
@@ -368,10 +368,10 @@ public IEnumerable<string> EnumerateUnownedPipes()
368368
baseName = baseName.Substring("CoreFxPipe_".Length);
369369

370370
// Count segments after DefaultPipeName
371-
// Unowned: PowerShell.MCP.Communication.{pwshPid} = 4 segments
372-
// Owned: PowerShell.MCP.Communication.{proxyPid}.{agentId}.{pwshPid} = 6 segments
371+
// Unowned: PSMCP.{pwshPid} = 2 segments
372+
// Owned: PSMCP.{proxyPid}.{agentId}.{pwshPid} = 4 segments
373373
var segments = baseName.Split('.');
374-
if (segments.Length == 4 && int.TryParse(segments[^1], out _))
374+
if (segments.Length == 2 && int.TryParse(segments[^1], out _))
375375
{
376376
yield return pipe;
377377
}

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static async Task<string> InvokeExpression(
197197
var newPipeName = sessionManager.GetActivePipeName(agentId);
198198
var (completedOutputs, busyStatusInfo) = await CollectAllCachedOutputsAsync(pipeDiscoveryService, agentId, newPipeName, cancellationToken);
199199

200-
// Extract PID from pipe name (format: PowerShell.MCP.Communication.{PID})
200+
// Extract PID from pipe name (format: PSMCP.{PID})
201201
var pid = GetPidString(newPipeName);
202202

203203
// Build response: busy status first + message + location + completedOutputs
@@ -228,7 +228,7 @@ public static async Task<string> InvokeExpression(
228228
await SetConsoleTitleAsync(powerShellService, readyPipeName, cancellationToken);
229229
var (completedOutputs, busyStatusInfo) = await CollectAllCachedOutputsAsync(pipeDiscoveryService, agentId, readyPipeName, cancellationToken);
230230

231-
// Extract PID from pipe name (format: PowerShell.MCP.Communication.{PID})
231+
// Extract PID from pipe name (format: PSMCP.{PID})
232232
var pid = GetPidString(readyPipeName);
233233

234234
// Build response: busy status first + closedConsoleInfo + message + locationResult + completedOutputs

PowerShell.MCP/Services/NamedPipeServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static IReadOnlyList<string> ConsumeCachedOutputs()
250250
/// </summary>
251251
public class NamedPipeServer : IDisposable
252252
{
253-
public const string BasePipeName = "PowerShell.MCP.Communication";
253+
public const string BasePipeName = "PSMCP";
254254
private const int MaxConcurrentConnections = 2; // Two pipe instances
255255

256256
/// <summary>

Staging/PowerShell.MCP.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ function Get-MCPOwner {
201201
}
202202

203203
# Parse pipe name segments
204-
# Unowned: PowerShell.MCP.Communication.{pwshPid} (4 segments)
205-
# Owned: PowerShell.MCP.Communication.{proxyPid}.{agentId}.{pwshPid} (6 segments)
204+
# Unowned: PSMCP.{pwshPid} (2 segments)
205+
# Owned: PSMCP.{proxyPid}.{agentId}.{pwshPid} (4 segments)
206206
$segments = $pipeName.Split('.')
207207

208-
if ($segments.Length -ne 6) {
208+
if ($segments.Length -ne 4) {
209209
return [PSCustomObject]@{
210210
Owned = $false
211211
ProxyPid = $null
@@ -214,8 +214,8 @@ function Get-MCPOwner {
214214
}
215215
}
216216

217-
$proxyPid = [int]$segments[3]
218-
$agentId = $segments[4]
217+
$proxyPid = [int]$segments[1]
218+
$agentId = $segments[2]
219219

220220
# Determine client name by examining process path and parent chain
221221
# Uses Get-Process Path and Parent properties (cross-platform, no Win32_Process)

Tests/Unit/Proxy/PipeDiscoveryServiceTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task FindReadyPipeAsync_ActivePipeStandby_ReturnsActivePipe()
4747
// Setup: Active pipe is in standby state
4848
var sessionManager = ConsoleSessionManager.Instance;
4949
var proxyPid = sessionManager.ProxyPid;
50-
var testPipeName = $"PowerShell.MCP.Communication.{proxyPid}.{DefaultAgentId}.99999";
50+
var testPipeName = $"PSMCP.{proxyPid}.{DefaultAgentId}.99999";
5151

5252
// Set the active pipe name (this requires the session manager to be aware of it)
5353
sessionManager.SetActivePipeName(DefaultAgentId, testPipeName);
@@ -70,7 +70,7 @@ public async Task FindReadyPipeAsync_ActivePipeCompleted_ReturnsActivePipe()
7070
{
7171
var sessionManager = ConsoleSessionManager.Instance;
7272
var proxyPid = sessionManager.ProxyPid;
73-
var testPipeName = $"PowerShell.MCP.Communication.{proxyPid}.{DefaultAgentId}.99998";
73+
var testPipeName = $"PSMCP.{proxyPid}.{DefaultAgentId}.99998";
7474

7575
sessionManager.SetActivePipeName(DefaultAgentId, testPipeName);
7676

@@ -92,7 +92,7 @@ public async Task FindReadyPipeAsync_ActivePipeDead_ReturnsNull()
9292
{
9393
var sessionManager = ConsoleSessionManager.Instance;
9494
var proxyPid = sessionManager.ProxyPid;
95-
var testPipeName = $"PowerShell.MCP.Communication.{proxyPid}.{DefaultAgentId}.99997";
95+
var testPipeName = $"PSMCP.{proxyPid}.{DefaultAgentId}.99997";
9696

9797
sessionManager.SetActivePipeName(DefaultAgentId, testPipeName);
9898

@@ -113,7 +113,7 @@ public async Task FindReadyPipeAsync_ActivePipeBusy_RecordsStatusInfo()
113113
{
114114
var sessionManager = ConsoleSessionManager.Instance;
115115
var proxyPid = sessionManager.ProxyPid;
116-
var testPipeName = $"PowerShell.MCP.Communication.{proxyPid}.{DefaultAgentId}.99996";
116+
var testPipeName = $"PSMCP.{proxyPid}.{DefaultAgentId}.99996";
117117

118118
sessionManager.SetActivePipeName(DefaultAgentId, testPipeName);
119119

@@ -156,7 +156,7 @@ public async Task CollectAllCachedOutputsAsync_ExcludesPipeName_SkipsExcluded()
156156
{
157157
var sessionManager = ConsoleSessionManager.Instance;
158158
var proxyPid = sessionManager.ProxyPid;
159-
var testPipeName = $"PowerShell.MCP.Communication.{proxyPid}.{DefaultAgentId}.99995";
159+
var testPipeName = $"PSMCP.{proxyPid}.{DefaultAgentId}.99995";
160160

161161
sessionManager.SetActivePipeName(DefaultAgentId, testPipeName);
162162

Tests/Unit/Proxy/PipelineHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void GetPidString_NullPipeName_ReturnsUnknown()
7676
[Fact]
7777
public void GetPidString_ValidPipeName_ReturnsPid()
7878
{
79-
var pipeName = "PowerShell.MCP.Communication.1234.5678";
79+
var pipeName = "PSMCP.1234.5678";
8080
var result = PipelineHelper.GetPidString(pipeName);
8181
Assert.Equal("5678", result);
8282
}

Tests/Unit/Proxy/PowerShellToolsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PowerShellToolsTests
1818
private readonly Mock<IPowerShellService> _mockPowerShellService;
1919
private readonly Mock<IPipeDiscoveryService> _mockPipeDiscoveryService;
2020
private const string TestAgentId = "test-agent";
21-
private const string TestPipeName = "PowerShell.MCP.Communication.1000.test-agent.2000";
21+
private const string TestPipeName = "PSMCP.1000.test-agent.2000";
2222

2323
public PowerShellToolsTests()
2424
{

0 commit comments

Comments
 (0)