1#[cfg(test)]
11#[path = "transport_tests.rs"]
12mod tests;
13
14use rmcp::transport::streamable_http_server::{
15 session::local::LocalSessionManager, StreamableHttpServerConfig, StreamableHttpService,
16};
17use soma_mcp_server::http::{self, AllowedHostsInput, AllowedOriginsInput};
18
19use soma_config::McpConfig;
20
21use super::rmcp_server::{rmcp_server as make_server, SomaRmcpServer};
22
23pub fn streamable_http_config(config: &McpConfig) -> StreamableHttpServerConfig {
26 http::streamable_http_config(allowed_hosts(config), allowed_origins(config))
27}
28
29pub fn streamable_http_service(
30 state: crate::McpState,
31 config: StreamableHttpServerConfig,
32) -> StreamableHttpService<SomaRmcpServer, LocalSessionManager> {
33 http::streamable_http_service(move || Ok(make_server(state.clone())), config)
34}
35
36pub fn allowed_hosts(config: &McpConfig) -> Vec<String> {
39 http::allowed_hosts(AllowedHostsInput {
40 bind_host: &config.host,
41 port: config.port,
42 extra_hosts: &config.allowed_hosts,
43 public_url: config.auth.public_url.as_deref(),
44 public_url_label: "SOMA_MCP_PUBLIC_URL",
45 })
46}
47
48pub fn allowed_origins(config: &McpConfig) -> Vec<String> {
49 http::allowed_origins(AllowedOriginsInput {
50 port: config.port,
51 extra_origins: &config.allowed_origins,
52 public_url: config.auth.public_url.as_deref(),
53 extra_origins_label: "SOMA_MCP_ALLOWED_ORIGINS",
54 public_url_label: "SOMA_MCP_PUBLIC_URL",
55 })
56}