Wymcp.Plugs.Validate (Wymcp v0.8.3)

View Source

Message validation: checks the parsed body against the compiled protocol schema (Wymcp.JsonRpc.validate_mcp_request/1) and answers a non-conforming message with HTTP 400 plus -32600, carrying the validator's distilled error — the one-line summary as the envelope's message, one entry per instance location under data.errors. This body's reader is the human debugging a client rather than an LLM, since no LLM authors a JSON-RPC message, so it keeps per-location detail where the tool-arguments path is tuned for a next action. The message a client sends back is not reflected: the client already holds it, and a body of junk answered with a copy of itself doubled the bytes on the wire for nothing.

One message kind bypasses validation, because validating it could only produce an answer the protocol forbids: a notification — Wymcp.Plugs.Dispatch answers it with the acceptance whatever its body, and JSON-RPC forbids an error response to a notification.

One more is refused after the schema admits it: a body the schema names besides a request and a notification is a JSON-RPC response, and the spec forbids a client to send one — this server initiates no request of its own, so nothing here could deliver it. It answers the same -32600 under a fixed sentence and its own rejection reason, :not_a_request, with a null id: on such a body a request and a response are indistinguishable, which is Wymcp.Response.rejection_id/1's rule. What reaches Wymcp.Plugs.Dispatch is therefore a request or a notification and nothing else.

Which kind a body is comes from the classification Wymcp.Plugs.Classify set, never re-read here. Called ahead of that plug — outside Wymcp.Plugs.Pipeline's chain — this one validates against the schema alone and lets a conforming body through whatever its kind.

What the schema checks is framing, not vocabulary: a body naming a method outside the method table passes it. Which bodies reach a method at all, and which methods wymcp acts on, is Wymcp.Plugs.Dispatch's to decide, there — by message classification first, then its table.