Skip to content

Commit 6d7a8f2

Browse files
committed
feat: add get_issue endpoint to retrieve single issue details
Adds functionality to fetch details of a specific GitHub issue by number. This includes: - New GetIssueSchema for input validation - Implementation of getIssue function using GitHub API - Addition of get_issue tool to available tools list - Handler for get_issue in CallToolRequestSchema This allows users to retrieve complete issue information including: - Issue metadata (title, body, state) - Associated data (labels, assignees, milestone) - Timestamps (created, updated, closed)
1 parent 2ecb382 commit 6d7a8f2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/github/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
CreateRepositorySchema,
2121
ForkRepositorySchema,
2222
GetFileContentsSchema,
23+
GetIssueSchema,
2324
GitHubCommitSchema,
2425
GitHubContentSchema,
2526
GitHubCreateUpdateFileResponseSchema,
@@ -691,6 +692,29 @@ async function searchUsers(
691692
return SearchUsersResponseSchema.parse(await response.json());
692693
}
693694

695+
async function getIssue(
696+
owner: string,
697+
repo: string,
698+
issueNumber: number
699+
): Promise<GitHubIssue> {
700+
const response = await fetch(
701+
`https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`,
702+
{
703+
headers: {
704+
Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`,
705+
Accept: "application/vnd.github.v3+json",
706+
"User-Agent": "github-mcp-server",
707+
},
708+
}
709+
);
710+
711+
if (!response.ok) {
712+
throw new Error(`Github API error: ${response.statusText}`);
713+
}
714+
715+
return GitHubIssueSchema.parse(await response.json());
716+
}
717+
694718
server.setRequestHandler(ListToolsRequestSchema, async () => {
695719
return {
696720
tools: [
@@ -778,6 +802,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
778802
description: "Search for users on GitHub",
779803
inputSchema: zodToJsonSchema(SearchUsersSchema),
780804
},
805+
{
806+
name: "get_issue",
807+
description: "Get details of a specific issue in a GitHub repository.",
808+
inputSchema: zodToJsonSchema(GetIssueSchema)
809+
}
781810
],
782811
};
783812
});
@@ -972,6 +1001,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
9721001
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
9731002
}
9741003

1004+
case "get_issue": {
1005+
const args = z.object({
1006+
owner: z.string(),
1007+
repo: z.string(),
1008+
issue_number: z.number()
1009+
}).parse(request.params.arguments);
1010+
const issue = await getIssue(args.owner, args.repo, args.issue_number);
1011+
return { toolResult: issue };
1012+
}
1013+
9751014
default:
9761015
throw new Error(`Unknown tool: ${request.params.name}`);
9771016
}

src/github/schemas.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ export const IssueCommentSchema = z.object({
677677
body: z.string()
678678
});
679679

680+
export const GetIssueSchema = z.object({
681+
owner: z.string().describe("Repository owner (username or organization)"),
682+
repo: z.string().describe("Repository name"),
683+
issue_number: z.number().describe("Issue number")
684+
});
685+
680686
// Export types
681687
export type GitHubAuthor = z.infer<typeof GitHubAuthorSchema>;
682688
export type GitHubFork = z.infer<typeof GitHubForkSchema>;

0 commit comments

Comments
 (0)