mcp

package
v0.10.0-rc Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mcp provides deterministic MCP client simulation and assertion helpers for testing MCP tool implementations without deploying infrastructure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t testing.TB, resp *mcpruntime.Response, expectedCode int)

AssertError asserts that the JSON-RPC response contains an error with the expected error code.

func AssertHasTools

func AssertHasTools(t testing.TB, tools []mcpruntime.ToolDef, names ...string)

AssertHasTools asserts that the tool list contains tools with all the given names.

func AssertToolResult

func AssertToolResult(t testing.TB, resp *mcpruntime.Response, expectedText string)

AssertToolResult asserts that the JSON-RPC response contains a successful tool result with a text content block matching the expected text.

func CallToolRequest

func CallToolRequest(id any, name string, args any) (*mcpruntime.Request, error)

CallToolRequest builds a JSON-RPC tools/call request for the named tool.

func InitializeRequest

func InitializeRequest(id any) *mcpruntime.Request

InitializeRequest builds a JSON-RPC initialize request.

func ListToolsRequest

func ListToolsRequest(id any) *mcpruntime.Request

ListToolsRequest builds a JSON-RPC tools/list request.

Types

type Client

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

Client is a test MCP client that invokes an in-process MCP server.

func NewClient

func NewClient(server *mcpruntime.Server, env *testkit.Env) *Client

NewClient creates a test MCP client backed by the given MCP server and deterministic test environment.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args any) (*mcpruntime.ToolResult, error)

CallTool sends a tools/call request for the named tool with the given arguments.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) (*mcpruntime.Response, error)

Initialize sends an MCP initialize request and captures the returned session ID for use in subsequent requests.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]mcpruntime.ToolDef, error)

ListTools sends a tools/list request and returns the parsed tool definitions.

func (*Client) Raw

Raw sends an arbitrary JSON-RPC request to the MCP server and returns the parsed JSON-RPC response. It automatically includes the session ID header if one has been captured, and captures any new session ID from the response.

func (*Client) SessionID

func (c *Client) SessionID() string

SessionID returns the current session ID captured from the last response.

Jump to

Keyboard shortcuts

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