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
83 changes: 74 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version = "0.2.2"
edition = "2024"

[dependencies]
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk.git", rev = "4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451", features = [
rmcp = { version = "0.6.1", features = [
"server",
"client",
"reqwest",
"client-side-sse",
"transport-sse-client",
"transport-streamable-http-client",
"transport-sse-client-reqwest",
"transport-streamable-http-client-reqwest",
"transport-worker",
"transport-child-process"
] }
Expand All @@ -29,12 +29,12 @@ version = "0.9"
features = ["vendored"]

[dev-dependencies]
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk.git", rev = "4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451", features = [
rmcp = { version = "0.6.1", features = [
"server",
"client",
"reqwest",
"client-side-sse",
"transport-sse-client",
"transport-sse-client-reqwest",
"transport-sse-server",
"transport-child-process",
"transport-streamable-http-server",
Expand Down
32 changes: 22 additions & 10 deletions examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ use rmcp::transport::SseServer;
use tracing_subscriber::FmtSubscriber;

use rmcp::{
ServerHandler,
model::{ServerCapabilities, ServerInfo},
schemars, tool,
ErrorData as McpError,
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
model::*,
tool, tool_handler, tool_router,
};

#[derive(Debug, Clone, Default)]
pub struct Echo;
#[tool(tool_box)]
pub struct Echo {
tool_router: ToolRouter<Echo>,
}
#[tool_router]
impl Echo {
fn new() -> Self {
Self {
tool_router: Self::tool_router(),
}
}

#[tool(description = "Echo a message")]
fn echo(&self, #[tool(param)] message: String) -> String {
message
fn echo(&self, Parameters(object): Parameters<JsonObject>) -> Result<CallToolResult, McpError> {
Ok(CallToolResult::success(vec![Content::text(
serde_json::Value::Object(object).to_string(),
)]))
}
}

#[tool(tool_box)]
impl ServerHandler for Echo {
#[tool_handler]
impl rmcp::ServerHandler for Echo {
fn get_info(&self) -> ServerInfo {
ServerInfo {
instructions: Some("A simple echo server".into()),
Expand Down Expand Up @@ -51,7 +63,7 @@ async fn main() -> anyhow::Result<()> {

let ct = SseServer::serve(args.address)
.await?
.with_service(Echo::default);
.with_service_directly(Echo::new);

tokio::signal::ctrl_c().await?;
ct.cancel();
Expand Down
30 changes: 19 additions & 11 deletions examples/echo_streamable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@ use rmcp::transport::streamable_http_server::{
use tracing_subscriber::FmtSubscriber;

use rmcp::{
ServerHandler,
model::{ServerCapabilities, ServerInfo},
schemars, tool,
ErrorData as McpError,
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
model::*,
tool, tool_handler, tool_router,
};

#[derive(Debug, Clone, Default)]
pub struct Echo;
#[tool(tool_box)]
pub struct Echo {
tool_router: ToolRouter<Echo>,
}
#[tool_router]
impl Echo {
pub fn new() -> Self {
Self {}
fn new() -> Self {
Self {
tool_router: Self::tool_router(),
}
}

#[tool(description = "Echo a message")]
fn echo(&self, #[tool(param)] message: String) -> String {
message
fn echo(&self, Parameters(object): Parameters<JsonObject>) -> Result<CallToolResult, McpError> {
Ok(CallToolResult::success(vec![Content::text(
serde_json::Value::Object(object).to_string(),
)]))
}
}

#[tool(tool_box)]
impl ServerHandler for Echo {
#[tool_handler]
impl rmcp::ServerHandler for Echo {
fn get_info(&self) -> ServerInfo {
ServerInfo {
instructions: Some("A simple echo server".into()),
Expand Down
1 change: 1 addition & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) async fn connect_with_streamable(app_state: &AppState) -> Result<SseC
uri: app_state.url.clone().into(),
// we don't want the sdk to perform any retries
retry_config: std::sync::Arc::new(rmcp::transport::common::client_side_sse::NeverRetry),
auth_header: None,
channel_buffer_capacity: 16,
allow_stateless: true,
},
Expand Down
3 changes: 2 additions & 1 deletion tests/basic_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod echo;
use echo::Echo;
use rmcp::{
ServiceExt,
transport::{ConfigureCommandExt, SseServer, TokioChildProcess},
Expand All @@ -11,7 +12,7 @@ const TEST_SERVER_URL: &str = "http://localhost:8099/sse";
async fn test_proxy_connects_to_real_server() -> anyhow::Result<()> {
let ct = SseServer::serve(BIND_ADDRESS.parse()?)
.await?
.with_service(echo::Echo::default);
.with_service_directly(Echo::new);

let transport = TokioChildProcess::new(
tokio::process::Command::new("./target/debug/mcp-proxy").configure(|cmd| {
Expand Down
31 changes: 22 additions & 9 deletions tests/echo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
use rmcp::{
ServerHandler,
model::{ServerCapabilities, ServerInfo},
schemars, tool,
ErrorData as McpError,
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
model::*,
tool, tool_handler, tool_router,
};

#[derive(Debug, Clone, Default)]
pub struct Echo;
#[tool(tool_box)]
pub struct Echo {
tool_router: ToolRouter<Echo>,
}
#[tool_router]
impl Echo {
#[allow(dead_code)]
pub fn new() -> Self {
Self {
tool_router: Self::tool_router(),
}
}

#[tool(description = "Echo a message")]
fn echo(&self, #[tool(param)] message: String) -> String {
message
fn echo(&self, Parameters(object): Parameters<JsonObject>) -> Result<CallToolResult, McpError> {
Ok(CallToolResult::success(vec![Content::text(
serde_json::Value::Object(object).to_string(),
)]))
}
}

#[tool(tool_box)]
impl ServerHandler for Echo {
#[tool_handler]
impl rmcp::ServerHandler for Echo {
fn get_info(&self) -> ServerInfo {
ServerInfo {
instructions: Some("A simple echo server".into()),
Expand Down