$ show github/github-mcp-server
This repository implements a production-grade Model Context Protocol (MCP) server that exposes GitHub's REST and GraphQL APIs as a collection of tools, resources, and prompts for AI agents. The server runs in either stdio (local CLI) or HTTP (remote) mode, supporting multiple authentication methods: personal access tokens, OAuth 2.1 (PKCE browser flow, device flow, manual fallback), and GitHub App installation tokens. It provides over 90 fine-grained tools organized into toolsets (issues, pull requests, actions, projects, code scanning, etc.), each with metadata including required OAuth scopes, feature flags, read-only hints, and information flow control (IFC) labels. The architecture is modular: a central inventory builder registers all tools, resources, and prompts; per-request filtering narrows availability based on authentication, feature flags, toolsets, and read-only mode. The HTTP server uses a chi router with middleware for CORS, body limits, token extraction, scope challenge, and MCP method parsing. A React-based UI (Primer components) provides sandboxed forms for creating and editing issues and pull requests, served as embedded HTML resources. The server also includes lockdown mode for prompt injection mitigation, sanitization of user-authored content, field filtering to reduce response size, and telemetry for metrics collection. External dependencies include the MCP Go SDK, go-github (REST), shurcooL/githubv4 (GraphQL), and various utility libraries for OAuth, HTML sanitization, and configuration.
The LLM identified 6 files worth highlighting for reuse:
Provides a generic builder for registering MCP tools, resources, and prompts with metadata (toolset, feature flags, scopes, annotations). Supports per-request filtering by MCP method, read-only mode, feature flags, and custom filters. The builder pattern is self-contained and can be extracted to build any MCP server with similar capability management.
Implements a two-pass sanitization pipeline for user-authored content: removes invisible characters, filters HTML tags using bluemonday, and strips suspicious code-fence metadata. Includes fast paths for inert content and is fully testable. Reusable in any application that needs to sanitize untrusted text before display or storage.
Defines OAuth scope definitions, hierarchy, expansion, and checking. Provides ExpandScopes and HasRequiredScopes functions that compute accepted scopes from required scopes using a defined hierarchy. Self-contained and reusable for any Go service that needs to validate OAuth scopes against a known set.
A ring buffer implementation for efficient log line processing. Supports concurrent writes and reads, with configurable capacity. Reusable in any Go application that needs a fixed-size, thread-safe buffer for streaming data.
Defines SecurityLabel struct with Integrity and Confidentiality fields, and provides constructors for each tool category (e.g., LabelListIssues, LabelSecurityAlert). Labels are attached to tool results to encode security policy. The package is self-contained and can be reused in any system that needs to annotate outputs with integrity/confidentiality metadata.
Provides common tool result constructors (NewToolResultText, NewToolResultError, NewToolResultAwaitingFormSubmission) used across all tool handlers. Encapsulates MCP result creation with consistent error handling and metadata attachment. Reusable in any MCP server implementation.