fix mcp tools by passing pullfrog_temp_dir to server and handling home directory correctly for codex and cursor
This commit is contained in:
+10
-1
@@ -1,4 +1,6 @@
|
||||
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 { log } from "../utils/cli.ts";
|
||||
import { addInstructions } from "./instructions.ts";
|
||||
@@ -16,7 +18,13 @@ export const codex = agent({
|
||||
run: async ({ payload, mcpServers, apiKey, cliPath, githubInstallationToken }) => {
|
||||
process.env.OPENAI_API_KEY = apiKey;
|
||||
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 });
|
||||
|
||||
@@ -45,6 +53,7 @@ export const codex = agent({
|
||||
let finalOutput = "";
|
||||
for await (const event of streamedTurn.events) {
|
||||
const handler = messageHandlers[event.type];
|
||||
console.log(event as never);
|
||||
if (handler) {
|
||||
handler(event as never);
|
||||
}
|
||||
|
||||
+10
-11
@@ -1,5 +1,6 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { log } from "../utils/cli.ts";
|
||||
import { addInstructions } from "./instructions.ts";
|
||||
@@ -25,9 +26,6 @@ export const cursor = agent({
|
||||
// and --approve-mcps to automatically approve all MCP servers
|
||||
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...");
|
||||
|
||||
// Use spawn to handle streaming output
|
||||
@@ -42,7 +40,8 @@ export const cursor = agent({
|
||||
...process.env,
|
||||
CURSOR_API_KEY: apiKey,
|
||||
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
|
||||
}
|
||||
@@ -116,14 +115,14 @@ export const cursor = agent({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Configure MCP servers for Cursor by writing to the Cursor configuration file.
|
||||
* For cursor, we need to add the MCP servers to the Cursor configuration file manually as there is no CLI command to do this.
|
||||
*/
|
||||
function configureCursorMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams) {
|
||||
const tempDir = cliPath.split("/.local/bin/")[0];
|
||||
const cursorConfigDir = join(tempDir, ".cursor");
|
||||
// There was an issue on macOS when you set HOME to a temp directory
|
||||
// it was unable to find the macOS keychain and would fail
|
||||
// temp solution is to stick with the actual $HOME
|
||||
function configureCursorMcpServers({ mcpServers }: ConfigureMcpServersParams) {
|
||||
const realHome = homedir();
|
||||
const cursorConfigDir = join(realHome, ".cursor");
|
||||
const mcpConfigPath = join(cursorConfigDir, "mcp.json");
|
||||
mkdirSync(cursorConfigDir, { recursive: true });
|
||||
writeFileSync(mcpConfigPath, JSON.stringify({ mcpServers }, null, 2), "utf-8");
|
||||
log.info(`MCP config written to ${mcpConfigPath}`);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export function createMcpConfigs(
|
||||
GITHUB_REPOSITORY: githubRepository,
|
||||
PULLFROG_MODES: JSON.stringify(modes),
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user