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

feat: add GitHub releases listing support #561

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions src/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MCP Server for the GitHub API, enabling file operations, repository management,
- **Git History Preservation**: Operations maintain proper Git history without force pushing
- **Batch Operations**: Support for both single-file and multi-file operations
- **Advanced Search**: Support for searching code, issues/PRs, and users
- **Get Repo Releases**: Retrieve the latest releases of a repository to assist with dependency management


## Tools
Expand Down Expand Up @@ -277,6 +278,24 @@ MCP Server for the GitHub API, enabling file operations, repository management,
- `pull_number` (number): Pull request number
- Returns: Array of pull request reviews with details like the review state (APPROVED, CHANGES_REQUESTED, etc.), reviewer, and review body

27. `list_releases`
- List releases for a GitHub repository
- Inputs:
- `owner` (string): Repository owner
- `repo` (string): Repository name
- `page` (optional number): Page number for pagination
- `perPage` (optional number): Results per page (max 100)
- `includeAssets` (optional boolean): Whether to include release assets (default: false)
- Returns: Array of repository releases with metadata (and optionally assets)

28. `get_latest_release`
- Get the latest release for a GitHub repository
- Inputs:
- `owner` (string): Repository owner
- `repo` (string): Repository name
- `includeAssets` (optional boolean): Whether to include release assets (default: false)
- Returns: Latest release with metadata (and optionally assets)

## Search Query Syntax

### Code Search
Expand Down
45 changes: 45 additions & 0 deletions src/github/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,49 @@ export type GitHubMilestone = z.infer<typeof GitHubMilestoneSchema>;
export type GitHubIssue = z.infer<typeof GitHubIssueSchema>;
export type GitHubSearchResponse = z.infer<typeof GitHubSearchResponseSchema>;
export type GitHubPullRequest = z.infer<typeof GitHubPullRequestSchema>;
// Release schemas
export const GitHubReleaseAssetSchema = z.object({
url: z.string(),
id: z.number(),
node_id: z.string(),
name: z.string(),
label: z.string().nullable(),
content_type: z.string(),
state: z.string(),
size: z.number(),
download_count: z.number(),
created_at: z.string(),
updated_at: z.string(),
browser_download_url: z.string()
});

export const GitHubReleaseSchema = z.object({
url: z.string(),
assets_url: z.string(),
upload_url: z.string(),
html_url: z.string(),
id: z.number(),
node_id: z.string(),
tag_name: z.string(),
target_commitish: z.string(),
name: z.string().nullable(),
draft: z.boolean(),
prerelease: z.boolean(),
created_at: z.string(),
published_at: z.string().nullable(),
assets: z.array(GitHubReleaseAssetSchema).optional(),
tarball_url: z.string(),
zipball_url: z.string(),
body: z.string().nullable(),
author: GitHubOwnerSchema
}).transform(data => {
// Ensure assets is always an array even if not included
return {
...data,
assets: data.assets || []
};
});

export type GitHubRelease = z.infer<typeof GitHubReleaseSchema>;
export type GitHubReleaseAsset = z.infer<typeof GitHubReleaseAssetSchema>;
export type GitHubPullRequestRef = z.infer<typeof GitHubPullRequestRefSchema>;
27 changes: 27 additions & 0 deletions src/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as pulls from './operations/pulls.js';
import * as branches from './operations/branches.js';
import * as search from './operations/search.js';
import * as commits from './operations/commits.js';
import * as releases from './operations/releases.js';
import {
GitHubError,
GitHubValidationError,
Expand Down Expand Up @@ -148,6 +149,16 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
name: "get_issue",
description: "Get details of a specific issue in a GitHub repository.",
inputSchema: zodToJsonSchema(issues.GetIssueSchema)
},
{
name: "list_releases",
description: "List releases for a GitHub repository",
inputSchema: zodToJsonSchema(releases.ListReleasesOptionsSchema)
},
{
name: "get_latest_release",
description: "Get the latest release for a GitHub repository",
inputSchema: zodToJsonSchema(releases.GetLatestReleaseSchema)
}
],
};
Expand Down Expand Up @@ -334,6 +345,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
};
}

case "list_releases": {
const args = releases.ListReleasesOptionsSchema.parse(request.params.arguments);
const releasesList = await releases.listReleases(args);
return {
content: [{ type: "text", text: JSON.stringify(releasesList, null, 2) }],
};
}

case "get_latest_release": {
const args = releases.GetLatestReleaseSchema.parse(request.params.arguments);
const latestRelease = await releases.getLatestRelease(args);
return {
content: [{ type: "text", text: JSON.stringify(latestRelease, null, 2) }],
};
}

default:
throw new Error(`Unknown tool: ${request.params.name}`);
}
Expand Down
64 changes: 64 additions & 0 deletions src/github/operations/releases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { z } from "zod";
import { buildUrl, githubRequest } from "../common/utils.js";
import { GitHubReleaseSchema } from "../common/types.js";

// Schema definitions
export const ListReleasesOptionsSchema = z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
page: z.number().optional().describe("Page number for pagination (default: 1)"),
perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)"),
includeAssets: z.boolean().optional().describe("Whether to include release assets in the response (default: false)")
});

export const GetLatestReleaseSchema = z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
includeAssets: z.boolean().optional().describe("Whether to include release assets in the response (default: false)")
});

export type ListReleasesOptions = z.infer<typeof ListReleasesOptionsSchema>;
export type GetLatestReleaseOptions = z.infer<typeof GetLatestReleaseSchema>;

// Function implementations
export async function listReleases({
owner,
repo,
page = 1,
perPage = 30,
includeAssets = false
}: ListReleasesOptions) {
const url = buildUrl(`https://api.github.com/repos/${owner}/${repo}/releases`, {
page: page.toString(),
per_page: perPage.toString(),
});

const response = await githubRequest(url);
const releases = z.array(GitHubReleaseSchema).parse(response);

if (!includeAssets) {
return releases.map(release => {
const { assets, ...rest } = release;
return { ...rest, assets: [] };
});
}

return releases;
}

export async function getLatestRelease({
owner,
repo,
includeAssets = false
}: GetLatestReleaseOptions) {
const url = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
const response = await githubRequest(url);
const release = GitHubReleaseSchema.parse(response);

if (!includeAssets) {
const { assets, ...rest } = release;
return { ...rest, assets: [] };
}

return release;
}