servercard

package
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package servercard provides the GitHub MCP Server's MCP Server Card (SEP-2127) types and a public, no-auth HTTP handler that serves it.

A Server Card is a static metadata document that describes a remote MCP server — its identity, repository, and HTTP transport — so clients can discover and connect to it before the protocol handshake. It is remote-only and deliberately does NOT enumerate primitives (tools, resources, prompts) or installable packages; those remain in the MCP Registry document (server.json) and runtime listing.

See:

Index

Constants

View Source
const (
	// SchemaURL is the v1 Server Card JSON Schema URI that emitted cards
	// conform to. The schema is versioned by its `vN` path segment.
	SchemaURL = "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json"

	// MediaType is the media type used to serve and request a Server Card.
	MediaType = "application/mcp-server-card+json"

	// Path is the suffix, relative to a server's streamable-HTTP URL, at which
	// MCP reserves the recommended Server Card location. A server hosted at
	// `https://host/mcp` therefore serves its card at `https://host/mcp/server-card`.
	Path = "/server-card"

	// DefaultRemoteURL is the streamable-HTTP endpoint of the hosted GitHub MCP
	// Server on github.com. The remote repository overrides this per environment.
	DefaultRemoteURL = "https://api.githubcopilot.com/mcp/"
)

Variables

This section is empty.

Functions

func ServeCard

func ServeCard(w http.ResponseWriter, r *http.Request, card *ServerCard)

ServeCard writes card to w as the canonical Server Card response and is the single source of truth for its headers and conditional-request behavior, so callers that build a card per request get byte-identical ETag and headers.

It sets the CORS headers, a one-hour Cache-Control, and a strong ETag. A matching If-None-Match (strong, weak, or `*`) yields 304; HEAD omits the body. Callers handle method dispatch and Accept negotiation first.

Types

type Config

type Config struct {
	// Version is advertised as the card's version and SHOULD match the
	// runtime serverInfo version. When empty, "0.0.0-dev" is used.
	Version string

	// RemoteURL is the absolute streamable-HTTP endpoint advertised in the
	// card's single remote. When empty, DefaultRemoteURL is used. The remote
	// repository supplies a per-environment URL here.
	RemoteURL string

	// RemoteURLFunc, when set, derives the streamable-HTTP remote URL from the
	// incoming request, taking precedence over RemoteURL whenever it returns a
	// non-empty value. This supports multi-tenant deployments (e.g. proxima)
	// where the absolute URL varies per request (e.g. from X-Forwarded-Host).
	//
	// It is consumed by the Handler when serving a card; NewServerCard ignores
	// it, since the card constructor is not request-aware.
	RemoteURLFunc func(*http.Request) string
}

Config controls how the GitHub MCP Server card is built and served.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the GitHub MCP Server's Server Card over HTTP as public, no-auth metadata. It mirrors the OAuth protected-resource-metadata handler so the remote server repository can mount it and supply a per-environment remote URL via Config.

func NewHandler

func NewHandler(cfg Config) *Handler

NewHandler returns a Handler that serves the card built from cfg.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(r chi.Router)

RegisterRoutes mounts the handler at the single canonical Path for every method (mirroring oauth.AuthHandler) so it owns the route — answering non-GET requests itself rather than falling through to the auth-gated MCP endpoint — and is deliberately exposed at no alternate path.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the Server Card as application/mcp-server-card+json.

It honors GET and HEAD (with OPTIONS preflight), performs content negotiation against the Accept header, supports ETag conditional requests, and is safe to mount at <streamable-http-url>/server-card without authentication middleware.

type Remote

type Remote struct {
	// Type is the transport type ("streamable-http" or "sse").
	Type string `json:"type"`
	// URL is the endpoint URL.
	URL string `json:"url"`
}

Remote describes a remote (HTTP-based) MCP server endpoint. Authentication is intentionally not described here: the hosted server advertises its auth requirements via OAuth protected-resource-metadata discovery, so duplicating them on the card would risk drift and cannot capture every accepted mode.

type Repository

type Repository struct {
	// URL is the repository URL for browsing source and cloning.
	URL string `json:"url"`
	// Source is the hosting service identifier (e.g. "github").
	Source string `json:"source"`
	// ID is the optional repository identifier owned by the hosting service.
	ID string `json:"id,omitempty"`
}

Repository describes the MCP server's source code location.

type ServerCard

type ServerCard struct {
	// Schema is the Server Card JSON Schema URI this document conforms to.
	Schema string `json:"$schema"`
	// Name is the server name in reverse-DNS format with exactly one slash.
	Name string `json:"name"`
	// Version is the server version, equivalent to Implementation.version.
	Version string `json:"version"`
	// Description is a short, human-readable explanation of server functionality.
	Description string `json:"description"`
	// Title is an optional human-readable display name.
	Title string `json:"title,omitempty"`
	// WebsiteURL optionally links to the server's homepage or documentation.
	WebsiteURL string `json:"websiteUrl,omitempty"`
	// Repository optionally describes the server's source code for inspection.
	Repository *Repository `json:"repository,omitempty"`
	// Remotes lists the HTTP-based endpoints for connecting to the server.
	Remotes []Remote `json:"remotes,omitempty"`
}

ServerCard is a static metadata document describing a remote MCP server, suitable for pre-connection discovery. It mirrors the ServerCard interface in modelcontextprotocol/experimental-ext-server-card. Server Cards are remote-only and never carry installable packages.

func NewServerCard

func NewServerCard(cfg Config) *ServerCard

NewServerCard builds the GitHub MCP Server's Server Card from cfg.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL