From 6d9c6fd2b1ca9efead9095a2975ae13ffd3c7613 Mon Sep 17 00:00:00 2001 From: ssalbdivad Date: Thu, 9 Oct 2025 18:04:00 -0400 Subject: [PATCH] try to add debugging to mcp server --- agents/claude.ts | 24 ++++++++++++++++++++++++ entry.cjs | 21 ++++++++++++++++++++- mcp/config.ts | 2 +- mcp/debug-server.sh | 16 ++++++++++++++++ package.json | 2 +- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100755 mcp/debug-server.sh diff --git a/agents/claude.ts b/agents/claude.ts index 485258d..b99d12c 100644 --- a/agents/claude.ts +++ b/agents/claude.ts @@ -1,3 +1,4 @@ +import { readFileSync } from "node:fs"; import { access, constants } from "node:fs/promises"; import * as core from "@actions/core"; import { createMcpConfig } from "../mcp/config.ts"; @@ -192,6 +193,29 @@ function processJSONChunk(chunk: string, agent?: ClaudeAgent): void { ], ]) ); + + // Check for failed MCP servers and show debug logs + if (parsedChunk.mcp_servers?.length > 0) { + const failedServers = parsedChunk.mcp_servers.filter( + (server: any) => server.status === "failed" + ); + if (failedServers.length > 0) { + const failedNames = failedServers.map((server: any) => server.name).join(", "); + + // Try to read MCP server debug logs + let debugInfo = ""; + try { + const logContent = readFileSync("/tmp/mcp-server.log", "utf-8"); + core.error("MCP Server Debug Log:"); + core.error(logContent); + debugInfo = " (see debug log above)"; + } catch (logError) { + debugInfo = ` (could not read debug log: ${logError instanceof Error ? logError.message : String(logError)})`; + } + + throw new Error(`MCP servers failed to start: ${failedNames}${debugInfo}`); + } + } } break; diff --git a/entry.cjs b/entry.cjs index f236eea..37c571d 100755 --- a/entry.cjs +++ b/entry.cjs @@ -25500,6 +25500,7 @@ var core4 = __toESM(require_core(), 1); var core2 = __toESM(require_core(), 1); // agents/claude.ts +var import_node_fs = require("node:fs"); var import_promises = require("node:fs/promises"); var core = __toESM(require_core(), 1); @@ -25514,7 +25515,7 @@ function createMcpConfig(githubInstallationToken) { { mcpServers: { minimal_github_comment: { - command: "node", + command: `${actionPath}/mcp/debug-server.sh`, args: [`${actionPath}/mcp/server.ts`], env: { GITHUB_INSTALLATION_TOKEN: githubInstallationToken, @@ -25858,6 +25859,24 @@ function processJSONChunk(chunk, agent) { ] ]) ); + if (parsedChunk.mcp_servers?.length > 0) { + const failedServers = parsedChunk.mcp_servers.filter( + (server) => server.status === "failed" + ); + if (failedServers.length > 0) { + const failedNames = failedServers.map((server) => server.name).join(", "); + let debugInfo = ""; + try { + const logContent = (0, import_node_fs.readFileSync)("/tmp/mcp-server.log", "utf-8"); + core.error("MCP Server Debug Log:"); + core.error(logContent); + debugInfo = " (see debug log above)"; + } catch (logError) { + debugInfo = ` (could not read debug log: ${logError instanceof Error ? logError.message : String(logError)})`; + } + throw new Error(`MCP servers failed to start: ${failedNames}${debugInfo}`); + } + } } break; case "assistant": diff --git a/mcp/config.ts b/mcp/config.ts index 6d64471..64d3d43 100644 --- a/mcp/config.ts +++ b/mcp/config.ts @@ -13,7 +13,7 @@ export function createMcpConfig(githubInstallationToken: string) { { mcpServers: { minimal_github_comment: { - command: "node", + command: `${actionPath}/mcp/debug-server.sh`, args: [`${actionPath}/mcp/server.ts`], env: { GITHUB_INSTALLATION_TOKEN: githubInstallationToken, diff --git a/mcp/debug-server.sh b/mcp/debug-server.sh new file mode 100755 index 0000000..efb4bbf --- /dev/null +++ b/mcp/debug-server.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Wrapper script to capture MCP server logs for debugging +LOG_FILE="/tmp/mcp-server.log" + +echo "=== MCP Server Debug Wrapper Starting ===" >> "$LOG_FILE" +echo "Timestamp: $(date)" >> "$LOG_FILE" +echo "Working directory: $(pwd)" >> "$LOG_FILE" +echo "Environment variables:" >> "$LOG_FILE" +env | grep -E "(GITHUB_|MCP_|NODE_)" >> "$LOG_FILE" +echo "Node.js version: $(node --version)" >> "$LOG_FILE" +echo "Arguments: $@" >> "$LOG_FILE" +echo "=== Starting MCP Server ===" >> "$LOG_FILE" + +# Execute the actual MCP server, capturing both stdout and stderr +exec node "$@" 2>&1 | tee -a "$LOG_FILE" \ No newline at end of file diff --git a/package.json b/package.json index c1681d8..bbd5ea5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pullfrog/action", - "version": "0.0.18", + "version": "0.0.19", "type": "module", "files": [ "index.js",