Generate a Focused GitHub REST API MCP Server
Generate a minimal, auditable GitHub Issues & Triage MCP server from OpenAPI JSON—zero black-box Docker containers, zero unnecessary repo-admin scopes.
MCP Tool Selection
6 / 10 Free6 endpoints parsed • 1 safety-guarded
List issues in a GitHub repository
Open a new GitHub issue
Get details for a single GitHub issue
Update issue title, state, or labels
Post a comment on an issue
Lock an issue conversation thread
1#!/usr/bin/env node2/**3* Generated by Spec2MCP (https://spec2mcp.com)4* Server: github-issues-rest-api v2022-11-285* Tools exposed: 66*/7import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";8import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";9import { z } from "zod";1011const BASE_URL = (process.env.GITHUB_ISSUES_REST_API_BASE_URL ?? "https://api.github.com").replace(/\/+$/, "");12const API_TOKEN = process.env.GITHUB_ISSUES_REST_API_API_TOKEN ?? "";13function buildAuthHeaders(): Record<string, string> {14return API_TOKEN ? { Authorization: `Bearer ${API_TOKEN}` } : {};15}1617interface UpstreamRequest {18method: string;19path: string;20query?: URLSearchParams;21body?: Record<string, unknown>;22}2324async function callUpstream(req: UpstreamRequest) {25const qs = req.query && req.query.toString() ? `?${req.query.toString()}` : "";26const url = `${BASE_URL}${req.path}${qs}`;2728const headers: Record<string, string> = {29Accept: "application/json",30"User-Agent": "spec2mcp/github-issues-rest-api",31...buildAuthHeaders(),32};3334if (req.body !== undefined) {35headers["Content-Type"] = "application/json";36}3738try {39const controller = new AbortController();40const timer = setTimeout(() => controller.abort(), 20_000);41const response = await fetch(url, {42method: req.method,43headers,44body: req.body !== undefined ? JSON.stringify(req.body) : undefined,45signal: controller.signal,46});47clearTimeout(timer);4849const rawText = await response.text();50let formatted = rawText;51try {52formatted = JSON.stringify(JSON.parse(rawText), null, 2);53} catch {54// keep raw text if upstream returned non-JSON55}5657if (!response.ok) {58return {59isError: true,60content: [61{62type: "text" as const,63text: `HTTP ${response.status} ${response.statusText} from ${req.method} ${req.path}\n${formatted}`,64},65],66};67}6869return {70content: [71{72type: "text" as const,73text: formatted || `HTTP ${response.status} (empty body)`,74},75],76};77} catch (err) {78const message = err instanceof Error ? err.message : String(err);79return {80isError: true,81content: [82{83type: "text" as const,84text: `Network error calling ${req.method} ${url}: ${message}`,85},86],87};88}89}9091const server = new McpServer({92name: "github-issues-rest-api",93version: "2022-11-28",94});9596server.tool(97"list_repo_issues",98"List issues in a GitHub repository [GET /repos/{owner}/{repo}/issues]",99{100"owner": z.string().describe("Repository owner"),101"repo": z.string().describe("Repository name"),102"state": z.enum(["open", "closed", "all"]).describe("Filter by issue state").optional(),103"labels": z.string().describe("Comma-separated label names").optional(),104"per_page": z.number().int().describe("Results per page (max 100)").optional(),105},106{107title: "List issues in a GitHub repository",108readOnlyHint: true,109destructiveHint: false,110idempotentHint: true,111openWorldHint: true,112},113async (args) => {114const query = new URLSearchParams();115if (args["state"] !== undefined) query.set("state", String(args["state"]));116if (args["labels"] !== undefined) query.set("labels", String(args["labels"]));117if (args["per_page"] !== undefined) query.set("per_page", String(args["per_page"]));118return callUpstream({119method: "GET",120path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues`,121query,122});123}124);125126server.tool(127"create_repo_issue",128"Open a new GitHub issue [POST /repos/{owner}/{repo}/issues]",129{130"owner": z.string().describe("Repository owner"),131"repo": z.string().describe("Repository name"),132"title": z.string().describe("Issue title"),133"body": z.string().describe("Markdown description of the issue").optional(),134"labels": z.array(z.unknown()).describe("List of label names").optional(),135"assignees": z.array(z.unknown()).describe("GitHub usernames to assign").optional(),136},137{138title: "Open a new GitHub issue",139readOnlyHint: false,140destructiveHint: false,141idempotentHint: false,142openWorldHint: true,143},144async (args) => {145const bodyPayload: Record<string, unknown> = {};146if (args["title"] !== undefined) bodyPayload["title"] = args["title"];147if (args["body"] !== undefined) bodyPayload["body"] = args["body"];148if (args["labels"] !== undefined) bodyPayload["labels"] = args["labels"];149if (args["assignees"] !== undefined) bodyPayload["assignees"] = args["assignees"];150return callUpstream({151method: "POST",152path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues`,153body: bodyPayload,154});155}156);157158server.tool(159"get_issue",160"Get details for a single GitHub issue [GET /repos/{owner}/{repo}/issues/{issue_number}]",161{162"owner": z.string().describe("Repository owner"),163"repo": z.string().describe("Repository name"),164"issue_number": z.number().int().describe("Issue number"),165},166{167title: "Get details for a single GitHub issue",168readOnlyHint: true,169destructiveHint: false,170idempotentHint: true,171openWorldHint: true,172},173async (args) => {174return callUpstream({175method: "GET",176path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues/${encodeURIComponent(String(args["issue_number"]))}`,177});178}179);180181server.tool(182"update_issue",183"Update issue title, state, or labels [PATCH /repos/{owner}/{repo}/issues/{issue_number}]",184{185"owner": z.string().describe("Repository owner"),186"repo": z.string().describe("Repository name"),187"issue_number": z.number().int().describe("Issue number"),188"title": z.string().describe("Updated title").optional(),189"state": z.enum(["open", "closed"]).describe("New issue state").optional(),190"labels": z.array(z.unknown()).describe("Replacement labels list").optional(),191},192{193title: "Update issue title, state, or labels",194readOnlyHint: false,195destructiveHint: false,196idempotentHint: false,197openWorldHint: true,198},199async (args) => {200const bodyPayload: Record<string, unknown> = {};201if (args["title"] !== undefined) bodyPayload["title"] = args["title"];202if (args["state"] !== undefined) bodyPayload["state"] = args["state"];203if (args["labels"] !== undefined) bodyPayload["labels"] = args["labels"];204return callUpstream({205method: "PATCH",206path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues/${encodeURIComponent(String(args["issue_number"]))}`,207body: bodyPayload,208});209}210);211212server.tool(213"create_issue_comment",214"Post a comment on an issue [POST /repos/{owner}/{repo}/issues/{issue_number}/comments]",215{216"owner": z.string().describe("Repository owner"),217"repo": z.string().describe("Repository name"),218"issue_number": z.number().int().describe("Issue number"),219"body": z.string().describe("Markdown comment body"),220},221{222title: "Post a comment on an issue",223readOnlyHint: false,224destructiveHint: false,225idempotentHint: false,226openWorldHint: true,227},228async (args) => {229const bodyPayload: Record<string, unknown> = {};230if (args["body"] !== undefined) bodyPayload["body"] = args["body"];231return callUpstream({232method: "POST",233path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues/${encodeURIComponent(String(args["issue_number"]))}/comments`,234body: bodyPayload,235});236}237);238239server.tool(240"lock_issue_conversation",241"Lock an issue conversation thread [PUT /repos/{owner}/{repo}/issues/{issue_number}/lock]",242{243"owner": z.string().describe("Repository owner"),244"repo": z.string().describe("Repository name"),245"issue_number": z.number().int().describe("Issue number"),246"lock_reason": z.enum(["off-topic", "too heated", "resolved", "spam"]).describe("Moderation lock reason").optional(),247confirm_destructive_action: z.boolean().describe("Safety guard: must be explicitly set to true to execute this PUT operation."),248},249{250title: "Lock an issue conversation thread",251readOnlyHint: false,252destructiveHint: true,253idempotentHint: true,254openWorldHint: true,255},256async (args) => {257if (!args.confirm_destructive_action) {258return {259isError: true,260content: [{ type: "text", text: "Blocked by safety guard: set confirm_destructive_action=true after user confirmation." }],261};262}263const bodyPayload: Record<string, unknown> = {};264if (args["lock_reason"] !== undefined) bodyPayload["lock_reason"] = args["lock_reason"];265return callUpstream({266method: "PUT",267path: `/repos/${encodeURIComponent(String(args["owner"]))}/${encodeURIComponent(String(args["repo"]))}/issues/${encodeURIComponent(String(args["issue_number"]))}/lock`,268body: bodyPayload,269});270}271);272273async function main() {274const transport = new StdioServerTransport();275await server.connect(transport);276console.error("github-issues-rest-api MCP server listening on stdio (6 tools)");277}278279main().catch((err) => {280console.error("Fatal MCP server error:", err);281process.exit(1);282});283
How to export & compile your GitHub REST OpenAPI spec
Try the built-in 'GitHub Issues' preset right now, or upload a subset of github/rest-api-description.
High-Signal GitHub REST MCP Tools to Expose First
| Method | Endpoint Path | MCP Tool Name | Purpose |
|---|---|---|---|
| GET | /repos/{owner}/{repo}/issues | list_repo_issues | Filter open/closed issues by label |
| POST | /repos/{owner}/{repo}/issues | create_repo_issue | File structured bug reports from Cursor |
| PATCH | /repos/{owner}/{repo}/issues/{issue_number} | update_issue | Update triage labels or close issues |
| POST | /repos/{owner}/{repo}/issues/{issue_number}/comments | create_issue_comment | Post root-cause analysis directly to GitHub |
Best Practices for GitHub REST
- Use GitHub Fine-Grained Personal Access Tokens restricted to a single repository and read/write Issues only.
- Keep lock_issue_conversation and destructive moderation actions behind the confirmation guard.
- Add X-GitHub-Api-Version: 2022-11-28 inside callUpstream() if your organization pins GitHub REST API versions.
Common GitHub REST MCP Gotchas
- GitHub's official OpenAPI description has 1,000+ operations; never load the unpruned spec into an MCP server.
- GitHub returns Pull Requests inside /issues GET responses—remind agents via tool descriptions to inspect the pull_request field if filtering issues only.
- Authenticated PATs get 5,000 requests/hour, whereas unauthenticated calls fail quickly at 60/hour.
GitHub REST API to MCP Server — Frequently Asked Questions
Why generate my own GitHub MCP server instead of using a generic binary?
You own 100% of the ~180 lines of auditable TypeScript or Python code, expose only the exact 5–8 endpoints your workflow needs, and keep your agent's context window lean.
Does it work with GitHub Enterprise Server?
Yes—override GITHUB_ISSUES_REST_API_BASE_URL in mcp.json to https://github.yourcompany.com/api/v3.
Can I add Pull Request diff endpoints too?
Yes. Paste any additional GitHub OpenAPI path definitions (such as /repos/{owner}/{repo}/pulls) into the JSON editor and regenerate immediately.
Related OpenAPI-to-MCP Converters
View all 20HTTP Basic Auth (your-email@company.com:JIRA_API_TOKEN)
Bearer, API Key Header/Query, or Basic via process.env
Environment-variable Bearer, API Key, or Basic Auth headers
Inherits Postman Bearer, API Key, or Basic Auth configuration
Free locally forever. Upgrade when your team goes remote.
Compile focused local TypeScript & Python MCP servers in your browser for $0. Move to Pro Cloud or Team when you need unlimited endpoints, hosted Remote MCP URLs, OAuth2 proxying, and CI sync.
Everything solo engineers need to turn REST APIs into local stdio MCP servers with zero login.
- Local TypeScript SDK + Zod codegen
- Local Python FastMCP + httpx codegen
- Up to 10 endpoints per MCP server
- Live context-window token estimator
- Destructive action confirmation guards
- Claude Desktop, Cursor, Windsurf & Antigravity mcp.json
- 100% client-side — specs stay in browser
Compile unlimited endpoints and publish a hosted Remote MCP URL with encrypted credential vaulting.
- Unlimited OpenAPI endpoints & tool grouping
- 1-click hosted Remote MCP endpoint (Streamable HTTP)
- Encrypted OAuth2 & API-Key secret vault
- Custom tool presets & OpenAPI overlay persistence
- Response payload truncation to stop context blowups
- Priority email & Discord support
Built for engineering orgs keeping internal MCP servers automatically synced with OpenAPI repos.
- Everything in Pro Cloud
- GitHub / GitLab CI auto-sync on OpenAPI PR merges
- Per-tool invocation audit logs & latency metrics
- Per-user rate limits & destructive-tool approval policies
- Role-based access across engineering & ops teams
- Dedicated onboarding & custom auth helpers