Skip to content

Commit 2cd407b

Browse files
committed
update deps, breaking: streamable-http now started at /mcp route
Signed-off-by: Tuan Anh Tran <[email protected]>
1 parent a02f0ec commit 2cd407b

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

Cargo.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ log = "=0.4.27"
3131
sigstore = { version = "=0.12.1", features = ["cosign", "verify", "bundle"] }
3232
tracing = "=0.1.41"
3333
tracing-subscriber = { version = "=0.3.19", features = ["env-filter"] }
34-
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", rev = "22134eb33e249a3b3ae6c0153b0176e4dd532220", features = ["server", "transport-io", "transport-sse-server", "transport-streamable-http-server"] }
34+
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", rev = "a66f66ae345a0fafde1e2ee496ec137d77aef82a", features = ["server", "transport-io", "transport-sse-server", "transport-streamable-http-server"] }
3535
serde_yaml = "=0.9.34"
3636
toml = "=0.8.22"
3737
bytesize = "=2.0.1"
38+
axum = "=0.8.4"
3839

3940
[[bin]]
4041
name = "hyper-mcp"

src/main.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use anyhow::Result;
22
use clap::Parser;
33
use rmcp::transport::sse_server::SseServer;
4-
use rmcp::transport::streamable_http_server::axum::StreamableHttpServer;
4+
use rmcp::transport::streamable_http_server::{
5+
StreamableHttpService, session::local::LocalSessionManager,
6+
};
57
use rmcp::{ServiceExt, transport::stdio};
68
use std::path::PathBuf;
79
use tracing_subscriber::{self, EnvFilter};
@@ -10,9 +12,6 @@ mod config;
1012
mod oci;
1113
mod plugins;
1214

13-
pub const JSONRPC_VERSION: &str = "2.0";
14-
pub const SERVER_NAME: &str = "hyper-mcp";
15-
pub const SERVER_VERSION: &str = "0.1.0";
1615
pub const DEFAULT_BIND_ADDRESS: &str = "127.0.0.1:3001";
1716

1817
#[derive(Parser, Clone)]
@@ -138,7 +137,10 @@ async fn main() -> Result<()> {
138137
service.waiting().await?;
139138
}
140139
"sse" => {
141-
tracing::info!("Starting SSE server at {}", cli.bind_address);
140+
tracing::info!(
141+
"Starting hyper-mcp with SSE transport at {}",
142+
cli.bind_address
143+
);
142144
let ct = SseServer::serve(cli.bind_address.parse()?)
143145
.await?
144146
.with_service(move || plugin_service.clone());
@@ -147,13 +149,29 @@ async fn main() -> Result<()> {
147149
ct.cancel();
148150
}
149151
"streamable-http" => {
150-
tracing::info!("Starting Streamable HTTP server at {}", cli.bind_address);
151-
let ct = StreamableHttpServer::serve(cli.bind_address.parse()?)
152-
.await?
153-
.with_service(move || plugin_service.clone());
154-
155-
tokio::signal::ctrl_c().await?;
156-
ct.cancel();
152+
tracing::info!(
153+
"Starting hyper-mcp with streamable-http transport at {}",
154+
cli.bind_address
155+
);
156+
157+
let service = StreamableHttpService::new(
158+
move || plugin_service.clone(),
159+
LocalSessionManager::default().into(),
160+
Default::default(),
161+
);
162+
163+
let router = axum::Router::new().nest_service("/mcp", service);
164+
165+
let tcp_listener = tokio::net::TcpListener::bind(cli.bind_address).await?;
166+
let _ = axum::serve(tcp_listener, router)
167+
.with_graceful_shutdown(async {
168+
tokio::signal::ctrl_c().await.unwrap();
169+
tracing::info!("Received Ctrl+C, shutting down hyper-mcp server...");
170+
// Give the log a moment to flush
171+
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
172+
std::process::exit(0);
173+
})
174+
.await;
157175
}
158176
_ => unreachable!(),
159177
}

src/plugins.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::oci::OciDownloader;
44
use anyhow::Result;
55
use bytesize::ByteSize;
66
use extism::{Manifest, Plugin, Wasm};
7-
use rmcp::service::{RequestContext, RoleServer};
7+
use rmcp::service::{NotificationContext, RequestContext, RoleServer};
88
use rmcp::{Error as McpError, ServerHandler, model::*};
99
use std::str::FromStr;
1010

@@ -278,21 +278,26 @@ impl ServerHandler for PluginService {
278278
std::future::ready(Ok(()))
279279
}
280280

281-
fn on_initialized(&self) -> impl Future<Output = ()> + Send + '_ {
281+
fn on_initialized(
282+
&self,
283+
_context: NotificationContext<RoleServer>,
284+
) -> impl Future<Output = ()> + Send + '_ {
282285
tracing::info!("got initialized notification");
283286
std::future::ready(())
284287
}
285288

286289
fn on_cancelled(
287290
&self,
288291
_notification: CancelledNotificationParam,
292+
_context: NotificationContext<RoleServer>,
289293
) -> impl Future<Output = ()> + Send + '_ {
290294
std::future::ready(())
291295
}
292296

293297
fn on_progress(
294298
&self,
295299
_notification: ProgressNotificationParam,
300+
_context: NotificationContext<RoleServer>,
296301
) -> impl Future<Output = ()> + Send + '_ {
297302
std::future::ready(())
298303
}

0 commit comments

Comments
 (0)