testkit

package
v0.0.0-...-8763363 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 9 Imported by: 0

README

testkit

Package testkit is mcpkit's shipped in-memory MCP test harness, built on mcpx.InMemoryPair (no subprocess). It is used by mcpkit's own tests and is intended for reuse by downstream consumers.

Reference

Documentation

Overview

Package testkit is mcpkit's shipped in-memory MCP test harness, built on mcpx.InMemoryPair (no subprocess). It is used by mcpkit's own tests and is intended for reuse by downstream consumers.

Index

Constants

This section is empty.

Variables

View Source
var ResultText = mcpx.ResultText

ResultText concatenates the text content of a CallToolResult.

Functions

func AssertToolListChanged

func AssertToolListChanged(t testing.TB, h *Harness, timeout time.Duration)

AssertToolListChanged fails the test unless the harness observes at least one notifications/tools/list_changed notification within timeout. The go-sdk debounces rapid successive list changes into a single notification, so this asserts "at least one arrived," never an exact count.

func AssertToolSet

func AssertToolSet(t testing.TB, h *Harness, want ...string)

AssertToolSet asserts that the app's advertised tools/list is exactly want, guarding against silent drift.

func DecodeToolResult

func DecodeToolResult[T any](t testing.TB, res *mcpx.CallToolResult) T

DecodeToolResult json-unmarshals a tool result's text content into T via jsonutil.Unmarshal, failing the test on decode error.

func EventuallyContains

func EventuallyContains(t testing.TB, timeout, interval time.Duration, fn func() []string, want string)

EventuallyContains polls fn until it returns a slice containing want, or fails the test after timeout.

Types

type Harness

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

Harness wires an in-memory MCP client to an *mcpkit.App for testing.

func New

func New(t testing.TB, app *mcpkit.App) *Harness

New composes app over an in-memory transport pair, connects a client, and returns a ready Harness. The client is closed automatically via t.Cleanup.

func (*Harness) CallTool

func (h *Harness) CallTool(ctx context.Context, name string, args any) (*mcpx.CallToolResult, error)

CallTool calls the named tool with args, which must be JSON-marshalable.

func (*Harness) CallToolWithProgressToken

func (h *Harness) CallToolWithProgressToken(ctx context.Context, name string, args any, token any) (*mcpx.CallToolResult, error)

CallToolWithProgressToken calls the named tool with args and attaches token as the request's progress token, so server-side progress notifications for this call can be retrieved via ProgressEvents(token).

func (*Harness) ListTools

func (h *Harness) ListTools(ctx context.Context) (*mcpx.ListToolsResult, error)

ListTools lists the tools the composed app advertises.

func (*Harness) ProgressEvents

func (h *Harness) ProgressEvents(token any) []ProgressEvent

ProgressEvents returns a snapshot of progress notifications recorded for token, in receipt order.

func (*Harness) WaitForToolListChanged

func (h *Harness) WaitForToolListChanged(timeout time.Duration) bool

WaitForToolListChanged blocks until the harness observes at least one notifications/tools/list_changed notification, or timeout elapses. It returns true on the former, false on the latter. Because the go-sdk debounces bursts of list changes into a single notification (~10ms), callers should not assert an exact count — one call observes "at least one arrived."

type ProgressEvent

type ProgressEvent struct {
	Token    any
	Message  string
	Progress float64
	Total    float64
}

ProgressEvent is one progress notification received for a tracked token.

Jump to

Keyboard shortcuts

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