From 6d7a8f2267ba571bb590d1b51add95173e5a659f Mon Sep 17 00:00:00 2001 From: Aschent89 Date: Fri, 6 Dec 2024 14:03:12 -0500 Subject: [PATCH 1/2] 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) --- src/github/index.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/github/schemas.ts | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/src/github/index.ts b/src/github/index.ts index 287cfdcb..3759e8b5 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -20,6 +20,7 @@ import { CreateRepositorySchema, ForkRepositorySchema, GetFileContentsSchema, + GetIssueSchema, GitHubCommitSchema, GitHubContentSchema, GitHubCreateUpdateFileResponseSchema, @@ -691,6 +692,29 @@ async function searchUsers( return SearchUsersResponseSchema.parse(await response.json()); } +async function getIssue( + owner: string, + repo: string, + issueNumber: number +): Promise { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`, + { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + } +); + + if (!response.ok) { + throw new Error(`Github API error: ${response.statusText}`); + } + + return GitHubIssueSchema.parse(await response.json()); +} + server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ @@ -778,6 +802,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { description: "Search for users on GitHub", inputSchema: zodToJsonSchema(SearchUsersSchema), }, + { + name: "get_issue", + description: "Get details of a specific issue in a GitHub repository.", + inputSchema: zodToJsonSchema(GetIssueSchema) + } ], }; }); @@ -972,6 +1001,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } + case "get_issue": { + const args = z.object({ + owner: z.string(), + repo: z.string(), + issue_number: z.number() + }).parse(request.params.arguments); + const issue = await getIssue(args.owner, args.repo, args.issue_number); + return { toolResult: issue }; + } + default: throw new Error(`Unknown tool: ${request.params.name}`); } diff --git a/src/github/schemas.ts b/src/github/schemas.ts index bd0d8618..cefdc1d1 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -677,6 +677,12 @@ export const IssueCommentSchema = z.object({ body: z.string() }); +export const GetIssueSchema = z.object({ + owner: z.string().describe("Repository owner (username or organization)"), + repo: z.string().describe("Repository name"), + issue_number: z.number().describe("Issue number") +}); + // Export types export type GitHubAuthor = z.infer; export type GitHubFork = z.infer; From 90380945895480a556fc2f9dfa035d20776461cf Mon Sep 17 00:00:00 2001 From: Aschent89 Date: Fri, 6 Dec 2024 14:08:01 -0500 Subject: [PATCH 2/2] Update the github-server readme to outline 'get_issue' --- src/github/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/github/README.md b/src/github/README.md index cc0a09c3..1898f9e1 100644 --- a/src/github/README.md +++ b/src/github/README.md @@ -180,6 +180,14 @@ MCP Server for the GitHub API, enabling file operations, repository management, - `sha` (optional string): branch name - Returns: List of commits +17. `get_issue` + - Gets the contents of an issue within a repository + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `issue_number` (number): Issue number to retrieve + - Returns: Github Issue object & details + ## Search Query Syntax ### Code Search