Skip to main content

sim_codec_mcp/
lib.rs

1//! MCP JSON-RPC envelope codec for SIM.
2//!
3//! This crate provides `codec:mcp`, a pure data codec for one MCP JSON-RPC
4//! envelope per frame. It owns only envelope validation and conversion; routing,
5//! transport, and callable execution live in later MCP libraries. As a domain
6//! codec it round-trips only MCP envelopes and fails closed outside them.
7//!
8//! Module map (all modules are private; the public surface is re-exported from
9//! this crate root):
10//! - canonical: the `McpCodec` decoder/encoder and the `McpCodecLib` host lib
11//!   bridging MCP JSON-RPC text and the envelope model.
12//! - envelope: the envelope types (`McpEnvelope` and its request, notification,
13//!   response, and error variants) and their class symbols.
14//! - error: the JSON-RPC and MCP error-code constants and the codec error
15//!   helper.
16//! - expr: conversion between envelopes and checked `Expr` values
17//!   (`envelope_to_expr`, `expr_to_envelope`).
18//! - wire_keys: duplicate-preserving checks for MCP-owned JSON object fields.
19
20#![forbid(unsafe_code)]
21#![deny(missing_docs)]
22
23mod canonical;
24mod envelope;
25mod error;
26mod expr;
27mod wire_keys;
28
29#[cfg(test)]
30mod tests;
31
32pub use canonical::{McpCodec, McpCodecLib};
33pub use envelope::{
34    McpEnvelope, McpError, McpErrorEnvelope, McpNotification, McpRequest, McpResponse,
35    mcp_error_class_symbol, mcp_error_envelope_class_symbol, mcp_notification_class_symbol,
36    mcp_request_class_symbol, mcp_response_class_symbol,
37};
38pub use error::{
39    CANCELLED, CAPABILITY_DENIED, EXECUTION_ERROR, INTERNAL_ERROR, INVALID_PARAMS, INVALID_REQUEST,
40    METHOD_NOT_FOUND, NOT_FOUND, PARSE_ERROR, RATE_LIMITED,
41};
42pub use expr::{envelope_to_expr, expr_to_envelope};
43
44/// Cookbook recipes for this codec, embedded at build time.
45pub static RECIPES: sim_cookbook::EmbeddedDir =
46    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));