mcpField
K
kuri (栗 or くり)

kuri (栗 or くり)

本地服务
github.com/itsaphel开发工具1376 周前更新

关于 kuri (栗 or くり)

kuri 是用于构建 MCP 服务的 Rust 框架。它以普通异步 Rust 函数定义工具和提示词,并减少宏与协议路由样板代码。

主要功能

  1. 01用异步 Rust 函数定义工具和提示词
  2. 02减少宏的使用
  3. 03减少序列化与路由样板代码
  4. 04支持 Tower 中间件与层
  5. 05支持标准输入/输出传输

适用场景

  1. 01用 Rust 构建 MCP 工具
  2. 02为 Rust MCP 服务添加提示词
  3. 03为服务应用 Tower 中间件

MCP 相关

kuri 是用于实现 MCP 服务的框架,支持生命周期处理、工具、提示词和标准输入/输出传输;资源与 HTTP 传输尚未列为已支持功能。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

kuri(栗 or くり)

kuri 是一个用于构建 Model Context Protocol(MCP)服务的框架,专注于提升开发者体验和清晰度。

Build status Crates.io Documentation

MCP 允许大模型执行预定义的函数(称为“工具”),从而获取数据并产生副作用(即与外部世界交互)。大模型只需提供函数的输入参数,函数随即执行,并将响应返回给模型。这些工具由“MCP 服务”提供,可以在本地运行,单个服务也可以提供多个工具。

设计理念

Rust 凭借强大的类型系统和正确性保证,是编写可靠 MCP 服务的出色语言。kuri 旨在让使用 Rust 编写 MCP 服务的过程格外愉悦,促进开发者用 Rust 构建 MCP 服务。我们的设计目标如下:

  • 开发者体验自然顺畅: 编写 MCP 服务应当像编写常规 Rust 程序一样。工具和提示词就是普通的异步 Rust 函数。
  • 尽量少用宏(#[tool]、#[prompt]):宏仅用于附加工具和参数说明,不用于复杂的代码生成。
  • 尽量减少样板代码: 专注于应用逻辑,而非序列化或 MCP 协议路由。
  • 充分利用 tower 中间件、服务和实用工具生态。免费获得超时、跟踪、panic 处理等功能,并复用 axum、tonic 和 hyper 的组件。

以上只是让我们有别于其他 MCP 服务 crate 的部分特点。我们专注于做好一件事,并做到极致。这里没有复杂又神秘的宏,应用代码仍然一目了然,kuri 的内部实现也清晰易读。kuri 还基于 tower 构建,让你能够复用丰富的中间件和层生态。

示例

use kuri::{MCPServiceBuilder, ServiceExt, ToolError, prompt, serve, tool, transport::StdioTransport};
use schemars::JsonSchema;
use serde::Deserialize;

#[derive(Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum Operation {
    Add,
    Subtract,
    Multiply,
    Divide,
}

// A pure function that takes three inputs and returns an integer. Descriptions
// for the tool and its parameters help the model decide which tool to use, and
// correctly supply the tool's parameters.
#[tool(
    description = "Perform basic arithmetic operations",
    params(
        x = "First number in the calculation",
        y = "Second number in the calculation",
        operation = "The operation to perform (add, subtract, multiply, divide)"
    )
)]
async fn calculator(x: i32, y: i32, operation: Operation) -> Result<i32, ToolError> {
    match operation {
        Operation::Add => Ok(x + y),
        Operation::Subtract => Ok(x - y),
        Operation::Multiply => Ok(x * y),
        Operation::Divide => {
            if y == 0 {
                Err(ToolError::ExecutionError("Division by zero".to_string()))
            } else {
                Ok(x / y)
            }
        }
    }
}

// Creates a prompt template for text summarisation. The application provides
// the text to summarise, and an optional format parameter (denoted using Rust's
// `Option` type). kuri tells the model that `format` may be omitted.
#[prompt(
    description = "Generates a prompt for summarising text",
    params(
        text = "The text to summarise",
        format = "Optional format for the summary (eg: 'bullet points' or 'Shakespeare')"
    )
)]
async fn summarise_text(text: String, format: Option<String>) -> String {
    let format_instruction = match format {
        Some(f) => format!(" in the format of {}", f),
        None => String::new(),
    };

    format!(
        "Please summarize the following text{}:\n\n{}",
        format_instruction, text
    )
}

#[tokio::main]
async fn main() -> Result<(), TransportError> {
    // Create the MCP service with the server's name
    let service = MCPServiceBuilder::new("kuri's test server".to_string())
        // Register the tool and prompt
        .with_tool(Calculator)
        .with_prompt(SummariseText)
        .build();

    // Serve over the stdio transport
    serve(service.into_request_service(), StdioTransport::new()).await
}

更多内容请参阅示例

开始使用时,在 Cargo.toml 中添加 kuri 和一些必要的依赖:

[dependencies]
kuri = "0.1"
async-trait = "0.1"
schemars = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }

MCP 规范支持

  • 核心生命周期:连接初始化、能力协商和会话控制
  • 工具:功能完整,并配有测试
  • 提示词:基本完整,并配有测试
  • 资源
  • 传输方式
  • 额外(可选)功能

我们目前优先添加 HTTP 传输支持、稳定 API,并确保全面支持核心规范。

参与贡献

本项目旨在构建一个易用、自然、符合惯用方式的 Rust 库,用于构建 MCP 服务。目前项目仍处于早期阶段,因此结构仍可能发生变化。如果你喜欢 Rust、MCP、构建 crate 或网络协议(也许你对 protohackers 感兴趣!),我们非常欢迎你加入!欢迎参与仓库开发,或者发送邮件联系交流!

如果你在自己的项目中使用了这个框架:感谢尝试!我很乐意听听你的使用体验!

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。