7
7
} from "@modelcontextprotocol/sdk/types.js" ;
8
8
import { z } from 'zod' ;
9
9
import { zodToJsonSchema } from 'zod-to-json-schema' ;
10
+ import fetch , { Request , Response } from 'node-fetch' ;
10
11
11
12
import * as repository from './operations/repository.js' ;
12
13
import * as files from './operations/files.js' ;
@@ -27,6 +28,11 @@ import {
27
28
} from './common/errors.js' ;
28
29
import { VERSION } from "./common/version.js" ;
29
30
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
+
30
36
const server = new Server (
31
37
{
32
38
name : "github-mcp-server" ,
@@ -293,10 +299,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
293
299
case "create_issue" : {
294
300
const args = issues . CreateIssueSchema . parse ( request . params . arguments ) ;
295
301
const { owner, repo, ...options } = args ;
296
- const issue = await issues . createIssue ( owner , repo , options ) ;
297
- return {
298
- content : [ { type : "text" , text : JSON . stringify ( issue , null , 2 ) } ] ,
299
- } ;
302
+
303
+ try {
304
+ console . error ( `[DEBUG] Attempting to create issue in ${ owner } /${ repo } ` ) ;
305
+ console . error ( `[DEBUG] Issue options:` , JSON . stringify ( options , null , 2 ) ) ;
306
+
307
+ const issue = await issues . createIssue ( owner , repo , options ) ;
308
+
309
+ console . error ( `[DEBUG] Issue created successfully` ) ;
310
+ return {
311
+ content : [ { type : "text" , text : JSON . stringify ( issue , null , 2 ) } ] ,
312
+ } ;
313
+ } catch ( err ) {
314
+ // Type guard for Error objects
315
+ const error = err instanceof Error ? err : new Error ( String ( err ) ) ;
316
+
317
+ console . error ( `[ERROR] Failed to create issue:` , error ) ;
318
+
319
+ if ( error instanceof GitHubResourceNotFoundError ) {
320
+ throw new Error (
321
+ `Repository '${ owner } /${ repo } ' not found. Please verify:\n` +
322
+ `1. The repository exists\n` +
323
+ `2. You have correct access permissions\n` +
324
+ `3. The owner and repository names are spelled correctly`
325
+ ) ;
326
+ }
327
+
328
+ // Safely access error properties
329
+ throw new Error (
330
+ `Failed to create issue: ${ error . message } ${
331
+ error . stack ? `\nStack: ${ error . stack } ` : ''
332
+ } `
333
+ ) ;
334
+ }
300
335
}
301
336
302
337
case "create_pull_request" : {
0 commit comments