From e220b11b4a51186930ee4c056f9386f995682f0f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 19:05:51 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20security:=20handle=20McpServer?= =?UTF-8?q?=20initialization=20errors=20gracefully?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed McpServer::new to return Result - Replaced unwrap() with ? operator for LocalReasoningEngine initialization - Updated main.rs to propagate initialization errors - Prevents potential DoS via unhandled panics during startup sequence Co-authored-by: LeandroPG19 <151863062+LeandroPG19@users.noreply.github.com> --- cuba_cognitive_engine/src/main.rs | 2 +- cuba_cognitive_engine/src/server/mcp_protocol.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cuba_cognitive_engine/src/main.rs b/cuba_cognitive_engine/src/main.rs index 27460b9..3569f9d 100644 --- a/cuba_cognitive_engine/src/main.rs +++ b/cuba_cognitive_engine/src/main.rs @@ -17,7 +17,7 @@ async fn main() -> anyhow::Result<()> { // 2. Initialize the MCP Protocol Server // This replaces the entire Python layer. - let mcp_server = std::sync::Arc::new(server::McpServer::new()); + let mcp_server = std::sync::Arc::new(server::McpServer::new()?); // 3. Block on the execution loop mcp_server.run().await?; diff --git a/cuba_cognitive_engine/src/server/mcp_protocol.rs b/cuba_cognitive_engine/src/server/mcp_protocol.rs index 41311c5..49ee288 100644 --- a/cuba_cognitive_engine/src/server/mcp_protocol.rs +++ b/cuba_cognitive_engine/src/server/mcp_protocol.rs @@ -133,16 +133,16 @@ pub struct McpServer { } impl McpServer { - pub fn new() -> Self { + pub fn new() -> Result { // DEBT-T07: Direct sandbox, no router indirection - let sandbox = Arc::new(LocalReasoningEngine::new("cognitive-engine-v3", 2).unwrap()); + let sandbox = Arc::new(LocalReasoningEngine::new("cognitive-engine-v3", 2)?); let sessions = Arc::new(crate::engine::thought_session::SessionStore::new()); let metrics = Arc::new(RedMetrics::new()); - Self { + Ok(Self { sandbox, sessions, metrics, - } + }) } /// Primary Execution Loop (STDIO)