Skip to main content

Crate neva

Crate neva 

Source
Expand description

§Neva

Easy configurable MCP server and client SDK for Rust

§Dependencies

[dependencies]
neva = { version = "0.2.1", features = ["full"] }
tokio = { version = "1", features = ["full"] }

§Example Server

use neva::App;
 
#[tokio::main]
async fn main() {
    let mut app = App::new()
        .with_options(|opt| opt
            .with_stdio());
 
    app.map_tool("hello", |name: String| async move { 
        format!("Hello, {name}!")
    });
 
    app.run().await;
} 

§Example Client

use std::time::Duration;
use neva::{Client, error::Error};
 
#[tokio::main]
async fn main() -> Result<(), Error> {
    let mut client = Client::new()
        .with_options(|opt| opt
            .with_stdio("npx", ["-y", "@modelcontextprotocol/server-everything"]));
 
    client.connect().await?;
 
    // Call a tool
    let args = [("message", "Hello MCP!")];
    let result = client.call_tool("echo", Some(args)).await?;
    println!("{:?}", result.content);
 
    client.disconnect().await
}

Re-exports§

pub use app::App;
pub use app::context::Context;
pub use client::Client;

Modules§

app
Represents an MCP application
auth
Authentication utilities
client
Utilities for the MCP client
commands
List of built-in commands supported by the MCP protocol
di
Types and utilities for dependency injection
error
Represents an error
json
JSON utilities
macros
Utilities for macros
middleware
MCP Server middleware utilities
prelude
Prelude with commonly used items
shared
Shared utilities for server and client
transport
Transport protocols and utilities for communicating between server and client
types
Types used by the MCP protocol

Macros§

spawn_fair
Cooperatively yields to the Tokio scheduler before spawning a new task, ensuring fair task scheduling especially under high load or on platforms like Windows where newly spawned tasks may not execute promptly.

Attribute Macros§

completion
Maps the completion function
elicitation
Maps the elicitation handler function
handler
Maps the function to a command handler
json_schema
Provides a utility to extract a JSON schema of this type
prompt
Maps the function to a prompt
resource
Maps the function to a resource template
resources
Maps the list of resources function
sampling
Maps the sampling handler function
tool
Maps the function to a tool