Skip to main content

fastmcp_protocol/
lib.rs

1//! MCP protocol types and JSON-RPC implementation.
2//!
3//! This crate provides:
4//! - JSON-RPC 2.0 message types
5//! - MCP-specific method types (tools, resources, prompts)
6//! - Protocol version negotiation
7//! - Message serialization/deserialization
8//!
9//! # MCP Protocol Overview
10//!
11//! MCP (Model Context Protocol) uses JSON-RPC 2.0 over various transports.
12//! The protocol defines:
13//!
14//! - **Tools**: Executable functions the client can invoke
15//! - **Resources**: Data sources the client can read
16//! - **Prompts**: Template prompts for the client to use
17//!
18//! # Wire Format
19//!
20//! All messages are newline-delimited JSON (NDJSON).
21//!
22//! # Role in the System
23//!
24//! `fastmcp-protocol` is the **shared vocabulary** for FastMCP:
25//! - The server uses these types to validate and serialize responses.
26//! - The client uses the same types to construct requests and parse replies.
27//! - Transports carry these messages without needing to know business logic.
28//!
29//! If you are integrating FastMCP with a custom runtime or embedding it into
30//! another system, depend on this crate to get the canonical JSON-RPC and MCP
31//! data models.
32
33#![forbid(unsafe_code)]
34#![allow(dead_code)]
35
36mod jsonrpc;
37mod messages;
38pub mod schema;
39mod types;
40
41pub use jsonrpc::{
42    JSONRPC_VERSION, JsonRpcError, JsonRpcMessage, JsonRpcRequest, JsonRpcResponse, RequestId,
43};
44pub use messages::*;
45pub use schema::{ValidationError, ValidationResult, validate, validate_strict};
46pub use types::*;