Wymcp. JsonRpc
(Wymcp v0.1.1)
View Source
JSON-RPC 2.0 envelopes and MCP protocol schema validation — the wire-format floor both eras share.
success_response/2 and the two error_response arities build the envelope
every answer is sent as; Wymcp.Response does the sending. The error map is
the one home for wymcp's JSON-RPC error codes: each error_type/0 atom
pairs with its {code, message} tuple, so a call site names the condition
and never the number. This module owns the envelope's shape; it owns no
decision about which condition applies — that is each plug's and each method
module's.
Schema validation
One self-contained MCP protocol schema per era —
priv/schema-2025-11-25.json and priv/schema-2026-07-28.json, JSON Schema
2020-12 — is compiled to a JSV.Root at build time through a module
attribute, so an inbound request is validated against the official protocol
definition with no runtime schema parsing. Both schemas name the same entry
point, JSONRPCMessage; validate_mcp_request/2 selects the era's root from
the era Wymcp.Plugs.Validate passes it. @external_resource on both paths
makes an edit to either schema file recompile this module.
A rejection is answered as a distilled map — a one-line message plus
an errors list of %{at:, problems:} entries, one per instance location,
each location's problems deduplicated — never JSV.normalize_error/1's
full tree. Both callers put it on the wire under the JSON-RPC error's
data: validate_schema/2 on the -32602 tool-arguments path, whose
reader is the calling LLM, and validate_mcp_request/2 on the -32600
message path, whose reader is the human debugging a client. The full tree
is JSON-encodable and was what previously reached the wire; it is simply
too verbose for either reader — 2353 bytes against 435 for one garbage
message, measured 2026-08-15.