testutil

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package testutil provides test helpers for MCP servers built with mcpkit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestClient

type TestClient struct {
	*client.Client

	Server *httptest.Server
	// contains filtered or unexported fields
}

TestClient wraps a client.Client with testing.T error handling and an in-process httptest.Server. Methods call t.Fatal on errors.

func NewTestClient

func NewTestClient(t *testing.T, srv *server.Server, opts ...client.ClientOption) *TestClient

NewTestClient creates a TestClient from a server.Server. It starts an httptest.Server (Streamable HTTP), performs the MCP initialize handshake, and registers cleanup. Optional ClientOption values (e.g., client.WithClientBearerToken) are passed to the client.

func (*TestClient) Call

func (tc *TestClient) Call(method string, params any) *client.CallResult

Call makes a raw JSON-RPC call. Calls t.Fatal on error.

func (*TestClient) ListResourceTemplates

func (tc *TestClient) ListResourceTemplates() []core.ResourceTemplate

ListResourceTemplates returns all registered resource templates. Calls t.Fatal on error.

func (*TestClient) ListResources

func (tc *TestClient) ListResources() []core.ResourceDef

ListResources returns all registered static resources. Calls t.Fatal on error.

func (*TestClient) ListTools

func (tc *TestClient) ListTools() []core.ToolDef

ListTools returns all registered tools. Calls t.Fatal on error.

func (*TestClient) ReadResource

func (tc *TestClient) ReadResource(uri string) string

ReadResource reads a resource URI and returns the text content. Calls t.Fatal on error.

func (*TestClient) SubscribeResource added in v0.0.14

func (tc *TestClient) SubscribeResource(uri string)

SubscribeResource subscribes to change notifications for a resource URI. Calls t.Fatal on error.

func (*TestClient) ToolCall

func (tc *TestClient) ToolCall(name string, args any) string

ToolCall invokes a tool and returns the first text content. Calls t.Fatal on error.

func (*TestClient) UnsubscribeResource added in v0.0.14

func (tc *TestClient) UnsubscribeResource(uri string)

UnsubscribeResource removes a subscription for a resource URI. Calls t.Fatal on error.

Jump to

Keyboard shortcuts

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