test

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 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 test has a mock MCP server, for tests of the MCP clients, and connectors

Index

Constants

View Source
const (
	Name    = "test-server"
	Version = "1.0"

	// ResourceName is the server's name, in the metadata of how it's
	// authorized, when it needs to be
	ResourceName = "Test Resource"
)

The name, and version, which the mock server says it is, as it's connected to

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*opt)

Opt is an option of a mock server

func WithAuth

func WithAuth() Opt

WithAuth makes the server need to be authorized, with a bearer token, which its own authorization server issues: its metadata, and the resource's, are at their well-known paths, a client is registered, and a code, which Approve gives, as a person would, is exchanged for a token, with PKCE's S256, which is refreshed

func WithIcons added in v1.6.3

func WithIcons(icons ...sdkmcp.Icon) Opt

WithIcons makes the server send the icons, as it's connected to

func WithPingResult

func WithPingResult(result string) Opt

WithPingResult replies to a ping, with the streamable HTTP transport, with the result, such as [], which some servers reply with, rather than {}

func WithSSE

func WithSSE() Opt

WithSSE serves only the SSE transport, of the 2024-11-05 protocol, rather than the streamable HTTP transport

type Server

type Server struct {
	*httptest.Server

	// The MCP server, which tools, prompts and resources can be added to
	MCP *sdkmcp.Server
	// contains filtered or unexported fields
}

Server is a mock MCP server, over HTTP, which records the headers of the requests it's sent

func NewServer

func NewServer(t *testing.T, opts ...Opt) *Server

NewServer starts a mock MCP server, with the streamable HTTP transport, or only SSE, with WithSSE, which is closed when the test ends

func (*Server) Approve

func (s *Server) Approve(authorizeURL string) (string, error)

Approve approves the authorization URL, as a person would, and returns the URL it redirects to, with a code, and its state, or an error, when it isn't a valid request, such as one without S256

func (*Server) Client

func (s *Server) Client(id, secret string, redirects ...string)

Client adds a client, with its secret, and redirect URIs, as one which is registered beforehand, rather than dynamically, would be

func (*Server) Headers

func (s *Server) Headers() []http.Header

Headers returns the headers of the requests the server has been sent, in the order they were sent

func (*Server) Revoke

func (s *Server) Revoke()

Revoke makes every token the server issued invalid, so it needs to be authorized again

Jump to

Keyboard shortcuts

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