尼瓦河
速度极快,易于配置 模型上下文协议(MCP) Rust的服务器和客户端SDK。 通过简单的配置和符合人体工程学的API,它提供了快速构建MCP客户端和服务器所需的一切, 完全符合最新的MCP规范。
    
💡 备注:此项目当前处于预览阶段。如有重大变更,恕不另行通知。
主要特点
- 客户端和服务器SDK -一个库,用于构建具有Rust功能的MCP客户端和服务器。
- 演出 -异步和东京供电。
- 运输 - 标准 用于本地集成和 可流式传输的HTTP 用于远程双向通信。
- 工具, 资源 & 提示 -为定义和使用主要MCP实体提供全方位支持。
- 身份验证和授权 -承载令牌身份验证、基于角色的访问控制等,以适应高安全标准。
- 结构化数据 -输出验证、嵌入式资源和开箱即用的资源链接。
- 规格对齐 -旨在跟踪最新的MCP规范并涵盖其核心功能。
快速开始
MCP客户端
依赖项
[dependencies]
neva = { version = "0.3.2", features = ["client-full"] }
tokio = { version = "1", features = ["full"] }代码
use neva::prelude::*;
#[tokio::main]
async fn main() -> Result {
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
let tools = client.list_tools(None).await?;
for tool in tools.tools {
println!("- {}", tool.name);
}
// Call a tool
let args = [
("message", "Hello MCP!")
];
let result = client.call_tool("echo", args).await?;
println!("{:?}", result.content);
client.disconnect().await
}MCP服务器
依赖项
[dependencies]
neva = { version = "0.3.2", features = ["server-full"] }
tokio = { version = "1", features = ["full"] }代码
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}"))
}
#[prompt(descr = "Analyze code for potential improvements")]
async 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;
}