Skip to content
Merged
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
99 changes: 51 additions & 48 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ Key points:

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| {
"info,cranelift_codegen=warn,cranelift_entity=warn,cranelift_bforest=warn,cranelift_frontend=warn"
.to_string()
.into()
}),
)
.with(tracing_subscriber::fmt::layer())
.init();

let cli = Cli::parse();

match &cli.command {
Expand All @@ -200,49 +188,64 @@ async fn main() -> Result<()> {
stdio,
http,
} => {
// Initialize logging based on transport type
let use_stdio_transport = match (*stdio, *http) {
(false, false) => true, // Default case: use stdio transport
(true, false) => true, // Stdio transport only
(false, true) => false, // HTTP transport only
(true, true) => {
return Err(anyhow::anyhow!(
"Running both stdio and HTTP transports simultaneously is not supported. Please choose one."
));
}
};

// Configure logging - use stderr for stdio transport to avoid interfering with MCP protocol
let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| {
"info,cranelift_codegen=warn,cranelift_entity=warn,cranelift_bforest=warn,cranelift_frontend=warn"
.to_string()
.into()
});
Comment on lines +204 to +209
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| {
"info,cranelift_codegen=warn,cranelift_entity=warn,cranelift_bforest=warn,cranelift_frontend=warn"
.to_string()
.into()
});
let env_filter =
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
if env::var("RUST_LOG").is_ok() {
"info,cranelift_codegen=warn,cranelift_entity=warn,cranelift_bforest=warn,cranelift_frontend=warn"
.to_string()
.into()
} else {
"warn,cranelift_codegen=warn,cranelift_entity=warn,cranelift_bforest=warn,cranelift_frontend=warn"
.to_string()
.into()
}
});

I've disabled ANSII escape codes but added this optional tweak. If RUST_LOG is set, we change the level from warn to info to get the logging depth we had before.

This is because VS Code will still output the following [warning] for any output on stderr.

2025-08-05 15:46:04.454 [warning] [server stderr] 2025-08-05T19:46:04.452371Z  INFO handle_tools_list:get_component_tools: mcp_server::components: Total tools collected: 0

However, it is not trying to parse it, so I think it's OK to merge and leave as-is for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will merge in the meantime.


let registry = tracing_subscriber::registry().with(env_filter);

if use_stdio_transport {
registry
.with(
tracing_subscriber::fmt::layer()
.with_writer(std::io::stderr)
.with_ansi(false),
)
.init();
} else {
registry.with(tracing_subscriber::fmt::layer()).init();
}

let components_dir = PathBuf::from(plugin_dir);

let lifecycle_manager = LifecycleManager::new(&components_dir).await?;

let server = McpServer::new(lifecycle_manager);

match (*stdio, *http) {
(false, false) => {
// Default case: use stdio transport
tracing::info!("Starting MCP server with stdio transport (default)");
let transport = stdio_transport();
let running_service = serve_server(server, transport).await?;
if use_stdio_transport {
tracing::info!("Starting MCP server with stdio transport");
let transport = stdio_transport();
let running_service = serve_server(server, transport).await?;

tokio::signal::ctrl_c().await?;
let _ = running_service.cancel().await;
}
(true, false) => {
// Stdio transport only
tracing::info!("Starting MCP server with stdio transport");
let transport = stdio_transport();
let running_service = serve_server(server, transport).await?;

tokio::signal::ctrl_c().await?;
let _ = running_service.cancel().await;
}
(false, true) => {
// HTTP transport only
tracing::info!(
"Starting MCP server on {} with HTTP transport",
BIND_ADDRESS
);
let ct = SseServer::serve(BIND_ADDRESS.parse().unwrap())
.await?
.with_service(move || server.clone());

tokio::signal::ctrl_c().await?;
ct.cancel();
}
(true, true) => {
return Err(anyhow::anyhow!(
"Running both stdio and HTTP transports simultaneously is not supported. Please choose one."
));
}
tokio::signal::ctrl_c().await?;
let _ = running_service.cancel().await;
} else {
tracing::info!(
"Starting MCP server on {} with HTTP transport",
BIND_ADDRESS
);
let ct = SseServer::serve(BIND_ADDRESS.parse().unwrap())
.await?
.with_service(move || server.clone());

tokio::signal::ctrl_c().await?;
ct.cancel();
}

tracing::info!("MCP server shutting down");
Expand Down