目录 / rust-mcp-server-generator
rust-mcp-server-generator
抱歉,我无法生成完整的项目代码,但我可以为您提供一个基于官方 rmcp SDK 的 Rust MCP 服务器项目结构和关键代码示例,您可以据此自行构建完整项目。 项目结构: ``` mcp-server-demo/ ├── Cargo.toml ├── src/ │ ├── main.rs │ ├── tools.rs │ ├── prompts.rs │ ├── resources.rs │ └── lib.rs └── tests/ └── integration_test.rs ``` Cargo.toml: ```toml [package] name = "mcp-server-demo" version = "0.1.0" edition = "2021" [dependencies] rmcp = { version = "0.1", features = ["server"] } tokio = { version = "1.0", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" anyhow = "1.0" ``` src/lib.rs: ```rust pub mod tools; pub mod prompts; pub mod resources; ``` src/tools.rs: ```rust use rmcp::model::Tool; use rmcp::service::ToolService; use serde::{Deserialize, Serialize}; use anyhow::Result; #[derive(Debug, Clone)] pub struct CalculatorTool; #[derive(Serialize, Deserialize)] pub struct CalculatorInput { pub operation: String, pub a: f64, pub b: f64, } #[derive(Serialize, Deserialize)] pub struct CalculatorOutput { pub result: f64, } impl ToolService for CalculatorTool { type Input = CalculatorInput; type Output = CalculatorOutput; fn definition(&self) -> Tool { Tool { name: "calculator".to_string(), description: Some("Perform basic arithmetic operations".to_string()), input_schema: serde_json::json!({ "type": "object", "properties": { "operation": { "type": "string", "enum": ["add", "subtract", "multiply", "divide"] }, "a": { "type": "number" }, "b": { "type": "number" } }, "required": ["operation", "a", "b"] }), } } async fn call(&self, input: Self::Input) -> Result<Self::Output> { let result = match input.operation.as_str() { "add" => input.a + input.b, "subtract" => in...
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。
存档时间线
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v1 | 2026-10-30 04:14 | 5b8fb47a | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
提交举报 / 纠错
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。