Skip to content

Commit 502e217

Browse files
committed
Fix MCP client for Codex on Mac too
1 parent 1ee7d02 commit 502e217

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/api/bridge-client.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import * as http from 'http';
22
import * as path from 'path';
3+
import { execFile } from 'child_process';
4+
import { promisify } from 'util';
35

46
import { getDeferred } from '@httptoolkit/util';
57

68
import { getSocketPath } from './ui-operation-bridge';
79

10+
const execFileAsync = promisify(execFile);
11+
let darwinTempDirPromise: Promise<string | undefined> | undefined;
12+
13+
function getDarwinTempDir(): Promise<string | undefined> {
14+
if (!darwinTempDirPromise) {
15+
darwinTempDirPromise = execFileAsync(
16+
'/usr/bin/getconf',
17+
['DARWIN_USER_TEMP_DIR'],
18+
{ encoding: 'utf8', timeout: 1000 }
19+
)
20+
.then(({ stdout }) => stdout.trim() || undefined)
21+
.catch(() => undefined);
22+
}
23+
24+
return darwinTempDirPromise;
25+
}
26+
827
export async function apiRequest(
928
method: 'GET' | 'POST',
1029
urlPath: string,
@@ -22,6 +41,15 @@ export async function apiRequest(
2241
`${process.getuid()}`,
2342
'httptoolkit-ctl.sock'
2443
));
44+
} else if (process.platform === 'darwin') {
45+
const darwinTempDir = await getDarwinTempDir();
46+
const darwinSocketPath = darwinTempDir
47+
? path.join(darwinTempDir, 'httptoolkit-ctl.sock')
48+
: undefined;
49+
50+
if (darwinSocketPath && !socketPaths.includes(darwinSocketPath)) {
51+
socketPaths.push(darwinSocketPath);
52+
}
2553
}
2654

2755
for (let i = 0; i < socketPaths.length; i++) {

0 commit comments

Comments
 (0)