Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions clients/mcpdo/__tests__/mcp-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,48 @@ describe("mcp.ts coverage", () => {
expect(unknown.stderr).toContain(`(config ${configPath}`);
});

// Windows named pipes have no sun_path limit, so the check is a no-op there.
it.skipIf(process.platform === "win32")(
"an over-limit daemon socket path fails connections/list and MRU inference like connect does (#2823)",
async () => {
configPath = createSampleTestConfig();
const e = env();
// Never created: the point is that nothing could ever bind here.
const longDir = path.join(storageDir!, "d".repeat(120));
const longEnv = { ...e, MCP_INSPECTOR_DAEMON_DIR: longDir };

const listed = await runMcp(["connections/list", "--format", "json"], {
env: longEnv,
});
expectCliFailure(listed);
expect(listed.stdout).not.toMatch(/connections/);
expect(listed.stderr).toMatch(/socket path is too long/);
expect(listed.stderr).toContain(path.join(longDir, "mcpdod.sock"));

const noMru = await runMcp(["servers/show", "--config", configPath], {
env: longEnv,
timeout: 20000,
});
expectCliFailure(noMru);
expect(noMru.stderr).toMatch(/socket path is too long/);
expect(noMru.stderr).not.toMatch(/no most-recently-used connection/);

// Neither command starts the daemon, or even creates its directory.
expect(fs.existsSync(longDir)).toBe(false);

// Same error, same exit code as the command that would start it.
const connected = await runMcp(
["connect", "test-stdio", "--config", configPath],
{ env: longEnv, timeout: 20000 },
);
expectCliFailure(connected);
expect(connected.stderr).toMatch(/socket path is too long/);

expect(listed.exitCode).toBe(connected.exitCode);
expect(noMru.exitCode).toBe(connected.exitCode);
},
);

it("connections/list and daemon status do not auto-spawn the daemon", async () => {
const e = env();
const listed = await runMcp(["connections/list", "--format", "json"], {
Expand Down
35 changes: 25 additions & 10 deletions clients/mcpdo/src/connection/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import {
getSecretStorageInfo,
warnAboutSecretStorage,
} from "@inspector/core/auth/node/secret-store-selection.js";
import { callDaemon, ensureDaemon } from "../daemon/index.js";
import {
assertSocketPathWithinLimit,
callDaemon,
ensureDaemon,
getDaemonSocketPath,
} from "../daemon/index.js";
import type {
ConnectionInfo,
ConnectionShowResult,
Expand Down Expand Up @@ -122,6 +127,19 @@ function isDaemonUnreachable(error: unknown): boolean {
);
}

/**
* For commands that read "daemon unreachable" as "nothing is connected"
* without starting the daemon (`connections/list`, MRU name inference):
* rethrow anything that is not an unreachable daemon, and fail with
* `ensureDaemon()`'s own socket-path error when the daemon could never bind
* in this environment at all (#2823). Without the check, an over-limit
* socket path reads as a healthy empty machine while `connect` refuses.
*/
function assertNoDaemonMeansNothingConnected(error: unknown): void {
if (!isDaemonUnreachable(error)) throw error;
assertSocketPathWithinLimit(getDaemonSocketPath());
}

/**
* `servers/show` with no name falls back to the MRU connection's entry name,
* under the same non-interactive gate as MRU connection targeting: an agent
Expand All @@ -145,7 +163,7 @@ async function resolveMruEntryName(): Promise<string> {
);
connections = result.connections;
} catch (error) {
if (!isDaemonUnreachable(error)) throw error;
assertNoDaemonMeansNothingConnected(error);
}
const mru = connections.find((c) => c.isMru);
if (!mru) {
Expand Down Expand Up @@ -1062,14 +1080,11 @@ function registerConnectionAdmin(program: CommandType): void {
connections: result.connections,
});
} catch (error) {
if (isDaemonUnreachable(error)) {
await writeConnectionOutput(outOpts(opts), {
kind: "connections/list",
connections: [],
});
return;
}
throw error;
assertNoDaemonMeansNothingConnected(error);
await writeConnectionOutput(outOpts(opts), {
kind: "connections/list",
connections: [],
});
}
});

Expand Down
Loading