Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/rust-mcp-sdk/src/hyper_servers/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use crate::{
utils::{
DEFAULT_MESSAGES_ENDPOINT, DEFAULT_SSE_ENDPOINT, DEFAULT_STREAMABLE_HTTP_ENDPOINT,
},
InMemorySessionStore, McpAppState,
McpAppState,
},
mcp_server::hyper_runtime::HyperRuntime,
mcp_traits::{mcp_handler::McpServerHandler, IdGenerator},
session_store::InMemorySessionStore,
};
#[cfg(feature = "ssl")]
use axum_server::tls_rustls::RustlsConfig;
Expand Down
7 changes: 6 additions & 1 deletion crates/rust-mcp-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub(crate) mod mcp_http;
mod mcp_macros;
mod mcp_runtimes;
mod mcp_traits;
#[cfg(any(feature = "server", feature = "hyper-server"))]
pub mod session_store;
mod utils;

#[cfg(feature = "client")]
Expand Down Expand Up @@ -65,7 +67,7 @@ pub mod mcp_server {
//! handle each message based on its type and parameters.
//!
//! Refer to [examples/hello-world-mcp-server-stdio-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio-core) for an example.
pub use super::mcp_handlers::mcp_server_handler::ServerHandler;
pub use super::mcp_handlers::mcp_server_handler::{ServerHandler, ToMcpServerHandler};
pub use super::mcp_handlers::mcp_server_handler_core::ServerHandlerCore;

pub use super::mcp_runtimes::server_runtime::mcp_server_runtime as server_runtime;
Expand All @@ -79,6 +81,9 @@ pub mod mcp_server {
#[cfg(feature = "hyper-server")]
pub use super::hyper_servers::*;
pub use super::utils::enforce_compatible_protocol_version;

#[cfg(feature = "hyper-server")]
pub use super::mcp_http::{McpAppState, McpHttpHandler};
}

#[cfg(feature = "client")]
Expand Down
17 changes: 16 additions & 1 deletion crates/rust-mcp-sdk/src/mcp_handlers/mcp_server_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::schema::{schema_utils::CallToolError, *};
use crate::{
mcp_server::server_runtime::ServerRuntimeInternalHandler,
mcp_traits::mcp_handler::McpServerHandler,
schema::{schema_utils::CallToolError, *},
};
use async_trait::async_trait;
use serde_json::Value;
use std::sync::Arc;
Expand Down Expand Up @@ -326,3 +330,14 @@ pub trait ServerHandler: Send + Sync + 'static {
Ok(())
}
}

// Custom trait for conversion
pub trait ToMcpServerHandler {
fn to_mcp_server_handler(self) -> Arc<dyn McpServerHandler + 'static>;
}

impl<T: ServerHandler + 'static> ToMcpServerHandler for T {
fn to_mcp_server_handler(self) -> Arc<dyn McpServerHandler + 'static> {
Arc::new(ServerRuntimeInternalHandler::new(Box::new(self)))
}
}
4 changes: 1 addition & 3 deletions crates/rust-mcp-sdk/src/mcp_http.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod app_state;
mod mcp_http_handler;
pub(crate) mod mcp_http_utils;
mod session_store;

pub(crate) use app_state::*;
pub use app_state::*;
pub use mcp_http_handler::*;
pub use session_store::*;

pub(crate) mod utils {
pub use super::mcp_http_utils::*;
Expand Down
7 changes: 2 additions & 5 deletions crates/rust-mcp-sdk/src/mcp_http/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::{sync::Arc, time::Duration};

use super::session_store::SessionStore;
use crate::mcp_traits::mcp_handler::McpServerHandler;
use crate::session_store::SessionStore;
use crate::{id_generator::FastIdGenerator, mcp_traits::IdGenerator, schema::InitializeResult};

use rust_mcp_transport::event_store::EventStore;

use rust_mcp_transport::{SessionId, TransportOptions};
use std::{sync::Arc, time::Duration};

/// Application state struct for the Hyper ser
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod in_memory;
mod in_memory_session_store;
use std::sync::Arc;

use async_trait::async_trait;
pub use in_memory::*;
pub use in_memory_session_store::*;
use rust_mcp_transport::SessionId;
use tokio::sync::Mutex;

use crate::mcp_server::ServerRuntime;

// Type alias for the server-side duplex stream used in sessions
pub type TxServer = Arc<ServerRuntime>;
type TxServer = Arc<ServerRuntime>;

/// Trait defining the interface for session storage operations
///
Expand Down