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" ,
@@ -248,10 +254,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
248
254
case "create_issue" : {
249
255
const args = issues . CreateIssueSchema . parse ( request . params . arguments ) ;
250
256
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
+ }
255
290
}
256
291
257
292
case "create_pull_request" : {
0 commit comments