Skip to content

Commit 902fa8a

Browse files
author
LittleCoinCoin
committed
fix(cli): mcp host configuration when using paths to hatch pkgs
Fix the retrieval of the package name to indeed correspond to what's in the hatch package metadata file. - Resolve whether the `package_path_or_name` is indeed a path or a package name - It matters because local packages might have a different directory name than the registered package name
1 parent b2e5a80 commit 902fa8a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

hatch/cli_hatch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from hatch.environment_manager import HatchEnvironmentManager
1818
from hatch_validator import HatchPackageValidator
19+
from hatch_validator.package.package_service import PackageService
1920
from hatch.template_generator import create_package_template
2021
from hatch.mcp_host_config import MCPHostConfigurationManager, MCPHostType, MCPHostRegistry, MCPServerConfig
2122

@@ -1462,11 +1463,14 @@ def main():
14621463
hosts = parse_host_list(args.host)
14631464
env_name = args.env or env_manager.get_current_environment()
14641465

1465-
# Get the package name from the path/name argument
1466-
package_name = args.package_path_or_name
1467-
if '/' in package_name or '\\' in package_name:
1468-
# Extract package name from path
1469-
package_name = Path(package_name).name
1466+
# Is it a path or a name?
1467+
pkg_path = Path(args.package_path_or_name)
1468+
if pkg_path.exists() and pkg_path.is_dir():
1469+
with open(pkg_path / "hatch_metadata.json", 'r') as f:
1470+
metadata = json.load(f)
1471+
package_name = metadata['name']
1472+
else:
1473+
package_name = args.package_path_or_name
14701474

14711475
# Get MCP server configuration for the newly added package
14721476
server_config = get_package_mcp_server_config(env_manager, env_name, package_name)

0 commit comments

Comments
 (0)