testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides shared helpers for tool-handler tests.

The canonical pattern: a test stands up an MCP server with the tool under test registered, connects an in-memory client to it via mcp.NewInMemoryTransports (net.Pipe-backed), and drives the handler through the SDK's CallTool API. This exercises the full schema-validate → handler → response shape end-to-end without spawning the binary or hitting stdio. CLAUDE.md "Where things go" names this as the standard test pattern for Phase 1+ tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeStructured

func DecodeStructured(t *testing.T, v, into any)

DecodeStructured re-encodes the SDK's CallToolResult.StructuredContent (a map[string]any after the JSON-RPC roundtrip) into the test's expected typed value. Tool tests use this to assert tool output shapes without hand-walking the map.

Types

type Harness

type Harness struct {
	Client *mcp.ClientSession
	// contains filtered or unexported fields
}

Harness pairs a connected client and server session for tool-handler tests. Close() tears both down; tests should defer it.

func Connect

func Connect(t *testing.T, register func(*mcp.Server)) *Harness

Connect spins up an in-memory MCP server with `register` already called against it (typically a tool package's Register function), connects an in-memory client, and returns the harness. Use h.Client.CallTool to drive a registered tool.

func (*Harness) Close

func (h *Harness) Close()

Close shuts down both sessions. Safe to call once.

Jump to

Keyboard shortcuts

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