fix mcp tools by passing pullfrog_temp_dir to server and handling home directory correctly for codex and cursor

This commit is contained in:
Colin McDonnell
2025-11-20 18:56:45 -08:00
parent 8298cdd07c
commit 550a162ca6
3 changed files with 21 additions and 12 deletions
+10 -1
View File
@@ -1,4 +1,6 @@
import { spawnSync } from "node:child_process"; import { spawnSync } from "node:child_process";
import { mkdirSync } from "node:fs";
import { join } from "node:path";
import { Codex, type CodexOptions, type ThreadEvent } from "@openai/codex-sdk"; import { Codex, type CodexOptions, type ThreadEvent } from "@openai/codex-sdk";
import { log } from "../utils/cli.ts"; import { log } from "../utils/cli.ts";
import { addInstructions } from "./instructions.ts"; import { addInstructions } from "./instructions.ts";
@@ -16,7 +18,13 @@ export const codex = agent({
run: async ({ payload, mcpServers, apiKey, cliPath, githubInstallationToken }) => { run: async ({ payload, mcpServers, apiKey, cliPath, githubInstallationToken }) => {
process.env.OPENAI_API_KEY = apiKey; process.env.OPENAI_API_KEY = apiKey;
process.env.GITHUB_INSTALLATION_TOKEN = githubInstallationToken; process.env.GITHUB_INSTALLATION_TOKEN = githubInstallationToken;
process.env.HOME = process.env.PULLFROG_TEMP_DIR;
// create config directory for codex before setting HOME
const tempHome = process.env.PULLFROG_TEMP_DIR!;
const configDir = join(tempHome, ".config", "codex");
mkdirSync(configDir, { recursive: true });
process.env.HOME = tempHome;
configureCodexMcpServers({ mcpServers, cliPath }); configureCodexMcpServers({ mcpServers, cliPath });
@@ -45,6 +53,7 @@ export const codex = agent({
let finalOutput = ""; let finalOutput = "";
for await (const event of streamedTurn.events) { for await (const event of streamedTurn.events) {
const handler = messageHandlers[event.type]; const handler = messageHandlers[event.type];
console.log(event as never);
if (handler) { if (handler) {
handler(event as never); handler(event as never);
} }
+10 -11
View File
@@ -1,5 +1,6 @@
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import { mkdirSync, writeFileSync } from "node:fs"; import { mkdirSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path"; import { join } from "node:path";
import { log } from "../utils/cli.ts"; import { log } from "../utils/cli.ts";
import { addInstructions } from "./instructions.ts"; import { addInstructions } from "./instructions.ts";
@@ -25,9 +26,6 @@ export const cursor = agent({
// and --approve-mcps to automatically approve all MCP servers // and --approve-mcps to automatically approve all MCP servers
const fullPrompt = addInstructions(payload); const fullPrompt = addInstructions(payload);
// Find temp directory from cliPath to set HOME for MCP config lookup
const tempDir = cliPath.split("/.local/bin/")[0];
log.info("Running Cursor CLI..."); log.info("Running Cursor CLI...");
// Use spawn to handle streaming output // Use spawn to handle streaming output
@@ -42,7 +40,8 @@ export const cursor = agent({
...process.env, ...process.env,
CURSOR_API_KEY: apiKey, CURSOR_API_KEY: apiKey,
GITHUB_INSTALLATION_TOKEN: githubInstallationToken, GITHUB_INSTALLATION_TOKEN: githubInstallationToken,
HOME: tempDir, // Set HOME so Cursor CLI can find .cursor/mcp.json // Don't override HOME - Cursor CLI needs access to macOS keychain
// MCP config is written to tempDir/.cursor/mcp.json which Cursor will find
}, },
stdio: ["ignore", "pipe", "pipe"], // Ignore stdin, pipe stdout/stderr stdio: ["ignore", "pipe", "pipe"], // Ignore stdin, pipe stdout/stderr
} }
@@ -116,14 +115,14 @@ export const cursor = agent({
}, },
}); });
/** // There was an issue on macOS when you set HOME to a temp directory
* Configure MCP servers for Cursor by writing to the Cursor configuration file. // it was unable to find the macOS keychain and would fail
* For cursor, we need to add the MCP servers to the Cursor configuration file manually as there is no CLI command to do this. // temp solution is to stick with the actual $HOME
*/ function configureCursorMcpServers({ mcpServers }: ConfigureMcpServersParams) {
function configureCursorMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams) { const realHome = homedir();
const tempDir = cliPath.split("/.local/bin/")[0]; const cursorConfigDir = join(realHome, ".cursor");
const cursorConfigDir = join(tempDir, ".cursor");
const mcpConfigPath = join(cursorConfigDir, "mcp.json"); const mcpConfigPath = join(cursorConfigDir, "mcp.json");
mkdirSync(cursorConfigDir, { recursive: true }); mkdirSync(cursorConfigDir, { recursive: true });
writeFileSync(mcpConfigPath, JSON.stringify({ mcpServers }, null, 2), "utf-8"); writeFileSync(mcpConfigPath, JSON.stringify({ mcpServers }, null, 2), "utf-8");
log.info(`MCP config written to ${mcpConfigPath}`);
} }
+1
View File
@@ -30,6 +30,7 @@ export function createMcpConfigs(
GITHUB_REPOSITORY: githubRepository, GITHUB_REPOSITORY: githubRepository,
PULLFROG_MODES: JSON.stringify(modes), PULLFROG_MODES: JSON.stringify(modes),
PULLFROG_PAYLOAD: JSON.stringify(payload), PULLFROG_PAYLOAD: JSON.stringify(payload),
PULLFROG_TEMP_DIR: process.env.PULLFROG_TEMP_DIR!,
}; };
// pass through GITHUB_RUN_ID if available (automatically set in GitHub Actions) // pass through GITHUB_RUN_ID if available (automatically set in GitHub Actions)