get_github_release
Retrieve the two most recent releases from any GitHub repository to monitor updates, track version changes, or automate workflows using repository owner and name inputs.
Instructions
Get the latest 2 releases from a GitHub repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Owner of the repository (username or organization) | |
| repo | Yes | Name of the repository | |
| token | No | GitHub personal access token (optional) |
Implementation Reference
- src/index.ts:534-601 (handler)The core handler function that implements the tool logic by fetching the latest 2 releases from the GitHub API, formatting the data, and handling errors.async function getGitHubReleases(owner: string, repo: string, token?: string) { // Use provided token or fall back to config token const authToken = token || config.githubToken; try { const headers: Record<string, string> = { 'Accept': 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28' }; if (authToken) { headers['Authorization'] = `Bearer ${authToken}`; } // Fetch releases from the GitHub API - limit to the latest 2 const releasesResponse = await axios.get( `https://api.github.com/repos/${owner}/${repo}/releases?per_page=2`, { headers } ); // Format the release information const releases = releasesResponse.data.map((release: any) => { // Extract asset information const assets = release.assets.map((asset: any) => ({ name: asset.name, size: asset.size, download_count: asset.download_count, browser_download_url: asset.browser_download_url, created_at: asset.created_at, updated_at: asset.updated_at })); return { id: release.id, name: release.name || release.tag_name, tag_name: release.tag_name, published_at: release.published_at, draft: release.draft, prerelease: release.prerelease, html_url: release.html_url, body: release.body, assets: assets, author: { login: release.author.login, html_url: release.author.html_url } }; }); return { count: releases.length, releases: releases }; } catch (error) { if (axios.isAxiosError(error)) { // Handle 404 (no releases) if (error.response?.status === 404) { return { count: 0, releases: [], message: 'No releases found for this repository' }; } throw new Error(`GitHub API error: ${error.response?.status} ${error.response?.statusText} - ${error.response?.data?.message || error.message}`); } throw error; } }
- src/index.ts:194-215 (registration)Tool registration in the tools array passed to server.setTools(), including name, description, and input schema definition.{ name: "get_github_release", description: "Get the latest 2 releases from a GitHub repository", inputSchema: { type: "object", properties: { owner: { type: "string", description: "Owner of the repository (username or organization)" }, repo: { type: "string", description: "Name of the repository" }, token: { type: "string", description: "GitHub personal access token (optional)" } }, required: ["owner", "repo"] } },
- src/index.ts:811-835 (handler)The dispatch handler case within the main CallToolRequestSchema handler that extracts arguments, calls the getGitHubReleases function, and formats the response.case "get_github_release": { const owner = String(request.params.arguments?.owner); const repo = String(request.params.arguments?.repo); const token = request.params.arguments?.token ? String(request.params.arguments?.token) : undefined; if (!owner || !repo) { throw new Error("Owner and repo are required"); } try { const releases = await getGitHubReleases(owner, repo, token); return { content: [{ type: "text", text: JSON.stringify(releases, null, 2) }] }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get GitHub releases: ${error.message}`); } throw error; } }
- src/index.ts:197-214 (schema)The input schema definition for the 'get_github_release' tool, specifying parameters and validation.inputSchema: { type: "object", properties: { owner: { type: "string", description: "Owner of the repository (username or organization)" }, repo: { type: "string", description: "Name of the repository" }, token: { type: "string", description: "GitHub personal access token (optional)" } }, required: ["owner", "repo"] }