Expand description
MCP JSON-RPC envelope codec for SIM.
This crate provides codec:mcp, a pure data codec for one MCP JSON-RPC
envelope per frame. It owns only envelope validation and conversion; routing,
transport, and callable execution live in later MCP libraries. As a domain
codec it round-trips only MCP envelopes and fails closed outside them.
Module map (all modules are private; the public surface is re-exported from this crate root):
- canonical: the
McpCodecdecoder/encoder and theMcpCodecLibhost lib bridging MCP JSON-RPC text and the envelope model. - envelope: the envelope types (
McpEnvelopeand its request, notification, response, and error variants) and their class symbols. - error: the JSON-RPC and MCP error-code constants and the codec error helper.
- expr: conversion between envelopes and checked
Exprvalues (envelope_to_expr,expr_to_envelope).
Structs§
- McpCodec
- The
codec:mcpdecoder/encoder. - McpCodec
Lib - The host-registered
Libthat installsMcpCodecas the domain codeccodec:mcp. - McpError
- The error object inside an
McpErrorEnvelope. - McpError
Envelope - A JSON-RPC error response for a prior request.
- McpNotification
- A JSON-RPC notification: a method call with no
idand no response. - McpRequest
- A JSON-RPC request: an addressed method call expecting a response.
- McpResponse
- A JSON-RPC successful response for a prior request.
Enums§
- McpEnvelope
- One MCP JSON-RPC 2.0 envelope: the typed payload carried by a single frame.
Constants§
- CANCELLED
- MCP cancelled: the request was cancelled before completion (
-32003). - CAPABILITY_
DENIED - MCP capability denied: a required capability was not granted (
-32001). - EXECUTION_
ERROR - MCP execution error: a tool or method failed while executing (
-32002). - INTERNAL_
ERROR - JSON-RPC internal error: an internal failure occurred (
-32603). - INVALID_
PARAMS - JSON-RPC invalid params: the method parameters are invalid (
-32602). - INVALID_
REQUEST - JSON-RPC invalid request: the payload is not a valid request object
(
-32600). - METHOD_
NOT_ FOUND - JSON-RPC method not found: the requested method does not exist (
-32601). - NOT_
FOUND - MCP not found: the addressed resource does not exist (
-32004). - PARSE_
ERROR - JSON-RPC parse error: invalid JSON was received (
-32700). - RATE_
LIMITED - MCP rate limited: the request was throttled (
-32005).
Functions§
- envelope_
to_ expr - Project an
McpEnvelopeinto its canonicalExprmap, with themcpversion field and the variant-specific fields. - expr_
to_ envelope - Validate a canonical
Exprmap back into a typedMcpEnvelope. - mcp_
error_ class_ symbol - The stable class symbol
mcp/ErrorforMcpError. - mcp_
error_ envelope_ class_ symbol - The stable class symbol
mcp/ErrorEnvelopeforMcpErrorEnvelope. - mcp_
notification_ class_ symbol - The stable class symbol
mcp/NotificationforMcpNotification. - mcp_
request_ class_ symbol - The stable class symbol
mcp/RequestforMcpRequest. - mcp_
response_ class_ symbol - The stable class symbol
mcp/ResponseforMcpResponse.