logcut 0.3.1

Local-first stacktrace, runtime log & compiler error slicing for AI coding agents and terminal pipelines
Documentation
//! Streamable HTTP transport for MCPRush managed hosting.

use axum::Router;
use rmcp::transport::streamable_http_server::{
    StreamableHttpServerConfig, StreamableHttpService, session::local::LocalSessionManager,
};

use crate::mcp::LogcutServer;

/// Build the MCP router served at `/mcp`.
pub fn router() -> Router {
    // MCPRush calls this container through its gateway: there is no public
    // address, so rmcp's loopback-only Host allowlist would refuse every call.
    // The gateway handles authentication; adding a token check here would
    // reject all hosted calls.
    let service = StreamableHttpService::new(
        || Ok(LogcutServer::for_hosted()),
        LocalSessionManager::default().into(),
        StreamableHttpServerConfig::default()
            .disable_allowed_hosts()
            .with_json_response(true),
    );
    Router::new().route_service("/mcp", service)
}

/// Serve MCP over HTTP until ctrl-c. Diagnostics go to stderr, never stdout.
pub async fn serve_http(host: &str, port: u16) -> anyhow::Result<()> {
    let listener = tokio::net::TcpListener::bind((host, port)).await?;
    eprintln!("logcut: serving MCP at http://{host}:{port}/mcp");
    axum::serve(listener, router())
        .with_graceful_shutdown(async {
            if tokio::signal::ctrl_c().await.is_err() {
                eprintln!("logcut: failed to listen for shutdown signal");
            }
        })
        .await?;
    Ok(())
}