From 06542e382a7e9ff8b91f12b85b0438b2b10c7646 Mon Sep 17 00:00:00 2001 From: David Blass Date: Mon, 13 Oct 2025 13:22:15 -0400 Subject: [PATCH] try adding more debug logging --- mcp/server.ts | 212 +++++++++++++++++++++++++++++++++----------------- package.json | 8 +- 2 files changed, 143 insertions(+), 77 deletions(-) diff --git a/mcp/server.ts b/mcp/server.ts index 692aaf3..9b91870 100644 --- a/mcp/server.ts +++ b/mcp/server.ts @@ -6,11 +6,38 @@ import { Octokit } from "@octokit/rest"; import { type } from "arktype"; import { z } from "zod"; import { resolveRepoContext } from "../utils/repo-context.ts"; +import { writeFileSync } from "node:fs"; -const server = new McpServer({ - name: "Minimal GitHub Issue Comment Server", - version: "0.0.1", -}); +// Simple error logging to file +function logError(message: string, error?: any) { + const timestamp = new Date().toISOString(); + const errorText = error + ? `\nError: ${error.message}\nStack: ${error.stack}` + : ""; + const logEntry = `[${timestamp}] ${message}${errorText}\n`; + + try { + writeFileSync("/tmp/mcp-error.log", logEntry, { flag: "a" }); + console.error(logEntry); + } catch (writeError) { + console.error(`Failed to write error log: ${writeError}`); + console.error(logEntry); + } +} + +let server: McpServer; + +try { + logError("Creating MCP server..."); + server = new McpServer({ + name: "Minimal GitHub Issue Comment Server", + version: "0.0.1", + }); + logError("MCP server created successfully"); +} catch (error) { + logError("Failed to create MCP server", error); + process.exit(1); +} // Define the schema for creating issue comments const Comment = type({ @@ -18,78 +45,117 @@ const Comment = type({ body: type.string.describe("the comment body content"), }); -server.tool( - "create_issue_comment", - "Create a comment on a GitHub issue", - { - issueNumber: z.number().describe("the issue number to comment on"), - body: z.string().describe("the comment body content"), - }, - async ({ issueNumber, body }) => { - try { - Comment.assert({ issueNumber, body }); +try { + logError("Registering create_issue_comment tool..."); - const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN; - if (!githubInstallationToken) { - throw new Error( - "GITHUB_INSTALLATION_TOKEN environment variable is required" - ); + server.tool( + "create_issue_comment", + "Create a comment on a GitHub issue", + { + issueNumber: z.number().describe("the issue number to comment on"), + body: z.string().describe("the comment body content"), + }, + async ({ issueNumber, body }) => { + try { + Comment.assert({ issueNumber, body }); + + const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN; + if (!githubInstallationToken) { + throw new Error( + "GITHUB_INSTALLATION_TOKEN environment variable is required" + ); + } + + // Resolve repository context from environment + const repoContext = resolveRepoContext(); + + const octokit = new Octokit({ + auth: githubInstallationToken, + }); + + const result = await octokit.rest.issues.createComment({ + owner: repoContext.owner, + repo: repoContext.name, + issue_number: issueNumber, + body: body, + }); + + return { + content: [ + { + type: "text", + text: JSON.stringify( + { + success: true, + commentId: result.data.id, + url: result.data.html_url, + body: result.data.body, + }, + null, + 2 + ), + }, + ], + }; + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : String(error); + logError("Tool execution failed", error); + return { + content: [ + { + type: "text", + text: `Error creating comment: ${errorMessage}`, + }, + ], + error: errorMessage, + isError: true, + }; } - - // Resolve repository context from environment - const repoContext = resolveRepoContext(); - - const octokit = new Octokit({ - auth: githubInstallationToken, - }); - - const result = await octokit.rest.issues.createComment({ - owner: repoContext.owner, - repo: repoContext.name, - issue_number: issueNumber, - body: body, - }); - - return { - content: [ - { - type: "text", - text: JSON.stringify( - { - success: true, - commentId: result.data.id, - url: result.data.html_url, - body: result.data.body, - }, - null, - 2 - ), - }, - ], - }; - } catch (error) { - const errorMessage = - error instanceof Error ? error.message : String(error); - return { - content: [ - { - type: "text", - text: `Error creating comment: ${errorMessage}`, - }, - ], - error: errorMessage, - isError: true, - }; } - } -); + ); -async function runServer() { - const transport = new StdioServerTransport(); - await server.connect(transport); - process.on("exit", () => { - server.close(); - }); + logError("Tool registered successfully"); +} catch (error) { + logError("Failed to register tool", error); + process.exit(1); } -runServer().catch(console.error); +async function runServer() { + try { + logError("Starting MCP server..."); + + const transport = new StdioServerTransport(); + logError("Transport created, attempting connection..."); + + await server.connect(transport); + logError("MCP server connected successfully"); + + process.on("exit", () => { + logError("Process exiting, closing server..."); + server.close(); + }); + + process.on("SIGTERM", () => { + logError("SIGTERM received, closing server..."); + server.close(); + process.exit(0); + }); + + process.on("SIGINT", () => { + logError("SIGINT received, closing server..."); + server.close(); + process.exit(0); + }); + } catch (error) { + logError("Server startup failed", error); + process.exit(1); + } +} + +logError("Initializing MCP server process..."); + +runServer().catch((error) => { + logError("Unhandled server error", error); + process.exit(1); +}); diff --git a/package.json b/package.json index 33c5ae3..cacd90b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pullfrog/action", - "version": "0.0.22", + "version": "0.0.23", "type": "module", "files": [ "index.js", @@ -34,7 +34,8 @@ "arktype": "^2.1.22", "dotenv": "^17.2.2", "execa": "^9.6.0", - "table": "^6.9.0" + "table": "^6.9.0", + "zod": "^3.24.4" }, "devDependencies": { "@types/node": "^20.10.0", @@ -42,8 +43,7 @@ "esbuild": "^0.25.9", "husky": "^9.0.0", "typescript": "^5.3.0", - "zshy": "^0.4.1", - "zod": "^3.24.4" + "zshy": "^0.4.1" }, "repository": { "type": "git",