feat(examples): add streamable HTTP section in configs (#296)

This commit is contained in:
Tyress K 2025-07-03 12:07:28 +09:00 • committed by GitHub
commit 31155a440c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 0 deletions

View file

@ -20,6 +20,7 @@ rmcp = { workspace = true, features = [
"reqwest", "reqwest",
"transport-child-process", "transport-child-process",
"transport-sse-client", "transport-sse-client",
"transport-streamable-http-client"
] } ] }
anyhow = "1.0" anyhow = "1.0"
serde_json = "1" serde_json = "1"

View file

@ -14,6 +14,9 @@ pub struct McpServerConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "protocol", rename_all = "lowercase")] #[serde(tag = "protocol", rename_all = "lowercase")]
pub enum McpServerTransportConfig { pub enum McpServerTransportConfig {
Streamable {
url: String,
},
Sse { Sse {
url: String, url: String,
}, },
@ -60,6 +63,11 @@ impl McpConfig {
impl McpServerTransportConfig { impl McpServerTransportConfig {
pub async fn start(&self) -> anyhow::Result<RunningService<RoleClient, ()>> { pub async fn start(&self) -> anyhow::Result<RunningService<RoleClient, ()>> {
let client = match self { let client = match self {
McpServerTransportConfig::Streamable { url } => {
let transport =
rmcp::transport::StreamableHttpClientTransport::from_uri(url.to_string());
().serve(transport).await?
}
McpServerTransportConfig::Sse { url } => { McpServerTransportConfig::Sse { url } => {
let transport = rmcp::transport::SseClientTransport::start(url.to_string()).await?; let transport = rmcp::transport::SseClientTransport::start(url.to_string()).await?;
().serve(transport).await? ().serve(transport).await?

View file

@ -18,6 +18,7 @@ rmcp = { workspace = true, features = [
"client", "client",
"transport-child-process", "transport-child-process",
"transport-sse-client", "transport-sse-client",
"transport-streamable-http-client",
"reqwest" "reqwest"
], no-default-features = true } ], no-default-features = true }
clap = { version = "4.0", features = ["derive"] } clap = { version = "4.0", features = ["derive"] }

View file

@ -29,6 +29,9 @@ pub struct McpServerConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "protocol", rename_all = "lowercase")] #[serde(tag = "protocol", rename_all = "lowercase")]
pub enum McpServerTransportConfig { pub enum McpServerTransportConfig {
Streamable {
url: String,
},
Sse { Sse {
url: String, url: String,
}, },
@ -44,6 +47,11 @@ pub enum McpServerTransportConfig {
impl McpServerTransportConfig { impl McpServerTransportConfig {
pub async fn start(&self) -> Result<RunningService<RoleClient, ()>> { pub async fn start(&self) -> Result<RunningService<RoleClient, ()>> {
let client = match self { let client = match self {
McpServerTransportConfig::Streamable { url } => {
let transport =
rmcp::transport::StreamableHttpClientTransport::from_uri(url.to_string());
().serve(transport).await?
}
McpServerTransportConfig::Sse { url } => { McpServerTransportConfig::Sse { url } => {
let transport = let transport =
rmcp::transport::sse_client::SseClientTransport::start(url.to_owned()).await?; rmcp::transport::sse_client::SseClientTransport::start(url.to_owned()).await?;