Documentation
¶
Overview ¶
Package auth is the client side of MCP authorization over HTTP: it finds the server's authorization server, runs the authorization code flow with PKCE on a loopback redirect, and sends and refreshes the token on every request. The client is either registered with the authorization server beforehand or identified by its Client ID Metadata Document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClientRequired = errors.New("auth: the authorization server needs a client registered with it")
ErrClientRequired is the authorization server taking only clients registered with it beforehand, and Config naming none.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
Authorizer holds the authorization of one MCP server. It is safe for concurrent use.
func New ¶
func New(cfg Config) *Authorizer
func (*Authorizer) Login ¶
func (a *Authorizer) Login(ctx context.Context) (*Login, error)
Login starts an authorization: it finds the authorization server and listens for the redirect on a loopback port. Wait completes it.
func (*Authorizer) Transport ¶
func (a *Authorizer) Transport(base http.RoundTripper) http.RoundTripper
Transport returns a RoundTripper that sends the stored token, refreshing it when it expires or the server rejects it. When no token works, the server's 401 or 403 is returned as is; Login then asks the user.
type Config ¶
type Config struct {
Server string // the MCP endpoint URL
Store Store
// ClientID, with ClientSecret if it has one, is a client registered
// beforehand with the server's authorization server, its redirect URI
// http://127.0.0.1/callback on any port (RFC 8252 Section 7.3).
ClientID string
ClientSecret string
// ClientMetadataURL is the https URL of the client's Client ID Metadata
// Document, its client_id with authorization servers that accept one.
// The document lists the loopback redirect URIs to listen on.
ClientMetadataURL string
// HTTPClient makes the metadata and token requests; nil means a client
// with a 30-second timeout.
HTTPClient *http.Client
}
type Login ¶
type Login struct {
// URL is the authorization page the user must open in a browser.
URL string
// contains filtered or unexported fields
}
Login is an authorization waiting for the user.
type Store ¶
type Store interface {
Token(server string) (*Token, error) // nil when absent
SaveToken(server string, t *Token) error // nil deletes
}
Store persists tokens by MCP server URL. They are secrets.
type Token ¶
type Token struct {
Issuer string `json:"issuer"`
ClientID string `json:"client_id"` // the client it was issued to
Resource string `json:"resource"` // the RFC 8707 resource it was issued for
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
Expiry time.Time `json:"expiry,omitzero"`
Scope string `json:"scope,omitempty"`
}
Token is an access token for one MCP server.