jsoncall
A simple asynchronous JSON-RPC 2.0 library leveraging Rust's type system
Overview
jsoncall
is a simple asynchronous JSON-RPC 2.0 library that maximizes the use of Rust's type system.
It is specifically designed to facilitate the creation of applications where the client launches the server, such as the Language Server Protocol and Model Context Protocol.
Features
- Asynchronous support using
tokio
andasync/await
- Strongly typed requests and responses using
serde
- Easy implementation of JSON Schema-defined RPCs by generating Rust types using
typify
- Easy implementation of JSON Schema-defined RPCs by generating Rust types using
- Built-in support for cancellation handling
- Enables implementation of cancellation for Language Server Protocol and Model Context Protocol
- Comprehensive error handling
- Provides error types that can store any error like
anyhow
orBox<dyn Error>
, with additional functionality to distinguish between information that should be sent externally and information that should not
- Provides error types that can store any error like
- Bidirectional communication support
- Notification support
- Transport layer supports any type implementing
tokio
'sAsyncBufRead
andAsyncWrite
traits- Standard I/O transport is readily available through
Session::from_stdio
andSession::from_command
- Standard I/O transport is readily available through
- Small, understandable API set
Installation
Add the following to your Cargo.toml:
[]
= "0.0.3"
Usage
Server Implementation Example
use ;
use ;
;
async
Client Usage Example
use ;
use Command;
use ;
async
Asynchronous Handler Example
use ;
;
License
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.