Skip to content

Commit fa273a4

Browse files
author
LittleCoinCoin
committed
fix(serialization): explicit model dump of server configuration
Prevent error `Failed to save environments: Object of type MCPServerConfig is not JSON serializable` - Use `model_dump` on the `MCPServerConfig` data model - Imported the `MCPServerConfig` for typing in method signature.
1 parent 6c5bc07 commit fa273a4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

hatch/environment_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from hatch.installers.dependency_installation_orchestrator import DependencyInstallerOrchestrator
1818
from hatch.installers.installation_context import InstallationContext
1919
from hatch.python_environment_manager import PythonEnvironmentManager, PythonEnvironmentError
20+
from hatch.mcp_host_config.models import MCPServerConfig
2021

2122
class HatchEnvironmentError(Exception):
2223
"""Exception raised for environment-related errors."""
@@ -724,7 +725,7 @@ def clear_host_from_all_packages_all_envs(self, hostname: str) -> int:
724725
self.logger.error(f"Failed to clear host from all packages: {e}")
725726
return 0
726727

727-
def apply_restored_host_configuration_to_environments(self, hostname: str, restored_servers: dict) -> int:
728+
def apply_restored_host_configuration_to_environments(self, hostname: str, restored_servers: Dict[str, MCPServerConfig]) -> int:
728729
"""Update environment tracking to match restored host configuration.
729730
730731
Args:
@@ -754,7 +755,7 @@ def apply_restored_host_configuration_to_environments(self, hostname: str, resto
754755
"config_path": self._get_host_config_path(hostname),
755756
"configured_at": configured_hosts.get(hostname, {}).get("configured_at", current_time),
756757
"last_synced": current_time,
757-
"server_config": server_config
758+
"server_config": server_config.model_dump(exclude_none=True)
758759
}
759760
updates_count += 1
760761
self.logger.info(f"Updated host {hostname} tracking for package {package_name} in env {env_name}")

0 commit comments

Comments
 (0)