Skip to content

Commit 88c8f5a

Browse files
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
1 parent c5968be commit 88c8f5a

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github/index.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@modelcontextprotocol/sdk/types.js";
88
import { z } from 'zod';
99
import { zodToJsonSchema } from 'zod-to-json-schema';
10+
import fetch, { Request, Response } from 'node-fetch';
1011

1112
import * as repository from './operations/repository.js';
1213
import * as files from './operations/files.js';
@@ -27,6 +28,11 @@ import {
2728
} from './common/errors.js';
2829
import { VERSION } from "./common/version.js";
2930

31+
// If fetch doesn't exist in global scope, add it
32+
if (!globalThis.fetch) {
33+
globalThis.fetch = fetch as unknown as typeof global.fetch;
34+
}
35+
3036
const server = new Server(
3137
{
3238
name: "github-mcp-server",
@@ -248,10 +254,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
248254
case "create_issue": {
249255
const args = issues.CreateIssueSchema.parse(request.params.arguments);
250256
const { owner, repo, ...options } = args;
251-
const issue = await issues.createIssue(owner, repo, options);
252-
return {
253-
content: [{ type: "text", text: JSON.stringify(issue, null, 2) }],
254-
};
257+
258+
try {
259+
console.error(`[DEBUG] Attempting to create issue in ${owner}/${repo}`);
260+
console.error(`[DEBUG] Issue options:`, JSON.stringify(options, null, 2));
261+
262+
const issue = await issues.createIssue(owner, repo, options);
263+
264+
console.error(`[DEBUG] Issue created successfully`);
265+
return {
266+
content: [{ type: "text", text: JSON.stringify(issue, null, 2) }],
267+
};
268+
} catch (err) {
269+
// Type guard for Error objects
270+
const error = err instanceof Error ? err : new Error(String(err));
271+
272+
console.error(`[ERROR] Failed to create issue:`, error);
273+
274+
if (error instanceof GitHubResourceNotFoundError) {
275+
throw new Error(
276+
`Repository '${owner}/${repo}' not found. Please verify:\n` +
277+
`1. The repository exists\n` +
278+
`2. You have correct access permissions\n` +
279+
`3. The owner and repository names are spelled correctly`
280+
);
281+
}
282+
283+
// Safely access error properties
284+
throw new Error(
285+
`Failed to create issue: ${error.message}${
286+
error.stack ? `\nStack: ${error.stack}` : ''
287+
}`
288+
);
289+
}
255290
}
256291

257292
case "create_pull_request": {

0 commit comments

Comments
 (0)