Skip to content

feat(rpc)!: support Standard Schema for RPC definitions with runtime validation - #157

Open
antfubot wants to merge 2 commits into
mainfrom
feat/rpc-standard-schema
Open

feat(rpc)!: support Standard Schema for RPC definitions with runtime validation#157
antfubot wants to merge 2 commits into
mainfrom
feat/rpc-standard-schema

Conversation

@antfubot

@antfubot antfubot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

What

RPC function definitions now accept any Standard Schema validator for their args and returns — valibot, zod, arktype, and others work interchangeably — instead of being locked to valibot's GenericSchema. Declared schemas are also enforced at runtime on every call.

Why

Handlers previously had to author args/returns in valibot, and those schemas only fed type inference and MCP JSON-schema generation — nothing validated the actual payloads at call time. Standing on the Standard Schema interface lets tools bring whichever validator they already use, and makes the declared schemas a real boundary guarantee.

How

  • RpcArgsSchema / RpcReturnSchema and the arg/return type inference are keyed off StandardSchemaV1 (new @standard-schema/spec dependency) rather than valibot.
  • A single seam — getRpcHandler — wraps the resolved handler so local, over-the-wire, and agent/MCP invocations all validate declared args/returns at the boundary. Failures raise coded diagnostics DF0043 (argument) / DF0044 (return value).
  • Validation is guard-only: payloads are never rewritten, so a schema describing a subset of an object doesn't silently strip the sender's extra fields (this preserves existing behaviour such as the terminals plugin returning fields beyond its schema).
  • The MCP JSON-schema surface keeps valibot's precise converter and degrades non-valibot vendors to a permissive object schema. The CLI-flags feature keeps its own valibot usage (out of scope for the RPC definition).

BREAKING CHANGE

Declared args/returns schemas are now enforced at runtime. Previously they were inert (type inference + JSON-schema only), so a call whose real payload didn't match its declared schema still ran. Such calls now throw DF0043 (invalid argument) / DF0044 (invalid return value). Guard-only validation means extra object fields are still allowed, but a schema stricter than reality will start rejecting calls that used to pass. Audit RPCs whose declared schemas may be narrower than what they actually accept/return.

Docs: docs/guide/rpc.md (with a runtime-enforcement warning), plus new docs/errors/DF0043.md and DF0044.md.

This PR was created with the help of an agent.

…te at runtime

Widen `args`/`returns` from valibot's `GenericSchema` to the
`StandardSchemaV1` interface so valibot, zod, arktype, and any other
Standard Schema validator work interchangeably, and infer handler
types from the schema's Standard Schema input types.

Every invocation path (local, over-the-wire, agent/MCP) now validates
declared `args`/`returns` at the boundary via `getRpcHandler`, throwing
coded diagnostics DF0043 / DF0044 on failure. Validation is guard-only:
payloads are never rewritten, so schemas describing a subset of an
object don't strip the sender's extra fields.

The MCP JSON-schema surface keeps valibot's converter for precise
schemas and degrades non-valibot vendors to a permissive object schema.
@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 864ae06
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a6e742ed9445200084f0e3f
😎 Deploy Preview https://deploy-preview-157--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@antfubot antfubot changed the title feat(rpc): support Standard Schema for RPC definitions with runtime validation feat(rpc)!: support Standard Schema for RPC definitions with runtime validation Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant