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 ¶
- Variables
- func AssertToolListChanged(t testing.TB, h *Harness, timeout time.Duration)
- func AssertToolSet(t testing.TB, h *Harness, want ...string)
- func DecodeToolResult[T any](t testing.TB, res *mcpx.CallToolResult) T
- func EventuallyContains(t testing.TB, timeout, interval time.Duration, fn func() []string, want string)
- type Harness
- func (h *Harness) CallTool(ctx context.Context, name string, args any) (*mcpx.CallToolResult, error)
- func (h *Harness) CallToolWithProgressToken(ctx context.Context, name string, args any, token any) (*mcpx.CallToolResult, error)
- func (h *Harness) ListTools(ctx context.Context) (*mcpx.ListToolsResult, error)
- func (h *Harness) ProgressEvents(token any) []ProgressEvent
- func (h *Harness) WaitForToolListChanged(timeout time.Duration) bool
- type ProgressEvent
Constants ¶
This section is empty.
Variables ¶
var ResultText = mcpx.ResultText
ResultText concatenates the text content of a CallToolResult.
Functions ¶
func AssertToolListChanged ¶
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 ¶
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.
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 ¶
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) ProgressEvents ¶
func (h *Harness) ProgressEvents(token any) []ProgressEvent
ProgressEvents returns a snapshot of progress notifications recorded for token, in receipt order.
func (*Harness) WaitForToolListChanged ¶
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."