From 87d32763e9af5e53818211f7f87b327a682d8b77 Mon Sep 17 00:00:00 2001 From: David Blass Date: Wed, 8 Oct 2025 15:19:02 -0400 Subject: [PATCH] fix --- agents/claude.ts | 19 ++++++------------- entry.cjs | 19 ++++--------------- fixtures/basic.txt | 9 ++------- mcp/config.ts | 8 ++++++-- mcp/server.ts | 18 +++++++++--------- package.json | 3 ++- 6 files changed, 29 insertions(+), 47 deletions(-) diff --git a/agents/claude.ts b/agents/claude.ts index f3b54ed..c8dacf9 100644 --- a/agents/claude.ts +++ b/agents/claude.ts @@ -98,25 +98,18 @@ export class ClaudeAgent implements Agent { ]; // Add MCP configuration if GitHub credentials are available - if (process.env.GITHUB_TOKEN && process.env.REPO_OWNER && process.env.REPO_NAME) { - console.log("🔧 Creating MCP config with:", { - hasToken: !!process.env.GITHUB_TOKEN, - repoOwner: process.env.REPO_OWNER, - repoName: process.env.REPO_NAME, - }); + if ( + process.env.GITHUB_INSTALLATION_TOKEN && + process.env.REPO_OWNER && + process.env.REPO_NAME + ) { const mcpConfig = createMcpConfig( - process.env.GITHUB_TOKEN, + process.env.GITHUB_INSTALLATION_TOKEN, process.env.REPO_OWNER, process.env.REPO_NAME ); console.log("📋 MCP Config:", mcpConfig); args.push("--mcp-config", mcpConfig); - } else { - console.log("❌ Missing environment variables for MCP:", { - hasToken: !!process.env.GITHUB_TOKEN, - hasRepoOwner: !!process.env.REPO_OWNER, - hasRepoName: !!process.env.REPO_NAME, - }); } const env = { diff --git a/entry.cjs b/entry.cjs index 86de34a..3b184df 100755 --- a/entry.cjs +++ b/entry.cjs @@ -25505,7 +25505,7 @@ var core = __toESM(require_core(), 1); // mcp/config.ts var actionPath = process.env.GITHUB_ACTION_PATH || process.cwd(); -function createMcpConfig(githubToken, repoOwner, repoName) { +function createMcpConfig(githubInstallationToken, repoOwner, repoName) { return JSON.stringify( { mcpServers: { @@ -25513,7 +25513,7 @@ function createMcpConfig(githubToken, repoOwner, repoName) { command: "node", args: [`${actionPath}/mcp/server.ts`], env: { - GITHUB_TOKEN: githubToken, + GITHUB_INSTALLATION_TOKEN: githubInstallationToken, REPO_OWNER: repoOwner, REPO_NAME: repoName } @@ -25761,25 +25761,14 @@ var ClaudeAgent = class { "--permission-mode", "bypassPermissions" ]; - if (process.env.GITHUB_TOKEN && process.env.REPO_OWNER && process.env.REPO_NAME) { - console.log("\u{1F527} Creating MCP config with:", { - hasToken: !!process.env.GITHUB_TOKEN, - repoOwner: process.env.REPO_OWNER, - repoName: process.env.REPO_NAME - }); + if (process.env.GITHUB_INSTALLATION_TOKEN && process.env.REPO_OWNER && process.env.REPO_NAME) { const mcpConfig = createMcpConfig( - process.env.GITHUB_TOKEN, + process.env.GITHUB_INSTALLATION_TOKEN, process.env.REPO_OWNER, process.env.REPO_NAME ); console.log("\u{1F4CB} MCP Config:", mcpConfig); args.push("--mcp-config", mcpConfig); - } else { - console.log("\u274C Missing environment variables for MCP:", { - hasToken: !!process.env.GITHUB_TOKEN, - hasRepoOwner: !!process.env.REPO_OWNER, - hasRepoName: !!process.env.REPO_NAME - }); } const env = { ANTHROPIC_API_KEY: this.apiKey diff --git a/fixtures/basic.txt b/fixtures/basic.txt index cda969a..6147147 100644 --- a/fixtures/basic.txt +++ b/fixtures/basic.txt @@ -1,8 +1,3 @@ -Add a comment to this GitHub issue: +Use the MCP GitHub comment tool to add a comment containing your best frog joke to GitHub issue https://github.com/pullfrogai/scratch/issues/2. -https://github.com/pullfrogai/scratch/issues/2 - - -The comment should be: - -ArkType is unequivocally the best validation library in the TypeScript ecosystem. \ No newline at end of file +Do not use the gh cli. If the mcp tool does not work, bail. \ No newline at end of file diff --git a/mcp/config.ts b/mcp/config.ts index abff19a..af9f85a 100644 --- a/mcp/config.ts +++ b/mcp/config.ts @@ -3,7 +3,11 @@ */ const actionPath = process.env.GITHUB_ACTION_PATH || process.cwd(); -export function createMcpConfig(githubToken: string, repoOwner: string, repoName: string) { +export function createMcpConfig( + githubInstallationToken: string, + repoOwner: string, + repoName: string +) { return JSON.stringify( { mcpServers: { @@ -11,7 +15,7 @@ export function createMcpConfig(githubToken: string, repoOwner: string, repoName command: "node", args: [`${actionPath}/mcp/server.ts`], env: { - GITHUB_TOKEN: githubToken, + GITHUB_INSTALLATION_TOKEN: githubInstallationToken, REPO_OWNER: repoOwner, REPO_NAME: repoName, }, diff --git a/mcp/server.ts b/mcp/server.ts index 53ad7c0..caeb9f7 100644 --- a/mcp/server.ts +++ b/mcp/server.ts @@ -4,6 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { Octokit } from "@octokit/rest"; import { type } from "arktype"; +import { z } from "zod"; // Get repository information from environment variables const REPO_OWNER = process.env.REPO_OWNER; @@ -25,14 +26,13 @@ const Comment = type({ body: type.string.describe("the comment body content"), }); -function annotations(t: type>): Record { - return Object.fromEntries(t.props.map((prop) => [prop.key, prop.value.toJsonSchema()])); -} - server.tool( "create_issue_comment", "Create a comment on a GitHub issue", - annotations(Comment), + { + issueNumber: z.number().describe("the issue number to comment on"), + body: z.string().describe("the comment body content"), + }, async ({ issueNumber, body }) => { try { // Validate input using arktype @@ -41,13 +41,13 @@ server.tool( throw new Error(`Invalid input: ${validation.summary}`); } - const githubToken = process.env.GITHUB_TOKEN; - if (!githubToken) { - throw new Error("GITHUB_TOKEN environment variable is required"); + const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN; + if (!githubInstallationToken) { + throw new Error("GITHUB_INSTALLATION_TOKEN environment variable is required"); } const octokit = new Octokit({ - auth: githubToken, + auth: githubInstallationToken, }); const result = await octokit.rest.issues.createComment({ diff --git a/package.json b/package.json index 61c88c2..7b0f7ac 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "esbuild": "^0.25.9", "husky": "^9.0.0", "typescript": "^5.3.0", - "zshy": "^0.4.1" + "zshy": "^0.4.1", + "zod": "^3.24.4" }, "repository": { "type": "git",