Skip to content

πŸ™Œ 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.py
index 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 LLM
from openhands.sdk.plugin import PluginSource
from openhands.sdk.secret import LookupSecret, SecretValue, StaticSecret
from openhands.sdk.utils.paging import page_iterator
-from openhands.sdk.utils.redact import sanitize_dict
from openhands.sdk.workspace.remote.async_remote_workspace import AsyncRemoteWorkspace
from openhands.server.types import AppMode
from 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_config
from 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 SDK
mcp_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_config
diff --git a/openhands/mcp/utils.py b/openhands/mcp/utils.py
index df0e420a40..82fb267c8d 100644
--- a/openhands/mcp/utils.py
+++ b/openhands/mcp/utils.py
@@ -24,7 +24,11 @@ from openhands.mcp.client import MCPClient
from openhands.mcp.error_collector import mcp_error_collector
from openhands.runtime.base import Runtime
from 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,
+ )
continue
is_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 provides
tool_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