Documentation
¶
Overview ¶
Package mcp provides deterministic MCP client simulation and assertion helpers for testing MCP tool implementations without deploying infrastructure.
Index ¶
- func AssertError(t testing.TB, resp *mcpruntime.Response, expectedCode int)
- func AssertHasTools(t testing.TB, tools []mcpruntime.ToolDef, names ...string)
- func AssertToolResult(t testing.TB, resp *mcpruntime.Response, expectedText string)
- func CallToolRequest(id any, name string, args any) (*mcpruntime.Request, error)
- func InitializeRequest(id any) *mcpruntime.Request
- func ListToolsRequest(id any) *mcpruntime.Request
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, args any) (*mcpruntime.ToolResult, error)
- func (c *Client) Initialize(ctx context.Context) (*mcpruntime.Response, error)
- func (c *Client) ListTools(ctx context.Context) ([]mcpruntime.ToolDef, error)
- func (c *Client) Raw(ctx context.Context, req *mcpruntime.Request) (*mcpruntime.Response, error)
- func (c *Client) SessionID() string
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 ¶
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 ¶
Initialize sends an MCP initialize request and captures the returned session ID for use in subsequent requests.
func (*Client) ListTools ¶
ListTools sends a tools/list request and returns the parsed tool definitions.
func (*Client) Raw ¶
func (c *Client) Raw(ctx context.Context, req *mcpruntime.Request) (*mcpruntime.Response, error)
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.