chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:31:35 +08:00
commit c275ba2868
13613 changed files with 2980806 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
[package]
name = "calculator-httpserver"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = { version = "0.8.4", features = ["macros"] }
rmcp = { version = "1.4.0", features = ["server","transport-streamable-http-server", "transport-worker"] }
serde = "1.0.219"
serde_json = "1.0.140"
tokio = { version = "1.46.0", features = ["macros", "rt-multi-thread", "signal"] }
[dev-dependencies]
slab = "0.4.11"
@@ -0,0 +1,13 @@
# Running this sample
## -1- Install the dependencies and build the project
```bash
cargo build
```
## -2- Run the sample
```bash
cargo run
```
@@ -0,0 +1,70 @@
use rmcp::{
ServerHandler,
handler::server::{router::tool::ToolRouter, tool::Parameters},
model::*,
schemars, tool, tool_handler, tool_router,
transport::streamable_http_server::{
StreamableHttpService, session::local::LocalSessionManager,
},
};
use std::error::Error;
const BIND_ADDRESS: &str = "127.0.0.1:8000";
#[derive(Debug, Clone)]
pub struct Calculator {
tool_router: ToolRouter<Self>,
}
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
pub struct CalculatorRequest {
pub a: f64,
pub b: f64,
}
#[tool_router]
impl Calculator {
pub fn new() -> Self {
Self {
tool_router: Self::tool_router(),
}
}
#[tool(description = "Adds a and b")]
async fn add(
&self,
Parameters(CalculatorRequest { a, b }): Parameters<CalculatorRequest>,
) -> String {
(a + b).to_string()
}
}
#[tool_handler]
impl ServerHandler for Calculator {
fn get_info(&self) -> ServerInfo {
ServerInfo {
instructions: Some("A simple calculator tool".into()),
capabilities: ServerCapabilities::builder().enable_tools().build(),
..Default::default()
}
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let service = StreamableHttpService::new(
|| Ok(Calculator::new()),
LocalSessionManager::default().into(),
Default::default(),
);
let router = axum::Router::new().nest_service("/mcp", service);
let tcp_listener = tokio::net::TcpListener::bind(BIND_ADDRESS).await?;
println!("Streamable HTTP server is running on {}", BIND_ADDRESS);
let _ = axum::serve(tcp_listener, router)
.with_graceful_shutdown(async { tokio::signal::ctrl_c().await.unwrap() })
.await;
Ok(())
}