Development · MODEL CONTEXT PROTOCOL

neva

MCP server SDK for Rust

连接能力

neva 为 AI Agent 提供什么

来源目录未提供结构化功能列表,请在使用前阅读源仓库文档。

安全

MCP 收录不等于安全审核

MCP 服务器可能获得模型上下文、凭据、本地文件或调用外部系统的权限。连接 Agent 前,请检查代码、环境变量、网络行为、软件包来源与维护状态。

README

仓库文档

Neva

Blazingly fast and easily configurable Model Context Protocol (MCP) 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.

latest latest License: MIT CI Release

💡 Note: This project is currently in preview. Breaking changes can be introduced without prior notice.

Tutorial | API Docs | 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 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 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
[dependencies]
neva = { version = "0.8.0", features = ["client-full"] }
tokio = { version = "1", features = ["full"] }
Code
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
[dependencies]
neva = { version = "0.8.0", features = ["server-full"] }
tokio = { version = "1", features = ["full"] }
Code
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;
}
在 GitHub 查看 README

社区

收藏、评分与讨论

正在载入社区数据…