Documentation
¶
Overview ¶
Package testutil provides test helpers for MCP servers built with mcpkit.
Index ¶
- type TestClient
- func (tc *TestClient) Call(method string, params any) *mcpkit.CallResult
- func (tc *TestClient) ListResourceTemplates() []mcpkit.ResourceTemplate
- func (tc *TestClient) ListResources() []mcpkit.ResourceDef
- func (tc *TestClient) ListTools() []mcpkit.ToolDef
- func (tc *TestClient) ReadResource(uri string) string
- func (tc *TestClient) SubscribeResource(uri string)
- func (tc *TestClient) ToolCall(name string, args any) string
- func (tc *TestClient) UnsubscribeResource(uri string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestClient ¶
type TestClient struct {
*mcpkit.Client
Server *httptest.Server
// contains filtered or unexported fields
}
TestClient wraps an mcpkit.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 *mcpkit.Server, opts ...mcpkit.ClientOption) *TestClient
NewTestClient creates a TestClient from an mcpkit.Server. It starts an httptest.Server (Streamable HTTP), performs the MCP initialize handshake, and registers cleanup. Optional ClientOption values (e.g., WithClientBearerToken) are passed to the client.
func (*TestClient) Call ¶
func (tc *TestClient) Call(method string, params any) *mcpkit.CallResult
Call makes a raw JSON-RPC call. Calls t.Fatal on error.
func (*TestClient) ListResourceTemplates ¶
func (tc *TestClient) ListResourceTemplates() []mcpkit.ResourceTemplate
ListResourceTemplates returns all registered resource templates. Calls t.Fatal on error.
func (*TestClient) ListResources ¶
func (tc *TestClient) ListResources() []mcpkit.ResourceDef
ListResources returns all registered static resources. Calls t.Fatal on error.
func (*TestClient) ListTools ¶
func (tc *TestClient) ListTools() []mcpkit.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.