@@ -24,7 +24,6 @@ use crate::cli::{Cli, Command, Configuration, HttpCommand, StdioCommand};
2424use crate :: protocol:: http:: { HttpProtocol , HttpServerConfig } ;
2525use crate :: servers:: elasticsearch;
2626use crate :: utils:: interpolator;
27- use is_container:: is_container;
2827use rmcp:: transport:: stdio;
2928use rmcp:: transport:: streamable_http_server:: session:: never:: NeverSessionManager ;
3029use rmcp:: { RoleServer , Service , ServiceExt } ;
@@ -37,15 +36,15 @@ use tokio_util::sync::CancellationToken;
3736impl Cli {
3837 pub async fn run ( self ) -> anyhow:: Result < ( ) > {
3938 match self . command {
40- Command :: Stdio ( cmd) => run_stdio ( cmd) . await ,
41- Command :: Http ( cmd) => run_http ( cmd) . await ,
39+ Command :: Stdio ( cmd) => run_stdio ( cmd, self . container_mode ) . await ,
40+ Command :: Http ( cmd) => run_http ( cmd, self . container_mode ) . await ,
4241 }
4342 }
4443}
4544
46- pub async fn run_stdio ( cmd : StdioCommand ) -> anyhow:: Result < ( ) > {
45+ pub async fn run_stdio ( cmd : StdioCommand , container_mode : bool ) -> anyhow:: Result < ( ) > {
4746 tracing:: info!( "Starting stdio server" ) ;
48- let handler = setup_services ( & cmd. config ) . await ?;
47+ let handler = setup_services ( & cmd. config , container_mode ) . await ?;
4948 let service = handler. serve ( stdio ( ) ) . await . inspect_err ( |e| {
5049 tracing:: error!( "serving error: {:?}" , e) ;
5150 } ) ?;
@@ -58,12 +57,12 @@ pub async fn run_stdio(cmd: StdioCommand) -> anyhow::Result<()> {
5857 Ok ( ( ) )
5958}
6059
61- pub async fn run_http ( cmd : HttpCommand ) -> anyhow:: Result < ( ) > {
62- let handler = setup_services ( & cmd. config ) . await ?;
60+ pub async fn run_http ( cmd : HttpCommand , container_mode : bool ) -> anyhow:: Result < ( ) > {
61+ let handler = setup_services ( & cmd. config , container_mode ) . await ?;
6362 let server_provider = move || handler. clone ( ) ;
6463 let address: SocketAddr = if let Some ( addr) = cmd. address {
6564 addr
66- } else if is_container ( ) {
65+ } else if container_mode {
6766 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , 8080 )
6867 } else {
6968 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: LOCALHOST ) , 8080 )
@@ -89,7 +88,7 @@ pub async fn run_http(cmd: HttpCommand) -> anyhow::Result<()> {
8988 Ok ( ( ) )
9089}
9190
92- pub async fn setup_services ( config : & Option < PathBuf > ) -> anyhow:: Result < impl Service < RoleServer > + Clone > {
91+ pub async fn setup_services ( config : & Option < PathBuf > , container_mode : bool ) -> anyhow:: Result < impl Service < RoleServer > + Clone > {
9392 // Read config file and expand variables
9493
9594 let config = if let Some ( path) = config {
@@ -123,6 +122,6 @@ pub async fn setup_services(config: &Option<PathBuf>) -> anyhow::Result<impl Ser
123122 Err ( err) => return Err ( err) ?,
124123 } ;
125124
126- let handler = elasticsearch:: ElasticsearchMcp :: new_with_config ( config. elasticsearch ) ?;
125+ let handler = elasticsearch:: ElasticsearchMcp :: new_with_config ( config. elasticsearch , container_mode ) ?;
127126 Ok ( handler)
128127}
0 commit comments