From 4a82ed02cf8e38c7c88ae01b5f621e7a728e8851 Mon Sep 17 00:00:00 2001 From: damocles Date: Wed, 1 Jul 2026 17:58:22 +0200 Subject: [PATCH] feat(#2038): render http mcp url when HYPERHIVE_MCP_HTTP_PORT set --- hive-ag3nt/src/mcp.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/hive-ag3nt/src/mcp.rs b/hive-ag3nt/src/mcp.rs index db21c244..da8dac22 100644 --- a/hive-ag3nt/src/mcp.rs +++ b/hive-ag3nt/src/mcp.rs @@ -2212,14 +2212,27 @@ fn load_extra_mcp() -> std::collections::BTreeMap { #[must_use] pub fn render_claude_config(agent_binary: &str, socket: &std::path::Path) -> String { let mut servers = serde_json::Map::new(); - servers.insert( - SERVER_NAME.to_owned(), - serde_json::json!({ + // When the harness is configured to run the built-in server as a + // persistent streamable-http daemon (loopback port in + // `HYPERHIVE_MCP_HTTP_PORT`), point claude at the stable URL instead of + // respawning a fresh stdio child each turn. The URL survives the per-turn + // claude re-spawn, so there is no per-turn re-registration race for the + // hyperhive surface. Extra servers (matrix/bash) stay stdio bridges. + let hyperhive_entry = match std::env::var("HYPERHIVE_MCP_HTTP_PORT") + .ok() + .and_then(|p| p.trim().parse::().ok()) + { + Some(port) => serde_json::json!({ + "type": "http", + "url": format!("http://127.0.0.1:{port}/mcp"), + }), + None => serde_json::json!({ "command": agent_binary, "args": ["--socket", socket.display().to_string(), "mcp"], "env": {} }), - ); + }; + servers.insert(SERVER_NAME.to_owned(), hyperhive_entry); // Auto-inject HYPERHIVE_STATE_DIR so extra MCP servers can resolve the // agent's durable state dir without the agent author hard-coding it. // User-supplied env takes precedence — we only fill in the missing key.