内容
# Neva
Blazingly fast and easily configurable [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server and client SDK for Rust.
With simple configuration and ergonomic APIs, it provides everything you need to quickly build MCP clients and servers,
fully aligned with the latest MCP specification.
[](https://crates.io/crates/neva)
[](https://releases.rs/docs/1.90.0/)
[](https://github.com/RomanEmreis/neva/blob/main/LICENSE)
[](https://github.com/RomanEmreis/neva/actions/workflows/rust.yml)
[](https://github.com/RomanEmreis/neva/actions/workflows/release.yml)
> 💡 **Note**: This project is currently in preview. Breaking changes can be introduced without prior notice.
[Tutorial](https://romanemreis.github.io/neva-docs/) | [API Docs](https://docs.rs/neva/latest/neva/) | [Examples](https://github.com/RomanEmreis/neva/tree/main/examples)
## Key Features
- **Client & Server SDK** - one library to build both MCP clients and servers with the powers of Rust.
- **Performance** - asynchronous and Tokio-powered.
- **Transports** - **stdio** for local integrations and **Streamable HTTP** for remote, bidirectional communication.
- **Tools**, **Resources** & **Prompts** - full-house support for defining and consuming the main MCP entities.
- **Async or sync handlers** - write `async fn` when you await something, a plain `fn` when you don't. Add `blocking` when the body blocks, and it runs on Tokio's blocking pool instead of a runtime worker.
- **Authentication & Authorization** - bearer token authentication, role-based access control, and more to fit high security standards.
- **Structured Data** - output validation, embedded resources, and resource links out of the box.
- **Safe Multi Round-Trip Requests** - a handler that asks the client for input mid-call re-runs from the top on every round, so neva owns the idempotency: `ctx.memo` computes once, `ctx.once` runs an effect once, `ctx.on_commit` defers it to the final result, and a lost response replays the committed answer instead of charging the card twice.
- **Confidential request state** - the `requestState` blob that carries progress between rounds is sealed with ChaCha20-Poly1305, not merely signed, so what `ctx.memo` caches stays unreadable to the client that echoes it back.
- **Handing tools to a model** - with the `svir` feature, an MCP server's tools become a [svir](https://docs.rs/svir) `Toolbox`: a remote server's through `RemoteTools`, or a function written once with `#[tool]` called in the same process through the server's own pipeline. Prompts and resources become svir messages, and a server's sampling request is answered with a model.
- **Registry publishing** - `server.json` for the [MCP Registry](https://registry.modelcontextprotocol.io) is generated from what the server already knows: its version, its transport and the crate Cargo is building. The registry's limits are checked before the upload rather than by it.
- **Spec Alignment** - designed to track the latest MCP specification and cover its core functionality.
## Quick Start
### MCP Client
#### Dependencies
```toml
[dependencies]
neva = { version = "0.8.2", features = ["client-full"] }
tokio = { version = "1", features = ["full"] }
```
#### Code
```rust
use neva::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut client = Client::new()
.with_options(|opt| opt
.with_stdio("npx", ["-y", "@modelcontextprotocol/server-everything"])
.with_timeout(Duration::from_secs(5)));
client.connect().await?;
// List tools
for tool in client.tools().list_all().await? {
println!("- {}", tool.name);
}
// Call a tool
let args = [
("message", "Hello MCP!")
];
let result = client.tools().call("echo", args).await?;
println!("{:?}", result.content);
client.disconnect().await
}
```
### MCP Server
#### Dependencies
```toml
[dependencies]
neva = { version = "0.8.2", features = ["server-full"] }
tokio = { version = "1", features = ["full"] }
```
#### Code
```rust
use neva::prelude::*;
#[tool(descr = "A say hello tool")]
async fn hello(name: String) -> String {
format!("Hello, {name}!")
}
#[resource(uri = "res://{name}", descr = "Some details about resource")]
async fn get_res(name: String) -> ResourceContents {
ResourceContents::new(format!("res://{name}"))
.with_mime("plain/text")
.with_text(format!("Some details about resource: {name}"))
}
// Nothing to await here, so a plain `fn` will do.
#[prompt(descr = "Analyze code for potential improvements")]
fn analyze_code(lang: String) -> PromptMessage {
PromptMessage::user()
.with(format!("Language: {lang}"))
}
#[tokio::main]
async fn main() {
App::new()
.with_options(|opt| opt
.with_stdio()
.with_name("Sample MCP server")
.with_version("1.0.0"))
.run()
.await;
}
```