Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose all declared GitHub tools #712

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions src/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,70 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
name: "get_issue",
description: "Get details of a specific issue in a GitHub repository.",
inputSchema: zodToJsonSchema(issues.GetIssueSchema)
},
{
name: "get_pull_request",
description: "Get details of a specific pull request in a GitHub repository",
inputSchema: zodToJsonSchema(pulls.GetPullRequestSchema),
},
{
name: "list_pull_requests",
description: "List pull requests in a GitHub repository with filtering options",
inputSchema: zodToJsonSchema(pulls.ListPullRequestsSchema),
},
{
name: "get_pull_request_files",
description: "Get the list of files changed in a pull request",
inputSchema: zodToJsonSchema(pulls.GetPullRequestFilesSchema),
},
{
name: "get_pull_request_comments",
description: "Get comments on a specific pull request",
inputSchema: zodToJsonSchema(pulls.GetPullRequestCommentsSchema),
},
{
name: "get_pull_request_reviews",
description: "Get reviews for a specific pull request",
inputSchema: zodToJsonSchema(pulls.GetPullRequestReviewsSchema),
},
{
name: "create_pull_request_review",
description: "Create a review for a pull request",
inputSchema: zodToJsonSchema(pulls.CreatePullRequestReviewSchema),
},
{
name: "merge_pull_request",
description: "Merge a pull request",
inputSchema: zodToJsonSchema(pulls.MergePullRequestSchema),
},
{
name: "update_pull_request_branch",
description: "Update a pull request branch with the latest changes from the base branch",
inputSchema: zodToJsonSchema(pulls.UpdatePullRequestBranchSchema),
},
{
name: "get_pull_request_status",
description: "Get the status checks for a pull request",
inputSchema: zodToJsonSchema(pulls.GetPullRequestStatusSchema),
},
{
name: "update_branch",
description: "Update a branch to point to a specific commit SHA",
inputSchema: zodToJsonSchema(z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
branch: z.string().describe("Branch name to update"),
sha: z.string().describe("SHA of the commit to point the branch to"),
})),
},
{
name: "get_branch_sha",
description: "Get the SHA of the latest commit on a branch",
inputSchema: zodToJsonSchema(z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
branch: z.string().describe("Branch name"),
})),
}
],
};
Expand Down Expand Up @@ -335,6 +399,107 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
};
}

case "get_pull_request": {
const args = pulls.GetPullRequestSchema.parse(request.params.arguments);
const pullRequest = await pulls.getPullRequest(args.owner, args.repo, args.pull_number);
return {
content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }],
};
}

case "list_pull_requests": {
const args = pulls.ListPullRequestsSchema.parse(request.params.arguments);
const { owner, repo, ...options } = args;
const pullRequests = await pulls.listPullRequests(owner, repo, options);
return {
content: [{ type: "text", text: JSON.stringify(pullRequests, null, 2) }],
};
}

case "get_pull_request_files": {
const args = pulls.GetPullRequestFilesSchema.parse(request.params.arguments);
const files = await pulls.getPullRequestFiles(args.owner, args.repo, args.pull_number);
return {
content: [{ type: "text", text: JSON.stringify(files, null, 2) }],
};
}

case "get_pull_request_comments": {
const args = pulls.GetPullRequestCommentsSchema.parse(request.params.arguments);
const comments = await pulls.getPullRequestComments(args.owner, args.repo, args.pull_number);
return {
content: [{ type: "text", text: JSON.stringify(comments, null, 2) }],
};
}

case "get_pull_request_reviews": {
const args = pulls.GetPullRequestReviewsSchema.parse(request.params.arguments);
const reviews = await pulls.getPullRequestReviews(args.owner, args.repo, args.pull_number);
return {
content: [{ type: "text", text: JSON.stringify(reviews, null, 2) }],
};
}

case "create_pull_request_review": {
const args = pulls.CreatePullRequestReviewSchema.parse(request.params.arguments);
const { owner, repo, pull_number, ...options } = args;
const review = await pulls.createPullRequestReview(owner, repo, pull_number, options);
return {
content: [{ type: "text", text: JSON.stringify(review, null, 2) }],
};
}

case "merge_pull_request": {
const args = pulls.MergePullRequestSchema.parse(request.params.arguments);
const { owner, repo, pull_number, ...options } = args;
const result = await pulls.mergePullRequest(owner, repo, pull_number, options);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
};
}

case "update_pull_request_branch": {
const args = pulls.UpdatePullRequestBranchSchema.parse(request.params.arguments);
const { owner, repo, pull_number, expected_head_sha } = args;
const result = await pulls.updatePullRequestBranch(owner, repo, pull_number, expected_head_sha);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
};
}

case "get_pull_request_status": {
const args = pulls.GetPullRequestStatusSchema.parse(request.params.arguments);
const status = await pulls.getPullRequestStatus(args.owner, args.repo, args.pull_number);
return {
content: [{ type: "text", text: JSON.stringify(status, null, 2) }],
};
}

case "update_branch": {
const args = z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
branch: z.string().describe("Branch name to update"),
sha: z.string().describe("SHA of the commit to point the branch to"),
}).parse(request.params.arguments);
const result = await branches.updateBranch(args.owner, args.repo, args.branch, args.sha);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
};
}

case "get_branch_sha": {
const args = z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
branch: z.string().describe("Branch name"),
}).parse(request.params.arguments);
const sha = await branches.getBranchSHA(args.owner, args.repo, args.branch);
return {
content: [{ type: "text", text: JSON.stringify(sha, null, 2) }],
};
}

default:
throw new Error(`Unknown tool: ${request.params.name}`);
}
Expand Down