From 88c8f5a34735adcc84a71ffa15d10032ebe733a4 Mon Sep 17 00:00:00 2001 From: steven gonsalvez Date: Thu, 6 Feb 2025 23:26:03 +0000 Subject: [PATCH 1/3] Add error handling and logging for GitHub issue creation - Improve error handling in GitHub issue creation process - Add detailed error messages for repository not found scenarios - Implement global fetch polyfill for node-fetch - Add debug and error logging for issue creation attempts --- package-lock.json | 9 ++++++++- src/github/index.ts | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ce8e521fcc..12482a9e11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4786,6 +4786,12 @@ "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", "license": "MIT" }, + "node_modules/universal-user-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", + "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", + "license": "ISC" + }, "node_modules/universalify": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", @@ -5292,6 +5298,7 @@ "@types/node": "^22", "@types/node-fetch": "^2.6.12", "node-fetch": "^3.3.2", + "universal-user-agent": "^7.0.2", "zod": "^3.22.4", "zod-to-json-schema": "^3.23.5" }, @@ -5445,7 +5452,7 @@ }, "src/memory": { "name": "@modelcontextprotocol/server-memory", - "version": "0.6.2", + "version": "0.6.3", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "1.0.1" diff --git a/src/github/index.ts b/src/github/index.ts index 88b236894f..dbdee604d8 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -7,6 +7,7 @@ import { } from "@modelcontextprotocol/sdk/types.js"; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; +import fetch, { Request, Response } from 'node-fetch'; import * as repository from './operations/repository.js'; import * as files from './operations/files.js'; @@ -27,6 +28,11 @@ import { } from './common/errors.js'; import { VERSION } from "./common/version.js"; +// If fetch doesn't exist in global scope, add it +if (!globalThis.fetch) { + globalThis.fetch = fetch as unknown as typeof global.fetch; +} + const server = new Server( { name: "github-mcp-server", @@ -248,10 +254,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { case "create_issue": { const args = issues.CreateIssueSchema.parse(request.params.arguments); const { owner, repo, ...options } = args; - const issue = await issues.createIssue(owner, repo, options); - return { - content: [{ type: "text", text: JSON.stringify(issue, null, 2) }], - }; + + try { + console.error(`[DEBUG] Attempting to create issue in ${owner}/${repo}`); + console.error(`[DEBUG] Issue options:`, JSON.stringify(options, null, 2)); + + const issue = await issues.createIssue(owner, repo, options); + + console.error(`[DEBUG] Issue created successfully`); + return { + content: [{ type: "text", text: JSON.stringify(issue, null, 2) }], + }; + } catch (err) { + // Type guard for Error objects + const error = err instanceof Error ? err : new Error(String(err)); + + console.error(`[ERROR] Failed to create issue:`, error); + + if (error instanceof GitHubResourceNotFoundError) { + throw new Error( + `Repository '${owner}/${repo}' not found. Please verify:\n` + + `1. The repository exists\n` + + `2. You have correct access permissions\n` + + `3. The owner and repository names are spelled correctly` + ); + } + + // Safely access error properties + throw new Error( + `Failed to create issue: ${error.message}${ + error.stack ? `\nStack: ${error.stack}` : '' + }` + ); + } } case "create_pull_request": { From 732c119c75f83b3395d39a5d3b711eba42b36c33 Mon Sep 17 00:00:00 2001 From: CONG To Quang Date: Mon, 3 Mar 2025 14:00:02 +0700 Subject: [PATCH 2/3] feat(gitlab): Make owner and fork properties optional --- src/gitlab/schemas.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gitlab/schemas.ts b/src/gitlab/schemas.ts index 108c190b3e..00a76537e0 100644 --- a/src/gitlab/schemas.ts +++ b/src/gitlab/schemas.ts @@ -22,10 +22,10 @@ export const GitLabRepositorySchema = z.object({ name: z.string(), path_with_namespace: z.string(), // Changed from full_name to match GitLab API visibility: z.string(), // Changed from private to match GitLab API - owner: GitLabOwnerSchema, + owner: GitLabOwnerSchema.optional(), web_url: z.string(), // Changed from html_url to match GitLab API description: z.string().nullable(), - fork: z.boolean(), + fork: z.boolean().optional(), ssh_url_to_repo: z.string(), // Changed from ssh_url to match GitLab API http_url_to_repo: z.string(), // Changed from clone_url to match GitLab API created_at: z.string(), From 8fe9b4768a14dfbd36326fabba3378a3970788d0 Mon Sep 17 00:00:00 2001 From: Franco Valerio Date: Sun, 9 Mar 2025 20:04:52 -0300 Subject: [PATCH 3/3] fix(gitlab): Invalid arguments error when using v4 API for gitlab.com Make 'merged' property optional and 'diff_refs' nullable in the `GitLabMergeRequestSchema` to align with GitLab V4 API specifications. --- src/gitlab/schemas.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gitlab/schemas.ts b/src/gitlab/schemas.ts index 108c190b3e..efb456eddc 100644 --- a/src/gitlab/schemas.ts +++ b/src/gitlab/schemas.ts @@ -218,12 +218,12 @@ export const GitLabMergeRequestSchema = z.object({ title: z.string(), description: z.string(), // Changed from body to match GitLab API state: z.string(), - merged: z.boolean(), + merged: z.boolean().optional(), author: GitLabUserSchema, assignees: z.array(GitLabUserSchema), source_branch: z.string(), // Changed from head to match GitLab API target_branch: z.string(), // Changed from base to match GitLab API - diff_refs: GitLabMergeRequestDiffRefSchema, + diff_refs: GitLabMergeRequestDiffRefSchema.nullable(), web_url: z.string(), // Changed from html_url to match GitLab API created_at: z.string(), updated_at: z.string(),