|
| 1 | +// Package servercard provides the GitHub MCP Server's MCP Server Card |
| 2 | +// (SEP-2127) types and a public, no-auth HTTP handler that serves it. |
| 3 | +// |
| 4 | +// A Server Card is a static metadata document that describes a remote MCP |
| 5 | +// server — its identity, repository, and HTTP transport — so clients can |
| 6 | +// discover and connect to it before the protocol handshake. It is remote-only |
| 7 | +// and deliberately does NOT enumerate primitives (tools, resources, prompts) |
| 8 | +// or installable packages; those remain in the MCP Registry document |
| 9 | +// (server.json) and runtime listing. |
| 10 | +// |
| 11 | +// See: |
| 12 | +// - https://github.com/modelcontextprotocol/experimental-ext-server-card |
| 13 | +// - https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2127 |
| 14 | +package servercard |
| 15 | + |
| 16 | +const ( |
| 17 | + // SchemaURL is the v1 Server Card JSON Schema URI that emitted cards |
| 18 | + // conform to. The schema is versioned by its `vN` path segment. |
| 19 | + SchemaURL = "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json" |
| 20 | + |
| 21 | + // MediaType is the media type used to serve and request a Server Card. |
| 22 | + MediaType = "application/mcp-server-card+json" |
| 23 | + |
| 24 | + // Path is the suffix, relative to a server's streamable-HTTP URL, at which |
| 25 | + // MCP reserves the recommended Server Card location. A server hosted at |
| 26 | + // `https://host/mcp` therefore serves its card at `https://host/mcp/server-card`. |
| 27 | + Path = "/server-card" |
| 28 | + |
| 29 | + // DefaultRemoteURL is the streamable-HTTP endpoint of the hosted GitHub MCP |
| 30 | + // Server on github.com. The remote repository overrides this per environment. |
| 31 | + DefaultRemoteURL = "https://api.githubcopilot.com/mcp/" |
| 32 | +) |
| 33 | + |
| 34 | +// Identity fields reused from the MCP Registry document (server.json) so the |
| 35 | +// Server Card and the registry entry describe the same server. |
| 36 | +const ( |
| 37 | + serverName = "io.github.github/github-mcp-server" |
| 38 | + serverTitle = "GitHub" |
| 39 | + serverDescription = "Connect AI assistants to GitHub - manage repos, issues, PRs, and workflows through natural language." |
| 40 | + repositoryURL = "https://github.com/github/github-mcp-server" |
| 41 | + repositorySource = "github" |
| 42 | + // repositoryID is the github.com repository ID for github/github-mcp-server. |
| 43 | + // It is stable across renames and changes if the repository is recreated. |
| 44 | + repositoryID = "942771284" |
| 45 | +) |
| 46 | + |
| 47 | +// ServerCard is a static metadata document describing a remote MCP server, |
| 48 | +// suitable for pre-connection discovery. It mirrors the ServerCard interface in |
| 49 | +// modelcontextprotocol/experimental-ext-server-card. Server Cards are |
| 50 | +// remote-only and never carry installable packages. |
| 51 | +type ServerCard struct { |
| 52 | + // Schema is the Server Card JSON Schema URI this document conforms to. |
| 53 | + Schema string `json:"$schema"` |
| 54 | + // Name is the server name in reverse-DNS format with exactly one slash. |
| 55 | + Name string `json:"name"` |
| 56 | + // Version is the server version, equivalent to Implementation.version. |
| 57 | + Version string `json:"version"` |
| 58 | + // Description is a short, human-readable explanation of server functionality. |
| 59 | + Description string `json:"description"` |
| 60 | + // Title is an optional human-readable display name. |
| 61 | + Title string `json:"title,omitempty"` |
| 62 | + // WebsiteURL optionally links to the server's homepage or documentation. |
| 63 | + WebsiteURL string `json:"websiteUrl,omitempty"` |
| 64 | + // Repository optionally describes the server's source code for inspection. |
| 65 | + Repository *Repository `json:"repository,omitempty"` |
| 66 | + // Icons optionally lists sized icons a client may render. |
| 67 | + Icons []Icon `json:"icons,omitempty"` |
| 68 | + // Remotes lists the HTTP-based endpoints for connecting to the server. |
| 69 | + Remotes []Remote `json:"remotes,omitempty"` |
| 70 | + // Meta carries vendor-specific metadata using reverse-DNS namespacing. |
| 71 | + Meta map[string]any `json:"_meta,omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +// Repository describes the MCP server's source code location. |
| 75 | +type Repository struct { |
| 76 | + // URL is the repository URL for browsing source and cloning. |
| 77 | + URL string `json:"url"` |
| 78 | + // Source is the hosting service identifier (e.g. "github"). |
| 79 | + Source string `json:"source"` |
| 80 | + // Subfolder is an optional clean relative path within a monorepo. |
| 81 | + Subfolder string `json:"subfolder,omitempty"` |
| 82 | + // ID is the optional repository identifier owned by the hosting service. |
| 83 | + ID string `json:"id,omitempty"` |
| 84 | +} |
| 85 | + |
| 86 | +// Remote describes a remote (HTTP-based) MCP server endpoint. |
| 87 | +type Remote struct { |
| 88 | + // Type is the transport type ("streamable-http" or "sse"). |
| 89 | + Type string `json:"type"` |
| 90 | + // URL is the endpoint URL template. Variables in {curly_braces} are |
| 91 | + // substituted from Variables before the client connects. |
| 92 | + URL string `json:"url"` |
| 93 | + // Headers describes HTTP headers required or accepted when connecting. |
| 94 | + Headers []KeyValueInput `json:"headers,omitempty"` |
| 95 | + // Variables defines values referenced by {curly_braces} in URL and headers. |
| 96 | + Variables map[string]Input `json:"variables,omitempty"` |
| 97 | + // SupportedProtocolVersions lists MCP protocol versions this endpoint serves. |
| 98 | + SupportedProtocolVersions []string `json:"supportedProtocolVersions,omitempty"` |
| 99 | +} |
| 100 | + |
| 101 | +// Input is a user-supplied or pre-set value for a remote URL variable or |
| 102 | +// header value. |
| 103 | +type Input struct { |
| 104 | + // Description is a human-readable explanation of the input. |
| 105 | + Description string `json:"description,omitempty"` |
| 106 | + // IsRequired indicates the input must be supplied to connect. |
| 107 | + IsRequired bool `json:"isRequired,omitempty"` |
| 108 | + // IsSecret indicates the value is sensitive and must be handled securely. |
| 109 | + IsSecret bool `json:"isSecret,omitempty"` |
| 110 | + // Format specifies the input format ("string", "number", "boolean", "filepath"). |
| 111 | + Format string `json:"format,omitempty"` |
| 112 | + // Default is the default value for the input. |
| 113 | + Default string `json:"default,omitempty"` |
| 114 | + // Placeholder is example guidance shown during configuration. |
| 115 | + Placeholder string `json:"placeholder,omitempty"` |
| 116 | + // Value is a pre-set value that end users should not configure. |
| 117 | + Value string `json:"value,omitempty"` |
| 118 | + // Choices, when set, constrains the input to one of the listed values. |
| 119 | + Choices []string `json:"choices,omitempty"` |
| 120 | +} |
| 121 | + |
| 122 | +// KeyValueInput is a named Input used to describe an HTTP header. |
| 123 | +type KeyValueInput struct { |
| 124 | + Input |
| 125 | + // Name is the header name. |
| 126 | + Name string `json:"name"` |
| 127 | + // Variables defines values referenced by {curly_braces} in Value. |
| 128 | + Variables map[string]Input `json:"variables,omitempty"` |
| 129 | +} |
| 130 | + |
| 131 | +// Icon is an optionally-sized icon a client may display. |
| 132 | +type Icon struct { |
| 133 | + // Src is a URI (HTTP(S) or data:) pointing to an icon resource. |
| 134 | + Src string `json:"src"` |
| 135 | + // MimeType optionally overrides the source MIME type. |
| 136 | + MimeType string `json:"mimeType,omitempty"` |
| 137 | + // Sizes optionally lists sizes (e.g. "48x48" or "any") the icon supports. |
| 138 | + Sizes []string `json:"sizes,omitempty"` |
| 139 | + // Theme optionally indicates the theme ("light" or "dark") the icon suits. |
| 140 | + Theme string `json:"theme,omitempty"` |
| 141 | +} |
| 142 | + |
| 143 | +// Config controls how the GitHub MCP Server card is built. |
| 144 | +type Config struct { |
| 145 | + // Version is advertised as the card's version and SHOULD match the |
| 146 | + // runtime serverInfo version. When empty, "0.0.0-dev" is used. |
| 147 | + Version string |
| 148 | + |
| 149 | + // RemoteURL is the absolute streamable-HTTP endpoint advertised in the |
| 150 | + // card's single remote. When empty, DefaultRemoteURL is used. The remote |
| 151 | + // repository supplies a per-environment URL here. |
| 152 | + RemoteURL string |
| 153 | +} |
| 154 | + |
| 155 | +// NewServerCard builds the GitHub MCP Server's Server Card from cfg. |
| 156 | +func NewServerCard(cfg Config) *ServerCard { |
| 157 | + version := cfg.Version |
| 158 | + if version == "" { |
| 159 | + version = "0.0.0-dev" |
| 160 | + } |
| 161 | + |
| 162 | + remoteURL := cfg.RemoteURL |
| 163 | + if remoteURL == "" { |
| 164 | + remoteURL = DefaultRemoteURL |
| 165 | + } |
| 166 | + |
| 167 | + return &ServerCard{ |
| 168 | + Schema: SchemaURL, |
| 169 | + Name: serverName, |
| 170 | + Version: version, |
| 171 | + Description: serverDescription, |
| 172 | + Title: serverTitle, |
| 173 | + WebsiteURL: repositoryURL, |
| 174 | + Repository: &Repository{ |
| 175 | + URL: repositoryURL, |
| 176 | + Source: repositorySource, |
| 177 | + ID: repositoryID, |
| 178 | + }, |
| 179 | + Remotes: []Remote{ |
| 180 | + { |
| 181 | + Type: "streamable-http", |
| 182 | + URL: remoteURL, |
| 183 | + Headers: []KeyValueInput{ |
| 184 | + { |
| 185 | + Input: Input{ |
| 186 | + Description: "Authorization header with authentication token (PAT or App token)", |
| 187 | + IsRequired: true, |
| 188 | + IsSecret: true, |
| 189 | + }, |
| 190 | + Name: "Authorization", |
| 191 | + }, |
| 192 | + }, |
| 193 | + }, |
| 194 | + }, |
| 195 | + } |
| 196 | +} |
0 commit comments