π OpenHands: AI-Driven Development
fix: redact MCP server secrets from log output (#13840)
OpenHands Bot21d86b6b5e29
diff --git a/openhands/app_server/app_conversation/live_status_app_conversation_service.py b/openhands/app_server/app_conversation/live_status_app_conversation_service.pyindex b35d3dc03a..090da5f8d0 100644--- a/openhands/app_server/app_conversation/live_status_app_conversation_service.py+++ b/openhands/app_server/app_conversation/live_status_app_conversation_service.py@@ -92,7 +92,6 @@ from openhands.sdk.llm import LLMfrom openhands.sdk.plugin import PluginSourcefrom openhands.sdk.secret import LookupSecret, SecretValue, StaticSecretfrom openhands.sdk.utils.paging import page_iterator-from openhands.sdk.utils.redact import sanitize_dictfrom openhands.sdk.workspace.remote.async_remote_workspace import AsyncRemoteWorkspacefrom openhands.server.types import AppModefrom openhands.storage.data_models.conversation_metadata import ConversationTrigger@@ -104,6 +103,7 @@ from openhands.tools.preset.planning import (format_plan_structure,get_planning_tools,)+from openhands.utils._redact_compat import sanitize_configfrom openhands.utils.git import ensure_valid_git_branch_name_conversation_info_type_adapter = TypeAdapter(list[ConversationInfo | None])@@ -1114,7 +1114,7 @@ class LiveStatusAppConversationService(AppConversationServiceBase):# Wrap in the mcpServers structure required by the SDKmcp_config = {'mcpServers': mcp_servers} if mcp_servers else {}- _logger.info(f'Final MCP configuration: {sanitize_dict(mcp_config)}')+ _logger.info(f'Final MCP configuration: {sanitize_config(mcp_config)}')return llm, mcp_configdiff --git a/openhands/mcp/utils.py b/openhands/mcp/utils.pyindex df0e420a40..82fb267c8d 100644--- a/openhands/mcp/utils.py+++ b/openhands/mcp/utils.py@@ -24,7 +24,11 @@ from openhands.mcp.client import MCPClientfrom openhands.mcp.error_collector import mcp_error_collectorfrom openhands.runtime.base import Runtimefrom openhands.runtime.impl.cli.cli_runtime import CLIRuntime-from openhands.sdk.utils.redact import sanitize_dict+from openhands.utils._redact_compat import (+ redact_text_secrets,+ redact_url_params,+ sanitize_config,+)def convert_mcp_clients_to_tools(mcp_clients: list[MCPClient] | None) -> list[dict]:@@ -101,7 +105,9 @@ async def create_mcp_clients()continue- logger.info(f'Initializing MCP agent for {server} with stdio connection...')+ logger.info(+ f'Initializing MCP agent for {redact_text_secrets(str(server))} with stdio connection...'+ )client = MCPClient()try:await client.connect_stdio(server)@@ -119,14 +125,17 @@ async def create_mcp_clients(mcp_clients.append(client)except Exception as e:# Error is already logged and collected in client.connect_stdio()- logger.error(f'Failed to connect to {server}: {str(e)}', exc_info=True)+ logger.error(+ f'Failed to connect to {redact_text_secrets(str(server))}: {str(e)}',+ exc_info=True,+ )continueis_shttp = isinstance(server, MCPSHTTPServerConfig)connection_type = 'SHTTP' if is_shttp else 'SSE'logger.info(- f'Initializing MCP agent for {server} with {connection_type} connection...'+ f'Initializing MCP agent for {redact_text_secrets(str(server))} with {connection_type} connection...')client = MCPClient()@@ -141,7 +150,7 @@ async def create_mcp_clients(# Log which tools this specific server providestool_names = [tool.name for tool in client.tools]logger.debug(- f'Successfully connected to MCP STTP server {server.url} - '+ f'Successfully connected to MCP STTP server {redact_url_params(server.url)} - 'f'provides {len(tool_names)} tools: {tool_names}')@@ -150,7 +159,10 @@ async def create_mcp_clients(except Exception as e:# Error is already logged and collected in client.connect_http()- logger.error(f'Failed to connect to {server}: {str(e)}', exc_info=True)+ logger.error(+ f'Failed to connect to {redact_text_secrets(str(server))}: {str(e)}',+ exc_info=True,+ )return mcp_clients@@ -179,7 +191,7 @@ async def fetch_mcp_tools_from_config(mcp_tools = []try:logger.debug(- f'Creating MCP clients with config: {sanitize_dict(mcp_config.model_dump())}'+ f'Creating MCP clients with config: {sanitize_config(mcp_config.model_dump())}')# Create clients - this will fetch tools but not maintain active connections