Expand description
§mcpr-protocol
MCP specification layer: JSON-RPC 2.0 parsing, MCP method classification, and session lifecycle management.
This crate is the foundation of the mcpr workspace. It contains everything related to understanding the MCP protocol itself, with zero coupling to HTTP frameworks or proxy logic.
§Responsibilities
-
JSON-RPC 2.0 parsing (
lib.rs): Parse and classify JSON-RPC 2.0 messages (requests, notifications, responses). ProvidesParsedBodyfor batch-aware parsing andMcpMethodfor typed MCP method discrimination. -
MCP method constants: Single source of truth for MCP method strings (
initialize,tools/call,resources/read, etc.). -
Error handling: JSON-RPC error codes, error response builders, and error extraction from response bodies.
-
Session management (
sessionmodule): MCP session state machine (Created -> Initialized -> Active -> Closed),SessionStoretrait for pluggable storage backends, andMemorySessionStorefor in-memory use. -
Schema primitives (
schemamodule): Pagination detection/merging, schema diffing (detect added/removed/modified tools, resources, prompts), and schema method classification. Pure helpers, no state. -
Schema manager (
schema_managermodule): Top-level per-upstream view of an MCP server. Owns versioned snapshots built from ingested discovery responses, exposes query APIs (list_tools, get_tool, …), tracks stale flags, and defines theSchemaScannertrait for active discovery.
§Module Structure
mcpr-protocol/src/
+-- lib.rs # JSON-RPC 2.0 types, parsing, MCP method classification
+-- schema.rs # Pagination merge + diff primitives
+-- schema_manager/ # SchemaManager, SchemaStore, SchemaScanner, SchemaVersion
+-- session.rs # Session state, SessionStore trait, MemorySessionStore§Dependencies
Minimal: serde, serde_json, chrono, dashmap. No HTTP framework deps.
Modules§
- error_
code - schema
- MCP schema capture: types, pagination merging, and diff logic.
- schema_
manager - Schema manager: the top-level per-upstream view of an MCP server.
- session
Structs§
- Json
RpcError - Json
RpcNotification - Json
RpcRequest - Json
RpcResponse - Parsed
Body - Result of parsing a POST body as JSON-RPC 2.0.
Enums§
- Json
RpcId - A parsed JSON-RPC 2.0 id (number or string).
- Json
RpcMessage - A classified JSON-RPC 2.0 message.
- McpMethod
- Known MCP methods — lets the proxy know exactly what function is being called.
Constants§
- COMPLETION_
COMPLETE - INITIALIZE
- INITIALIZED
- LOGGING_
SET_ LEVEL - NOTIFICATIONS_
CANCELLED - NOTIFICATIONS_
PROGRESS - NOTIFICATIONS_
TOOLS_ LIST_ CHANGED - PING
- PROMPTS_
GET - PROMPTS_
LIST - RESOURCES_
LIST - RESOURCES_
READ - RESOURCES_
SUBSCRIBE - RESOURCES_
TEMPLATES_ LIST - RESOURCES_
UNSUBSCRIBE - TOOLS_
CALL - TOOLS_
LIST
Functions§
- error_
response - Build a JSON-RPC 2.0 error response as bytes.
idcan be a request id orValue::Nullif the request id couldn’t be parsed. - extract_
error_ code - Extract the JSON-RPC error code from a response body (if it’s an error response).
- parse_
body - Parse a POST body as JSON-RPC 2.0 — single message or batch.
Returns
Noneif the body is not valid JSON-RPC 2.0. - parse_
message - Parse a single JSON value as a JSON-RPC 2.0 message.
Returns
Noneif it doesn’t have"jsonrpc": "2.0".