mcpfixture

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package mcpfixture provides deterministic official-MCP-SDK fixtures for runtime and OAuth integration tests.

Index

Constants

View Source
const (

	// ModernProtocolVersion is the latest MCP revision exercised by the fixture.
	ModernProtocolVersion = "2026-07-28"
	// LegacyProtocolVersion is the legacy revision used after negotiation fallback.
	LegacyProtocolVersion = "2025-11-25"
	// ToolListTTLMs is the deterministic cache hint returned by modern tools/list.
	ToolListTTLMs = 60_000
)
View Source
const (

	// AuthorizationCode is the deterministic authorization code returned by the fixture.
	AuthorizationCode = "mcpfixture-authorization-code"
	// AccessToken is the deterministic access token returned by the fixture.
	// #nosec G101 -- deterministic test-fixture value, never a credential.
	AccessToken = "mcpfixture-access-token"
	// RefreshToken is the deterministic refresh token returned by the fixture.
	// #nosec G101 -- deterministic test-fixture value, never a credential.
	RefreshToken = "mcpfixture-refresh-token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixture

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

Fixture exposes one deterministic official Go SDK MCP server profile.

func MustNew

func MustNew(profile Profile) *Fixture

MustNew constructs a fixture and panics only for a programmer-supplied invalid profile.

func New

func New(profile Profile) (*Fixture, error)

New constructs a deterministic server for profile.

func (*Fixture) Profile

func (f *Fixture) Profile() Profile

Profile reports the fixture's interoperability profile.

func (*Fixture) RunStdio

func (f *Fixture) RunStdio(ctx context.Context, input io.ReadCloser, output io.WriteCloser) error

RunStdio serves newline-delimited MCP JSON over input and output until ctx ends.

func (*Fixture) Server

func (f *Fixture) Server() *mcp.Server

Server returns the official Go SDK server used by this fixture.

func (*Fixture) StartHTTP

func (f *Fixture) StartHTTP(t testing.TB) *httptest.Server

StartHTTP starts the fixture on a loopback server and closes it with t.

func (*Fixture) StreamableHTTPHandler

func (f *Fixture) StreamableHTTPHandler() http.Handler

StreamableHTTPHandler returns a stateless, JSON-response Streamable HTTP handler.

type OAuthConfig

type OAuthConfig struct {
	ResourceURL                                string
	MCPPath                                    string
	Scopes                                     []string
	StepUpScope                                string
	CallbackIssuer                             string
	AuthorizationResponseIssParameterSupported bool
	ClientIDMetadataDocumentSupported          bool
}

OAuthConfig configures the optional local OAuth surface around an MCP fixture.

type OAuthEndpoints

type OAuthEndpoints struct {
	MCPURL               string
	ProtectedResourceURL string
	IssuerURL            string
	AuthorizationURL     string
	TokenURL             string
	RegistrationURL      string
	ClientMetadataURL    string
}

OAuthEndpoints identifies the local, dynamically generated OAuth endpoints.

type OAuthHTTPServer

type OAuthHTTPServer struct {
	Server    *httptest.Server
	Endpoints OAuthEndpoints
	// contains filtered or unexported fields
}

OAuthHTTPServer combines a fixture MCP endpoint and a local OAuth authority.

func StartOAuthHTTP

func StartOAuthHTTP(t testing.TB, fixture *Fixture, config OAuthConfig) *OAuthHTTPServer

StartOAuthHTTP starts a fixture with protected-resource metadata, authorization, token, dynamic-registration, client-metadata, refresh, mix-up, and step-up surfaces.

func (*OAuthHTTPServer) Requests

func (s *OAuthHTTPServer) Requests() OAuthRequests

Requests returns independent snapshots of every received OAuth boundary request.

type OAuthRequests

type OAuthRequests struct {
	MCPHeaders    []http.Header
	Authorization []url.Values
	Token         []url.Values
	Registration  []map[string]any
}

OAuthRequests records observable OAuth boundary inputs without emitting them to logs.

type Profile

type Profile string

Profile selects an MCP interoperability behavior exposed by a Fixture.

const (
	// ProfileModern2026 implements the 2026-07-28 stateless server/discover flow.
	ProfileModern2026 Profile = "modern-2026"
	// ProfileLegacy2025 rejects server/discover so clients negotiate through initialize.
	ProfileLegacy2025 Profile = "legacy-2025"
	// ProfileInputRequired returns an MRTR input-required tool result.
	ProfileInputRequired Profile = "input-required"
)

Jump to

Keyboard shortcuts

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