Documentation
¶
Overview ¶
Package mcpauthtest is a remote MCP server behind an OAuth sign-in, as Neon's or Notion's is, for the tests of magpie signing in to one (#615).
Index ¶
- func SignIn(t *testing.T, name, u string) mcpauth.State
- func SignInAccount(t *testing.T, name, u, label string) mcpauth.State
- type Fake
- func (f *Fake) AddApp(id, secret string)
- func (f *Fake) FailRenewals(status int)
- func (f *Fake) ForgetRefresh()
- func (f *Fake) RefreshAsked() int
- func (f *Fake) RefuseTokens()
- func (f *Fake) Revoke()
- func (f *Fake) SignIn(t *testing.T, name string) mcpauth.State
- func (f *Fake) Throttle(retryAfter string)
- func (f *Fake) Unthrottle()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fake ¶
type Fake struct {
*httptest.Server
URL string // the MCP endpoint, <server>/mcp
// Registered are the clients registration made, as they asked
Registered []map[string]any
// Exchanged are the code exchanges, Refreshed the renewals asked
Exchanged, Refreshed int
// Calls are the MCP requests that got through: method and JSON-RPC
// method, with the session they named
Calls []string
// Seen are the headers of the last MCP request that got through
Seen http.Header
// SeenQuery is the query of the last MCP request that got through, as
// it came (Exa's ?login is a bare key)
SeenQuery string
ExpiresIn int // what a token is said to last, in seconds
// NoMetadata leaves out the resource metadata: the server of the 2025-03
// spec, whose authorization server is its own origin
NoMetadata bool
// OpenID is an authorization server that is an OpenID provider, as
// Vercel's is: the server names only the scope "openid" and its 401 none,
// and a refresh token is given only to a sign-in that asked for
// offline_access, which the authorization server's metadata offers
OpenID bool
// AuthMethods are the token endpoint's client authentications, as its
// metadata lists them (none when unset): a registration asking for
// another is refused (RFC 7591's invalid_client_metadata), and a client
// registered for a secret is given one and has to send it as it said
AuthMethods []string
// RefuseRegistration turns every registration away as Figma's
// authorization server does a client it doesn't list: 403, a JSON
// content type and the bare body "Forbidden" (#1619)
RefuseRegistration bool
// NoRegistration leaves the registration endpoint out of the metadata,
// as GitHub's does: only an app made beforehand (AddApp) signs in
NoRegistration bool
// Assign is a server that registers the client for another of the
// methods it supports than the one asked for, as RFC 7591's
// registration response lets it: the token endpoint takes it as
// registered
Assign string
// PathAppendMetadata serves the authorization server metadata at
// <issuer>/.well-known/oauth-authorization-server instead of RFC 8414's
// path-inserted URL, while root /.well-known/ paths return an HTML page
PathAppendMetadata bool
// InvalidPathMetadata serves incomplete JSON at the first RFC 8414
// candidate, so discovery must keep trying the later candidates
InvalidPathMetadata bool
// SplitPathMetadata serves the authorization endpoint and token endpoint
// in different candidates, so discovery must not combine their fields
SplitPathMetadata bool
// MetadataPaths records metadata URLs in the order they were requested
MetadataPaths []string
// HoldGet, when set, is a server whose GET event stream sends its
// headers and then nothing until HoldGet closes, as one with no
// notification to send yet does (#7744)
HoldGet chan struct{}
// Tools are what tools/list lists, when set; the reply is otherwise
// the bare method's name
Tools []string
// OpenInitialize is a server that answers initialize and tools/list
// without a token and asks for one only on tools/call, as Google
// Workspace's and Colab's do (#7751): that 401 names metadata of the
// tool's own, /.well-known/oauth-protected-resource/<tool>, declaring
// another resource (the origin) and scope, and its body is a JSON-RPC
// result with isError, not an error. Signing in has to find the
// server's own metadata, at the path-aware URL.
OpenInitialize bool
// contains filtered or unexported fields
}
Fake is the server: its MCP endpoint is URL, which takes only a token it gave out and hasn't revoked.
func (*Fake) AddApp ¶ added in v0.1.1217
AddApp makes an OAuth app the user signs in as, made with the server's vendor rather than registered by magpie: with a secret, it gives it in the token request's form.
func (*Fake) FailRenewals ¶
FailRenewals answers every renewal with status, a token endpoint's outage; 0 renews them again.
func (*Fake) ForgetRefresh ¶
func (f *Fake) ForgetRefresh()
ForgetRefresh makes every refresh token given out so far unusable.
func (*Fake) RefreshAsked ¶
RefreshAsked is how many renewals were asked for, those turned away included.
func (*Fake) RefuseTokens ¶ added in v0.1.1217
func (f *Fake) RefuseTokens()
RefuseTokens turns every token away at the MCP endpoint, one just renewed too, as a server that no longer takes the sign-in does while its token endpoint still renews it.
func (*Fake) Revoke ¶
func (f *Fake) Revoke()
Revoke makes every access token given out so far unusable, as a server that ended them early would.
func (*Fake) SignIn ¶
SignIn signs magpie in to the server as name, standing in for the browser: it opens the sign-in page, which sends it back to magpie.