McpTester
Rasuvaeff\Yii3Mcp\Testing\McpTester
Class — Rasuvaeff\Yii3Mcp — Source
In-process MCP client for testing application tools without HTTP or a transport process: drives the same Streamable HTTP code path the real endpoint uses and returns decoded results.
By default it speaks the handshake era (initialize, session id); given a modern revision (2026-07-28) it speaks the stateless era instead — no initialize, every request carries its own _meta envelope and the standard Mcp-Method/Mcp-Name/Mcp-Param-* headers, built by the SDK's own client classes so the tester cannot drift from a conformant client.
$tester = new McpTester($server, $requestFactory, $responseFactory, $streamFactory);
$tester->callTool('order.status', ['orderId' => '42']);
$modern = new McpTester($server, $requestFactory, $responseFactory, $streamFactory, ProtocolVersion::V2026_07_28);Methods
initialize()
initialize(): arrayPerforms the initialize handshake; called implicitly by the other methods when needed. The modern era has no handshake: there it asks server/discover instead, which answers the same questions.
listTools()
listTools(): arraylistResources()
listResources(): arraylistResourceTemplates()
listResourceTemplates(): arraylistPrompts()
listPrompts(): arraycallTool()
callTool(string $name, array $arguments): arrayCalls a tool and returns the decoded result envelope (content, isError, structuredContent, …).
readResource()
readResource(string $uri): arrayrequest()
request(string $method, ?array $params): array