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
fix(mcp): report whether a server has auth instead of the auth itself
oxoxDevbeb955e0192a
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp.rs b/crates/openhuman-core/src/tools/impl/network/mcp.rsindex 03061693bd..b043d63fdb 100644--- a/crates/openhuman-core/src/tools/impl/network/mcp.rs+++ b/crates/openhuman-core/src/tools/impl/network/mcp.rs@@ -1,4 +1,4 @@-use crate::mcp::config_servers::{McpRegistrySource, McpServerRegistry};+use crate::mcp::config_servers::{McpDefinitionAuth, McpRegistrySource, McpServerRegistry};use crate::security::{SecurityPolicy, ToolOperation};use async_trait::async_trait;use serde_json::{json, Value};@@ -49,12 +49,13 @@ impl Tool for McpListServersTool {.map(|server| {json!({"name": server.name,- "endpoint": server.endpoint,+ "endpoint": endpoint_without_query(&server.endpoint),"description": server.description,"timeout_secs": server.timeout_secs,"allowed_tools": server.allowed_tools,"disallowed_tools": server.disallowed_tools,- "auth": server.auth,+ "auth_configured": !matches!(server.auth, McpDefinitionAuth::None),+ "auth_kind": auth_kind(&server.auth),"source": server.source,})})@@ -73,20 +74,8 @@ impl Tool for McpListServersTool {md.push_str(&format!("\n- **{}** ({source})\n - endpoint: `{}`\n - auth: `{}`",server.name,- server.endpoint,- match &server.auth {- tinymcp_bus::McpAuthConfig::None => "none",- tinymcp_bus::McpAuthConfig::BearerToken { .. } => "bearer_token",- tinymcp_bus::McpAuthConfig::Basic { .. } => "basic",- tinymcp_bus::McpAuthConfig::Header { .. } => "header",- tinymcp_bus::McpAuthConfig::Headers { .. } => "headers",- tinymcp_bus::McpAuthConfig::QueryParam { .. } => "query_param",- // The contract's auth enum is `#[non_exhaustive]`, so a- // kind a newer one adds is reported rather than failing- // the build. This is a label in a listing; an unknown- // one is honest.- _ => "unknown",- }+ endpoint_without_query(&server.endpoint),+ auth_kind(&server.auth)));if let Some(description) = server.description.as_deref() {md.push_str(&format!("\n - {description}"));@@ -286,6 +275,24 @@ impl Tool for McpCallTool {}}+fn auth_kind(auth: &McpDefinitionAuth) -> &'static str {+ match auth {+ McpDefinitionAuth::None => "none",+ McpDefinitionAuth::BearerToken { .. } => "bearer_token",+ McpDefinitionAuth::Basic { .. } => "basic",+ McpDefinitionAuth::Header { .. } => "header",+ McpDefinitionAuth::Headers { .. } => "headers",+ McpDefinitionAuth::QueryParam { .. } => "query_param",+ _ => "unknown",+ }+}++fn endpoint_without_query(endpoint: &str) -> &str {+ endpoint+ .find(['?', '#'])+ .map_or(endpoint, |cut| &endpoint[..cut])+}+fn required_string_arg(args: &Value, key: &str) -> anyhow::Result<String> {let value = args.get(key)diff --git a/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs b/crates/openhuman-core/src/tools/impl/network/mcp_tests.rsindex ef8ddb50f9..654dc51414 100644--- a/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs+++ b/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs@@ -2,11 +2,18 @@ use super::*;use crate::config::{Config, McpServerConfig};fn test_registry() -> Arc<McpServerRegistry> {+ registry_with(+ "https://example.com/mcp",+ crate::config::McpAuthConfig::None,+ )+}++fn registry_with(endpoint: &str, auth: crate::config::McpAuthConfig) -> Arc<McpServerRegistry> {let mut config = Config::default();config.gitbooks.enabled = false;config.mcp_client.servers.push(McpServerConfig {name: "docs".into(),- endpoint: "https://example.com/mcp".into(),+ endpoint: endpoint.into(),command: String::new(),args: Vec::new(),env: std::collections::HashMap::new(),@@ -16,7 +23,7 @@ fn test_registry() -> Arc<McpServerRegistry> {allowed_tools: Vec::new(),disallowed_tools: Vec::new(),timeout_secs: 30,- auth: crate::config::McpAuthConfig::None,+ auth,});// Through the host conversion, so the test builds the registry the// same way the application does.@@ -37,3 +44,99 @@ async fn list_tools_requires_server() {let result = tool.execute(json!({})).await;assert!(result.is_err());}++const SECRET: &str = "s3cr3t-Value_91";++fn every_auth_kind() -> Vec<(crate::config::McpAuthConfig, &'static str)> {+ use crate::config::{HttpHeader, McpAuthConfig};+ vec![+ (+ McpAuthConfig::BearerToken {+ token: SECRET.into(),+ },+ "bearer_token",+ ),+ (+ McpAuthConfig::Basic {+ username: "svc-user".into(),+ password: SECRET.into(),+ },+ "basic",+ ),+ (+ McpAuthConfig::Header {+ name: "X-Api-Key".into(),+ value: SECRET.into(),+ },+ "header",+ ),+ (+ McpAuthConfig::Headers {+ headers: vec![+ HttpHeader {+ name: "X-Org".into(),+ value: "org-7".into(),+ },+ HttpHeader {+ name: "X-Api-Key".into(),+ value: SECRET.into(),+ },+ ],+ },+ "headers",+ ),+ (+ McpAuthConfig::QueryParam {+ name: "api_key".into(),+ value: SECRET.into(),+ },+ "query_param",+ ),+ ]+}++fn full_output(result: &ToolResult) -> String {+ format!(+ "{}\n{}\n{}",+ result.output(),+ result.markdown_formatted.clone().unwrap_or_default(),+ serde_json::to_string(&result.content).unwrap_or_default()+ )+}++#[tokio::test]+async fn list_servers_never_emits_auth_secrets() {+ for (auth, kind) in every_auth_kind() {+ let tool = McpListServersTool::new(registry_with("https://example.com/mcp", auth));+ let result = tool.execute(json!({})).await.expect("execute");+ let rendered = full_output(&result);+ assert!(!rendered.contains(SECRET), "{kind} leaked: {rendered}");+ assert!(+ rendered.contains("\"auth_configured\":true"),+ "{kind}: {rendered}"+ );+ assert!(rendered.contains(kind), "{kind}: {rendered}");+ }+}++#[tokio::test]+async fn list_servers_reports_no_auth_as_unconfigured() {+ let tool = McpListServersTool::new(test_registry());+ let result = tool.execute(json!({})).await.expect("execute");+ let rendered = full_output(&result);+ assert!(rendered.contains("\"auth_configured\":false"), "{rendered}");+ assert!(!rendered.contains("\"auth\":"), "{rendered}");+}++#[tokio::test]+async fn list_servers_strips_endpoint_query_string() {+ let tool = McpListServersTool::new(registry_with(+ &format!("https://example.com/mcp?token={SECRET}&v=2#frag"),+ crate::config::McpAuthConfig::None,+ ));+ let result = tool.execute(json!({})).await.expect("execute");+ let rendered = full_output(&result);+ assert!(!rendered.contains(SECRET), "{rendered}");+ assert!(!rendered.contains("v=2"), "{rendered}");+ assert!(rendered.contains("https://example.com/mcp"), "{rendered}");+}