Skip to content
docsv0.1.0

JsonRpcService

JSON-RPC 2.0 dispatcher for the Model Context Protocol, running over a {@see ToolRegistry}. Transport-agnostic by design: it takes a decoded JSON-RPC request array and an optional caller {@see ToolContext}, and returns a JSON-RPC response array — nothing here knows about HTTP, SSE, stdio, or how the caller authenticated. A host adapter owns decoding the wire request, resolving the caller into a `ToolContext` (see `Auth\TokenValidatorInterface`), and encoding the response back onto its transport of choice. Covers the MCP method set this package implements: `initialize`, `notifications/initialized`, `tools/list`, `tools/call`.

JsonRpcService::__construct()

public function __construct(Milpa\ToolRuntime\ToolRegistry $toolRegistry):

Parameters

Parameters of __construct()
NameTypeDescription
$toolRegistryMilpa\ToolRuntime\ToolRegistry

JsonRpcService::handle()

public function handle(array $request, ?Milpa\ToolRuntime\Contracts\ToolContext $ctx = null): array

Dispatch one JSON-RPC 2.0 request through the MCP method set and return its response. Never throws for a well-formed-but-unknown method or a failed tool call — those come back as a JSON-RPC `error` member. Only a malformed envelope (missing/wrong `jsonrpc`, missing `method`) throws, since there is no `id` to safely key a response on.

Parameters

Parameters of handle()
NameTypeDescription
$requestarray<string, mixed>
$ctx?Milpa\ToolRuntime\Contracts\ToolContext