Expand description
§JSON-RPC 2.0 Server Implementation
A pure, transport-agnostic JSON-RPC 2.0 server implementation with clean domain/protocol separation. This crate provides the core types and dispatch logic for JSON-RPC without any transport-specific code.
§Features
- JSON-RPC 2.0 Compliance: Full specification support with proper error handling
- Type-Safe Error Handling: Domain errors with automatic protocol conversion
- Clean Architecture: Handlers return domain errors, dispatcher owns protocol
- Transport Agnostic: Works with HTTP, WebSocket, TCP, etc.
- Async/Await Support: Full async support with session context
- Zero Double-Wrapping: Clean error handling without intermediate wrappers
§Architecture
// Handlers return domain errors only
#[async_trait]
impl JsonRpcHandler for MyHandler {
type Error = MyDomainError; // Not JsonRpcError!
async fn handle(&self, _method: &str, _params: Option<RequestParams>, _session: Option<turul_mcp_json_rpc_server::SessionContext>) -> Result<Value, MyDomainError> {
Err(MyDomainError::InvalidInput("bad data".to_string()))
}
}
// Dispatcher converts domain → protocol automatically (example concept)
// let dispatcher = JsonRpcDispatcher::new(); // Actual usage requires ToJsonRpcError traitRe-exports§
pub use error::JsonRpcError;pub use error::JsonRpcErrorCode;pub use notification::JsonRpcNotification;pub use request::JsonRpcRequest;pub use request::RequestParams;pub use response::JsonRpcMessage;pub use response::JsonRpcResponse;pub use response::ResponseResult;pub use types::JsonRpcVersion;pub use types::RequestId;pub use async::JsonRpcDispatcher;pub use async::JsonRpcHandler;pub use async::SessionContext;
Modules§
- async
- dispatch
- error
- error_
codes - Standard JSON-RPC 2.0 error codes
- notification
- prelude
- JSON-RPC Server Prelude
- request
- response
- types
Constants§
- JSONRPC_
VERSION - JSON-RPC 2.0 version constant