mcpauthtest

package
v0.1.5708 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func SignIn

func SignIn(t *testing.T, name, u string) mcpauth.State

SignIn signs magpie in to the server at u as name, standing in for the browser.

func SignInAccount

func SignInAccount(t *testing.T, name, u, label string) mcpauth.State

SignInAccount signs magpie in to the server at u as name as another account, labelled, standing in for the browser.

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 New

func New(t *testing.T) *Fake

New starts the server.

func (*Fake) AddApp added in v0.1.1217

func (f *Fake) AddApp(id, secret string)

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

func (f *Fake) FailRenewals(status int)

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

func (f *Fake) RefreshAsked() int

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

func (f *Fake) SignIn(t *testing.T, name string) mcpauth.State

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.

func (*Fake) Throttle

func (f *Fake) Throttle(retryAfter string)

Throttle turns every renewal from now on away as Canva's token endpoint does one it rate-limits (#7451): 429, too_many_requests, with retryAfter as its Retry-After unless it is "". Unthrottle ends it.

func (*Fake) Unthrottle

func (f *Fake) Unthrottle()

Unthrottle renews tokens again.

Jump to

Keyboard shortcuts

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