skillstest

package
v0.75.0 Latest Latest
Warning

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

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

Documentation

Overview

Package skillstest is a fake upstream MCP server that serves skills over raw JSON-RPC on HTTP. It is not built on mcp-go's server because that server answers unknown methods with METHOD_NOT_FOUND and has no hook to add skills/list or skills/get.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixture

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

Fixture is the fake upstream. It is safe for concurrent use.

func New

func New(t testing.TB, opts ...Option) *Fixture

New starts the fixture and registers its shutdown with t.

func NewDetached added in v0.75.0

func NewDetached(opts ...Option) *Fixture

NewDetached builds a fixture without starting a server. Serve it with Handler.

func Start added in v0.75.0

func Start(opts ...Option) *Fixture

Start starts the fixture on an ephemeral port for use outside go test (the cmd/skillsfixture command). The caller owns Close.

func (*Fixture) AddRawEntry

func (f *Fixture) AddRawEntry(entry json.RawMessage)

AddSkill registers a skill. Digests and sizes in the listing are computed from the current bytes each time, so they are correct unless a knob says otherwise. AddRawEntry appends one listing entry exactly as given, after the skills added with AddSkill. It is how a test lists something AddSkill cannot express: a malformed entry, or a second address for a path already listed. Nothing is served for it on skills/get or resources/read.

func (*Fixture) AddSkill

func (f *Fixture) AddSkill(s Skill)

func (*Fixture) Close added in v0.75.0

func (f *Fixture) Close()

Close stops the server started by New or Start; it is a no-op for a fixture built with NewDetached.

func (*Fixture) Count

func (f *Fixture) Count(method string) int

Count returns how many messages with this method were received.

func (*Fixture) Handler added in v0.75.0

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

Handler is the JSON-RPC endpoint, for serving the fixture on a listener the caller owns. It answers every path.

func (*Fixture) Methods

func (f *Fixture) Methods() []string

Methods returns the method of every message received, in order.

func (*Fixture) Mutate

func (f *Fixture) Mutate(path, file string, content []byte)

Mutate replaces one file's bytes. The listing follows, so a later skills/list reports the new digest and size.

func (*Fixture) Requests

func (f *Fixture) Requests() []Request

Requests returns a copy of every JSON-RPC message received, in order.

func (*Fixture) SetDelay

func (f *Fixture) SetDelay(d time.Duration)

SetDelay makes every answer wait d first.

func (*Fixture) SetInstructions added in v0.75.0

func (f *Fixture) SetInstructions(text string)

SetInstructions makes the initialize result carry instructions. Set it before the consumer connects.

func (*Fixture) SetListFailure

func (f *Fixture) SetListFailure(fail bool)

SetListFailure makes skills/list answer with a JSON-RPC error.

func (*Fixture) TryMutate added in v0.75.0

func (f *Fixture) TryMutate(path, file string, content []byte) error

TryMutate is Mutate for callers that cannot panic: it reports an unknown skill as an error instead.

func (*Fixture) URL

func (f *Fixture) URL() string

URL is the endpoint to point a streamable-HTTP upstream at.

type Option

type Option func(*Fixture)

Option configures New.

func WithPageSize

func WithPageSize(n int) Option

WithPageSize makes skills/list return at most n entries per page.

func WithoutExtension

func WithoutExtension() Option

WithoutExtension leaves the skills extension out of the initialize result.

func WithoutResources

func WithoutResources() Option

WithoutResources leaves the resources capability out of the initialize result.

type Request

type Request struct {
	Method string
	// URI is params.uri when present.
	URI string
	// Cursor is params.cursor when present.
	Cursor string
}

Request is one JSON-RPC message the fixture received.

type Skill

type Skill struct {
	Path  string
	Files map[string][]byte

	// ListedFrontmatter replaces the frontmatter in the listing; SKILL.md keeps
	// its own, so the two disagree.
	ListedFrontmatter map[string]any
	// Dynamic lists resources as the string "dynamic".
	Dynamic bool
	// WrongDigest and WrongSize list a digest or size that the served bytes do
	// not match.
	WrongDigest []string
	WrongSize   []string
	// Binary serves the file as a base64 blob instead of text.
	Binary []string
	// Oversize serves the file with this many extra bytes while the listing
	// keeps the original size.
	Oversize map[string]int
	// ListedSize lists this size for the file, whatever its real length.
	ListedSize map[string]int64
}

Skill describes one skill the fixture serves. Path is the part of the skill address after "skill://", for example "pdf" or "acme/billing/refunds". Files maps a path inside the skill to its bytes; SKILL.md is generated when absent.

The knobs below make the fixture lie in one specific way so a test can prove the consumer notices. They name files by their path inside the skill.

Jump to

Keyboard shortcuts

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