π OpenHands: AI-Driven Development
Remove mcp_config.py: drop TOML-based MCP configuration (#14241)
Tim O'Farrelld035bf1fe16d
diff --git a/openhands/app_server/settings/settings_models.py b/openhands/app_server/settings/settings_models.pyindex c3ee294d85..2814cf108d 100644--- a/openhands/app_server/settings/settings_models.py+++ b/openhands/app_server/settings/settings_models.py@@ -13,6 +13,7 @@ from __future__ import annotationsfrom enum import Enumfrom typing import Annotated, Any+from fastmcp.mcp_config import MCPConfigfrom fastmcp.mcp_config import MCPConfig as SDKMCPConfigfrom pydantic import (BaseModel,@@ -35,7 +36,6 @@ from openhands.app_server.utils.sdk_settings_compat import (default_agent_settings,validate_agent_settings,)-from openhands.core.config.mcp_config import MCPConfigfrom openhands.sdk.settings import ConversationSettingsdiff --git a/openhands/core/config/__init__.py b/openhands/core/config/__init__.pyindex 7c860c2fa2..3cefa4b071 100644--- a/openhands/core/config/__init__.py+++ b/openhands/core/config/__init__.py@@ -6,7 +6,6 @@ from openhands.core.config.config_utils import (OH_DEFAULT_AGENT,OH_MAX_ITERATIONS,)-from openhands.core.config.mcp_config import MCPConfigfrom openhands.core.config.openhands_config import OpenHandsConfigfrom openhands.core.config.utils import (finalize_config,@@ -21,7 +20,6 @@ __all__ = ['OH_DEFAULT_AGENT','OH_MAX_ITERATIONS','OpenHandsConfig',- 'MCPConfig','load_openhands_config','load_from_env','load_from_toml',diff --git a/openhands/core/config/mcp_config.py b/openhands/core/config/mcp_config.pydeleted file mode 100644index 0904a10b54..0000000000--- a/openhands/core/config/mcp_config.py+++ /dev/null@@ -1,93 +0,0 @@-"""MCP configuration β thin wrappers around the SDK MCPConfig from *fastmcp*.--All server configuration uses the unified ``MCPConfig.mcpServers`` dict.-Legacy helpers (``from_toml_section``) are provided for config.toml parsing.-"""--from __future__ import annotations--import shlex-from typing import Any--from fastmcp.mcp_config import MCPConfig, RemoteMCPServer, StdioMCPServer--__all__ = [- 'MCPConfig',- 'RemoteMCPServer',- 'StdioMCPServer',- 'mcp_config_from_toml',-]---# ----------------------------------------------------------------------------# Helpers-# ------------------------------------------------------------------------------def _parse_stdio_args(v: Any) -> list[str]:- """Parse stdio args from a string using shlex or return list as-is."""- if isinstance(v, str):- if not v.strip():- return []- return shlex.split(v.strip())- return list(v or [])---def _parse_stdio_env(v: Any) -> dict[str, str]:- """Parse stdio env from a comma-separated string or return dict as-is."""- if isinstance(v, str):- env: dict[str, str] = {}- for pair in v.split(','):- pair = pair.strip()- if not pair:- continue- if '=' not in pair:- raise ValueError(- f"Environment variable '{pair}' must be in KEY=VALUE format"- )- key, value = pair.split('=', 1)- env[key.strip()] = value- return env- return dict(v or {})---def mcp_config_from_toml(data: dict[str, Any]) -> dict[str, MCPConfig]:- """Parse a ``[mcp]`` TOML section into ``{'mcp': MCPConfig}``.-- Accepts the legacy ``sse_servers`` / ``shttp_servers`` / ``stdio_servers``- list format and converts to the unified ``mcpServers`` dict.- """- servers: dict[str, RemoteMCPServer | StdioMCPServer] = {}-- for entry in data.get('sse_servers', []):- if isinstance(entry, str):- entry = {'url': entry}- name = f'sse_{len([k for k in servers if k.startswith("sse_")])}'- servers[name] = RemoteMCPServer(- url=entry['url'],- transport='sse',- auth=entry.get('api_key'),- )-- for entry in data.get('shttp_servers', []):- if isinstance(entry, str):- entry = {'url': entry}- name = f'shttp_{len([k for k in servers if k.startswith("shttp_")])}'- servers[name] = RemoteMCPServer(- url=entry['url'],- transport='http',- auth=entry.get('api_key'),- timeout=entry.get('timeout', 60),- )-- for entry in data.get('stdio_servers', []):- name = entry.get(- 'name', f'stdio_{len([k for k in servers if k.startswith("stdio_")])}'- )- servers[name] = StdioMCPServer(- command=entry['command'],- args=_parse_stdio_args(entry.get('args', [])),- env=_parse_stdio_env(entry.get('env', {})),- )-- return {'mcp': MCPConfig(mcpServers=servers)}diff --git a/openhands/core/config/openhands_config.py b/openhands/core/config/openhands_config.pyindex 3bdd20ea13..7900d83e49 100644--- a/openhands/core/config/openhands_config.py+++ b/openhands/core/config/openhands_config.py@@ -16,7 +16,6 @@ from openhands.core.config.config_utils import (OH_MAX_ITERATIONS,model_defaults_to_dict,)-from openhands.core.config.mcp_config import MCPConfigclass OpenHandsConfig(BaseModel):@@ -48,7 +47,6 @@ class OpenHandsConfig(BaseModel):cli_multiline_input: Whether to enable multiline input in CLI. When disabled,input is read line by line. When enabled, input continues until /exit command.mcp_host: Host for OpenHands' default MCP server- mcp: MCP configuration settings.git_user_name: Git user name for commits made by the agent.git_user_email: Git user email for commits made by the agent."""@@ -100,7 +98,6 @@ class OpenHandsConfig(BaseModel):description='Timeout in seconds for waiting for websocket client connection during initialization',)mcp_host: str = Field(default=f'localhost:{os.getenv("port", 3000)}')- mcp: MCPConfig = Field(default_factory=MCPConfig)git_user_name: str = Field(default='openhands', description='Git user name for commits made by the agent')diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.pyindex 91dd18b963..f797b0665c 100644--- a/openhands/core/config/utils.py+++ b/openhands/core/config/utils.py@@ -16,13 +16,12 @@ from uuid import uuid4import tomlfrom dotenv import load_dotenv-from pydantic import BaseModel, SecretStr, ValidationError+from pydantic import BaseModel, SecretStrfrom openhands.app_server.file_store import get_file_storefrom openhands.app_server.file_store.files import FileStorefrom openhands.app_server.utils import loggerfrom openhands.core.config.arg_utils import get_headless_parser-from openhands.core.config.mcp_config import mcp_config_from_tomlfrom openhands.core.config.openhands_config import OpenHandsConfigJWT_SECRET = '.jwt_secret'@@ -175,25 +174,12 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> Nonef'Unknown config key "{key}" in [core] section')- # Process MCP sections if present- if 'mcp' in toml_config:- try:- mcp_mapping = mcp_config_from_toml(toml_config['mcp'])- if 'mcp' in mcp_mapping:- cfg.mcp = mcp_mapping['mcp']- except (TypeError, KeyError, ValidationError) as e:- logger.openhands_logger.warning(- f'Cannot parse MCP config from toml, values have not been applied.\nError: {e}'- )- except ValueError:- raise ValueError('Error in MCP sections in config.toml')-# Check for unknown sections# Note: legacy sections are kept for backwards compatibility with old config# files - they are silently ignoredknown_sections = {'core',- 'mcp',+ 'mcp', # Legacy, ignored'llm', # Legacy, ignored'sandbox', # Legacy, ignored'security', # Legacy, ignoreddiff --git a/tests/unit/app_server/test_live_status_app_conversation_service.py b/tests/unit/app_server/test_live_status_app_conversation_service.pyindex b16d353bd1..cb0b4130b4 100644--- a/tests/unit/app_server/test_live_status_app_conversation_service.py+++ b/tests/unit/app_server/test_live_status_app_conversation_service.py@@ -1746,7 +1746,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_with_custom_remote_servers(self):"""Test _configure_llm_and_mcp merges custom remote servers."""- from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServer+ from fastmcp.mcp_config import MCPConfig, RemoteMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1775,7 +1775,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_with_custom_http_servers(self):"""Test _configure_llm_and_mcp merges custom HTTP servers with timeout."""- from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServer+ from fastmcp.mcp_config import MCPConfig, RemoteMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1800,7 +1800,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_with_custom_stdio_servers(self):"""Test _configure_llm_and_mcp merges custom STDIO servers with explicit names."""- from openhands.core.config.mcp_config import MCPConfig, StdioMCPServer+ from fastmcp.mcp_config import MCPConfig, StdioMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1829,7 +1829,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_merges_system_and_custom_servers(self):"""Test _configure_llm_and_mcp merges both system and custom MCP servers."""- from openhands.core.config.mcp_config import (+ from fastmcp.mcp_config import (MCPConfig,RemoteMCPServer,StdioMCPServer,@@ -1906,7 +1906,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_empty_custom_config(self):"""Test _configure_llm_and_mcp handles empty custom MCP config."""- from openhands.core.config.mcp_config import MCPConfig+ from fastmcp.mcp_config import MCPConfigself.mock_user.mcp_config = MCPConfig(mcpServers={})self.mock_user_context.get_mcp_api_key.return_value = None@@ -1922,7 +1922,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_remote_server_without_auth(self):"""Test _configure_llm_and_mcp handles remote servers without auth."""- from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServer+ from fastmcp.mcp_config import MCPConfig, RemoteMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1941,7 +1941,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_http_server_default_timeout(self):"""Test _configure_llm_and_mcp handles HTTP servers with default timeout."""- from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServer+ from fastmcp.mcp_config import MCPConfig, RemoteMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1962,7 +1962,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_stdio_server_without_env(self):"""Test _configure_llm_and_mcp handles STDIO servers without environment variables."""- from openhands.core.config.mcp_config import MCPConfig, StdioMCPServer+ from fastmcp.mcp_config import MCPConfig, StdioMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -1984,7 +1984,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_multiple_servers_same_type(self):"""Test _configure_llm_and_mcp handles multiple custom servers of the same type."""- from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServer+ from fastmcp.mcp_config import MCPConfig, RemoteMCPServerself.mock_user.mcp_config = MCPConfig(mcpServers={@@ -2014,7 +2014,7 @@ class TestLiveStatusAppConversationService:@pytest.mark.asyncioasync def test_configure_llm_and_mcp_mixed_server_types(self):"""Test _configure_llm_and_mcp handles all server types together."""- from openhands.core.config.mcp_config import (+ from fastmcp.mcp_config import (MCPConfig,RemoteMCPServer,StdioMCPServer,diff --git a/tests/unit/core/config/test_shttp_timeout_config.py b/tests/unit/core/config/test_shttp_timeout_config.pyindex 75f5964d32..ba98f621f6 100644--- a/tests/unit/core/config/test_shttp_timeout_config.py+++ b/tests/unit/core/config/test_shttp_timeout_config.py@@ -1,6 +1,6 @@"""Test MCP remote server timeout configuration."""-from openhands.core.config.mcp_config import RemoteMCPServer+from fastmcp.mcp_config import RemoteMCPServerclass TestRemoteMCPServer:diff --git a/tests/unit/mcp/test_mcp_integration.py b/tests/unit/mcp/test_mcp_integration.pyindex b11f43ed02..a3d95940c8 100644--- a/tests/unit/mcp/test_mcp_integration.py+++ b/tests/unit/mcp/test_mcp_integration.py@@ -3,11 +3,11 @@from unittest.mock import AsyncMock, patchimport pytest+from fastmcp.mcp_config import MCPConfig, RemoteMCPServerfrom openhands.app_server.settings.file_settings_store import FileSettingsStorefrom openhands.app_server.settings.settings_models import Settingsfrom openhands.app_server.user_auth.default_user_auth import DefaultUserAuth-from openhands.core.config.mcp_config import MCPConfig, RemoteMCPServerfrom openhands.sdk.llm import LLMfrom openhands.sdk.settings import AgentSettings