Repository navigation
feat: JSON-RPC 2.0 transport with rpc.discover (OpenRPC) - #21
Merged
Merged
Conversation
With laravel-api.jsonrpc.enabled, POST /{prefix}/rpc/{version} serves
every action as a method controller.action with by-name params, through
Runtime\Dispatcher. Failures are errors (-32602 for 422, -32000 otherwise,
status and payload in data); batches and notifications per spec;
rpc.discover answers with an OpenRPC 1.3.2 document. ServedVersions and
NamedOperations are shared with MCP. JsonSchemas::encodable() writes empty
properties/$defs as {} — the OpenRPC validator rejected [].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 2, step 3: the second non-HTTP transport, on
Runtime\Dispatcherlike MCP (#20).What
With
laravel-api.jsonrpc.enabled, every served version answers JSON-RPC 2.0 atPOST /{prefix}/rpc/{version}:controller.action, params by name (an object; positional →-32602: actions have no argument order). Called through the dispatcher — router, middleware cascade, validation, as the caller of the HTTP request (headers passed on).error:-32602(Invalid params) when the action answered 422 — a validation failure — and-32000otherwise;message= the payload'smessage(orerrorKey);data: {status, payload}witherrorKeyand all.-32600; invalid items →-32600withid: null), notifications (carried out, never answered; all-notification → 204). Protocol errors:-32700parse,-32600invalid request,-32601method not found. HTTP status 200 whenever there is a body.rpc.discover→ an OpenRPC 1.3.2 document of the version: one method per action (summary= first summary line,description,paramStructure: by-name, one param per input field withrequired/description/schema,result.schema= the payload schema or the 200@responsetemplate,deprecated), templates undercomponents.schemas— same#/components/schemas/…spelling, so refs pass through unchanged.'jsonrpc' => falseon an action/controller leaves it out; configlaravel-api.jsonrpc(enabled/LARAVEL_API_JSONRPC,versions,path,middleware); routeapi-jsonrpc.Shared with MCP now:
Transports\ServedVersions(which versions a transport serves) andTransports\NamedOperations(thecontroller.action→Operationindex from the route map, with the per-transport opt-out).McpToolset/McpControlleruse them; behaviour unchanged.Checked with the official validator
The OpenRPC documents of all 13 fixture APIs and the example go through
@open-rpc/schema-utils-js(validateOpenRPCDocument+dereferenceDocument). The first run failed on 2 of 7: an action without@outputfields hadresult.schema.properties: []— PHP's empty array encodes as a JSON list where JSON Schema wants a map. NewOperations\Schema\JsonSchemas::encodable()writes emptyproperties/patternProperties/$defs/definitionsas{}; used by the OpenRPC document and by MCP'sinputSchema($defsof a template without fields had the same problem). After it: 13/13 valid and dereferenceable.The OpenAPI document has the same bug —
"properties": []21 times across 6 golden-master snapshots (empty@output, envelope payloads). Not changed here: it moves the snapshots and deserves its own PR — next.Tests
635 passing; golden-master unchanged. New
tests/Feature/Transports/JsonRpcTest.php(12): off by default; call + result; by-name params + header forwarding; failed action →-32000withdata; protocol errors; batch order with notifications and invalid items; notifications-only → 204; served versions;rpc.discovershape; a real validation failure →-32602, status 422, field errors in data (own module + routes);'jsonrpc' => false;JsonSchemas::encodable(); no"properties":[]in a discover document.Docs: README (en/ru/zh/de) "JSON-RPC 2.0", config comments, CHANGELOG, CLAUDE.md.
🤖 Generated with Claude Code