The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(mcp): verify registry echo calls reach a real MCP server
Steven Enamakele99c7def10c7
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rsindex 8029b5b7ef..3a38545456 100644--- a/tests/agent_harness_e2e.rs+++ b/tests/agent_harness_e2e.rs@@ -15,6 +15,9 @@mod env_guard;#[path = "support/linked_modules.rs"]mod linked_modules;+#[cfg(feature = "mcp")]+#[path = "support/local_mcp_http.rs"]+mod local_mcp_http;#[path = "support/scripted_stack.rs"]mod scripted_stack;#[path = "support/tinyhumans_boot.rs"]@@ -3394,44 +3397,49 @@ const REGISTRY_MCP_SERVER: &str = "io.github.harness/echo";#[cfg(feature = "mcp")]const MCP_ECHO_CANARY: &str = "MCP_ECHO_CANARY_91c2";-/// An official-registry record whose npm package launches the hermetic stub.-///-/// `runtimeHint` replaces the `npx` launcher (`official/types.rs`-/// `to_example_config`), and the stub ignores the `-y <identifier>` it is given.+/// An official-registry record pointing to the local, protocol-speaking fixture.#[cfg(feature = "mcp")]-fn registry_mcp_record() -> Value {+fn registry_mcp_record(endpoint: &str) -> Value {json!({"name": REGISTRY_MCP_SERVER,"title": "Harness Echo","description": "Echoes a message back.",- "remotes": [],- "packages": [{- "registryType": "npm",- "identifier": "@harness/echo",- "runtimeHint": env!("CARGO_BIN_EXE_test-mcp-stub"),- "environmentVariables": []- }]+ "remotes": [{ "type": "streamable-http", "url": endpoint }]})}/// The official registry's list and versions endpoints, serving one server.#[cfg(feature = "mcp")]-async fn serve_mcp_registry_fixture() -> (+async fn serve_mcp_registry_fixture(+ endpoint: &str,+) -> (SocketAddr,tokio::task::JoinHandle<Result<(), std::io::Error>>,) {- async fn list() -> Json<Value> {+ async fn list(endpoint: String) -> Json<Value> {Json(json!({- "servers": [{ "server": registry_mcp_record() }],+ "servers": [{ "server": registry_mcp_record(&endpoint) }],"metadata": { "nextCursor": "" }}))}- async fn versions() -> Json<Value> {- Json(json!({ "servers": [{ "server": registry_mcp_record() }] }))+ async fn versions(endpoint: String) -> Json<Value> {+ Json(json!({ "servers": [{ "server": registry_mcp_record(&endpoint) }] }))}let app = Router::new()- .route("/v0/servers", get(list))- .route("/v0/servers/{name}/versions", get(versions));+ .route(+ "/v0/servers",+ get({+ let endpoint = endpoint.to_owned();+ move || list(endpoint.clone())+ }),+ )+ .route(+ "/v0/servers/{name}/versions",+ get({+ let endpoint = endpoint.to_owned();+ move || versions(endpoint.clone())+ }),+ );serve_on_ephemeral(app).await}@@ -3459,7 +3467,8 @@ fn agent_calls_a_tool_on_an_mcp_server_installed_from_the_registry() {#[cfg(feature = "mcp")]async fn agent_calls_a_tool_on_an_mcp_server_installed_from_the_registry_inner() {let _lock = env_lock();- let (registry_addr, registry_join) = serve_mcp_registry_fixture().await;+ let mcp_server = local_mcp_http::LocalMcpHttpServer::start_echo().await;+ let (registry_addr, registry_join) = serve_mcp_registry_fixture(mcp_server.endpoint()).await;let _registry = EnvVarGuard::set("MCP_OFFICIAL_REGISTRY_BASE",format!("http://{registry_addr}"),@@ -3485,7 +3494,8 @@ async fn agent_calls_a_tool_on_an_mcp_server_installed_from_the_registry_inner());// Declared in mcp.json (the registry is browse-only) and connected.- let server_id = declare_and_connect_registry_echo_server(&stack.rpc_base, 801).await;+ let server_id =+ declare_and_connect_registry_echo_server(&stack.rpc_base, 801, mcp_server.endpoint()).await;// Used: the orchestrator discovers the schema, then calls the tool itself.reset_script(vec![@@ -3538,22 +3548,27 @@ async fn agent_calls_a_tool_on_an_mcp_server_installed_from_the_registry_inner()result.contains(MCP_ECHO_CANARY),"the MCP server's answer did not reach the model: {result}");+ assert_echo_call(&mcp_server, MCP_ECHO_CANARY);registry_join.abort();stack.shutdown();}-/// Declare the registry's echo server in `mcp.json` the way a user who found-/// it in the registry tab would — by its command, pointed at the stub — through-/// the settings RPCs, connect it, and return its server id.+/// Declare the registry's echo server in `mcp.json` by its discovered endpoint,+/// connect it through settings RPCs, and return its server id. Registry data+/// remains browse-only and never grants operator trust.#[cfg(feature = "mcp")]-async fn declare_and_connect_registry_echo_server(rpc_base: &str, first_rpc_id: i64) -> String {+async fn declare_and_connect_registry_echo_server(+ rpc_base: &str,+ first_rpc_id: i64,+ endpoint: &str,+) -> String {let declared = post_json_rpc(rpc_base,first_rpc_id,"openhuman.mcp_clients_config_set",json!({ "mcpServers": { REGISTRY_MCP_SERVER: {- "command": env!("CARGO_BIN_EXE_test-mcp-stub"),+ "url": endpoint,// Off until the explicit connect below, so the background connect// config_set would otherwise start cannot race it."enabled": false@@ -3695,7 +3710,8 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {let _ttl = EnvVarGuard::set("OPENHUMAN_APPROVAL_TTL_SECS", "120");ensure_approval_gate().await;let _approval_bridge = register_approval_bridge();- let (registry_addr, registry_join) = serve_mcp_registry_fixture().await;+ let mcp_server = local_mcp_http::LocalMcpHttpServer::start_echo().await;+ let (registry_addr, registry_join) = serve_mcp_registry_fixture(mcp_server.endpoint()).await;let _registry = EnvVarGuard::set("MCP_OFFICIAL_REGISTRY_BASE",format!("http://{registry_addr}"),@@ -3703,7 +3719,7 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {reset_script(Vec::new());let stack = boot_stack().await;// Connecting also writes the tool cache the orchestrator's surface reads.- declare_and_connect_registry_echo_server(&stack.rpc_base, 940).await;+ declare_and_connect_registry_echo_server(&stack.rpc_base, 940, mcp_server.endpoint()).await;reset_script(vec![tool_call_completion(@@ -3791,11 +3807,30 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {!result.contains("\"is_error\":true"),"the direct MCP call failed: {result}");+ assert_echo_call(&mcp_server, MCP_ECHO_CANARY);registry_join.abort();stack.shutdown();}+#[cfg(feature = "mcp")]+fn assert_echo_call(server: &local_mcp_http::LocalMcpHttpServer, expected: &str) {+ let calls = server.tool_calls();+ assert_eq!(+ calls.len(),+ 1,+ "expected one actual MCP tools/call: {calls:?}"+ );+ assert_eq!(calls[0].get("name").and_then(Value::as_str), Some("echo"));+ assert_eq!(+ calls[0]+ .pointer("/arguments/message")+ .and_then(Value::as_str),+ Some(expected),+ "the actual MCP server must receive the model's argument"+ );+}+#[cfg(feature = "mcp")]fn scripted_discovered_mcp_tool_name(body: &Value) -> Option<String> {let native = bodydiff --git a/tests/support/local_mcp_http.rs b/tests/support/local_mcp_http.rsnew file mode 100644index 0000000000..4f251cf87a--- /dev/null+++ b/tests/support/local_mcp_http.rs@@ -0,0 +1,127 @@+//! A real loopback Streamable HTTP MCP server for host integration tests.+//!+//! Keeping this fixture at the protocol boundary exercises TinyMCP's actual+//! client while avoiding stdio sandbox/trust policy in tests of registry+//! installation and host tool projection.++use axum::extract::State;+use axum::http::StatusCode;+use axum::routing::post;+use axum::{Json, Router};+use serde_json::{json, Value};+use std::sync::{Arc, Mutex};+use tokio::task::JoinHandle;++#[derive(Clone)]+struct EchoState {+ calls: Arc<Mutex<Vec<Value>>>,+}++/// An ephemeral actual MCP HTTP endpoint exposing one `echo` tool.+pub struct LocalMcpHttpServer {+ endpoint: String,+ calls: Arc<Mutex<Vec<Value>>>,+ task: JoinHandle<()>,+}++impl LocalMcpHttpServer {+ /// Start the loopback server and return its Streamable HTTP endpoint.+ pub async fn start_echo() -> Self {+ let calls = Arc::new(Mutex::new(Vec::new()));+ let app = Router::new()+ .route("/", post(handle_request))+ .with_state(EchoState {+ calls: Arc::clone(&calls),+ });+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0")+ .await+ .expect("bind local MCP fixture");+ let endpoint = format!("http://{}/", listener.local_addr().expect("local address"));+ let task = tokio::spawn(async move {+ axum::serve(listener, app)+ .await+ .expect("serve local MCP fixture");+ });+ Self {+ endpoint,+ calls,+ task,+ }+ }++ pub fn endpoint(&self) -> &str {+ &self.endpoint+ }++ /// Snapshot the actual `tools/call` requests received by the server.+ pub fn tool_calls(&self) -> Vec<Value> {+ self.calls+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .clone()+ }+}++impl Drop for LocalMcpHttpServer {+ fn drop(&mut self) {+ self.task.abort();+ }+}++async fn handle_request(+ State(state): State<EchoState>,+ Json(request): Json<Value>,+) -> (StatusCode, Json<Value>) {+ let id = request.get("id").cloned().unwrap_or(Value::Null);+ let method = request.get("method").and_then(Value::as_str).unwrap_or("");+ let result = match method {+ "initialize" => json!({+ "protocolVersion": tinymcp_bus::LATEST_PROTOCOL_VERSION,+ "capabilities": { "tools": { "listChanged": false } },+ "serverInfo": { "name": "openhuman-test-echo", "version": "1.0.0" }+ }),+ "notifications/initialized" => {+ return (StatusCode::NO_CONTENT, Json(Value::Null));+ }+ "tools/list" => json!({+ "tools": [{+ "name": "echo",+ "description": "Echo a message for the OpenHuman harness test.",+ "inputSchema": {+ "type": "object",+ "properties": { "message": { "type": "string" } },+ "required": ["message"]+ }+ }]+ }),+ "tools/call" => {+ state+ .calls+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .push(request.get("params").cloned().unwrap_or(Value::Null));+ let message = request+ .pointer("/params/arguments/message")+ .and_then(Value::as_str)+ .unwrap_or("");+ json!({+ "content": [{ "type": "text", "text": message }],+ "isError": false+ })+ }+ _ => {+ return (+ StatusCode::OK,+ Json(json!({+ "jsonrpc": "2.0",+ "id": id,+ "error": { "code": -32601, "message": "method not found" }+ })),+ );+ }+ };+ (+ StatusCode::OK,+ Json(json!({ "jsonrpc": "2.0", "id": id, "result": result })),+ )+}