mcp

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 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 GetPromptRequest added in v0.11.0

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

GetPromptRequest builds a JSON-RPC prompts/get request for the given name and arguments.

func InitializeRequest

func InitializeRequest(id any) *mcpruntime.Request

InitializeRequest builds a JSON-RPC initialize request.

func ListPromptsRequest added in v0.11.0

func ListPromptsRequest(id any) *mcpruntime.Request

ListPromptsRequest builds a JSON-RPC prompts/list request.

func ListResourcesRequest added in v0.11.0

func ListResourcesRequest(id any) *mcpruntime.Request

ListResourcesRequest builds a JSON-RPC resources/list request.

func ListToolsRequest

func ListToolsRequest(id any) *mcpruntime.Request

ListToolsRequest builds a JSON-RPC tools/list request.

func ReadResourceRequest added in v0.11.0

func ReadResourceRequest(id any, uri string) (*mcpruntime.Request, error)

ReadResourceRequest builds a JSON-RPC resources/read request for the given URI.

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) GetPrompt added in v0.11.0

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

GetPrompt sends a prompts/get request for the named prompt 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) ListPrompts added in v0.11.0

func (c *Client) ListPrompts(ctx context.Context) ([]mcpruntime.PromptDef, error)

ListPrompts sends a prompts/list request and returns the parsed prompt definitions.

func (*Client) ListResources added in v0.11.0

func (c *Client) ListResources(ctx context.Context) ([]mcpruntime.ResourceDef, error)

ListResources sends a resources/list request and returns the parsed resource definitions.

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) ReadResource added in v0.11.0

func (c *Client) ReadResource(ctx context.Context, uri string) ([]mcpruntime.ResourceContent, error)

ReadResource sends a resources/read request for the given URI and returns the parsed contents.

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