Package Handlers¶
The package handlers module (cli_package.py) contains handlers for package management commands.
Overview¶
This module provides handlers for:
- Package Installation: Add packages to environments
- Package Removal: Remove packages with confirmation
- Package Listing: List packages (deprecated - use
env list) - Package Synchronization: Synchronize package MCP servers to hosts
Handler Functions¶
Package Management¶
handle_package_add(): Add packages to environments with optional host configurationhandle_package_remove(): Remove packages with confirmationhandle_package_list(): List packages (deprecated - usehatch env list)handle_package_sync(): Synchronize package MCP servers to hosts
Internal Helpers¶
_get_package_names_with_dependencies(): Get package name and dependencies_configure_packages_on_hosts(): Shared logic for configuring packages on hosts
Handler Signature¶
All handlers follow the standard signature:
def handle_package_command(args: Namespace) -> int:
"""Handle 'hatch package command' command.
Args:
args: Namespace with:
- env_manager: HatchEnvironmentManager instance
- mcp_manager: MCPHostConfigurationManager instance
- <command-specific arguments>
Returns:
Exit code (0 for success, 1 for error)
"""
Module Reference¶
hatch.cli.cli_package
¶
Package CLI handlers for Hatch.
This module contains handlers for package management commands. Packages are MCP server implementations that can be installed into environments and configured on MCP host platforms.
Commands
- hatch package add
: Add a package to an environment - hatch package remove
: Remove a package from an environment - hatch package list: List packages in an environment
- hatch package sync
: Synchronize package MCP servers to hosts
Package Workflow
- Add package to environment: hatch package add my-mcp-server
- Configure on hosts: hatch mcp configure claude-desktop my-mcp-server ...
- Or sync automatically: hatch package sync my-mcp-server --host all
Handler Signature
All handlers follow: (args: Namespace) -> int - args.env_manager: HatchEnvironmentManager instance - Returns: EXIT_SUCCESS (0) on success, EXIT_ERROR (1) on failure
Internal Helpers
_configure_packages_on_hosts(): Shared logic for configuring packages on hosts
Example
$ hatch package add mcp-server-fetch $ hatch package list $ hatch package sync mcp-server-fetch --host claude-desktop,cursor
Classes¶
Functions¶
handle_package_add(args)
¶
Handle 'hatch package add' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - env_manager: HatchEnvironmentManager instance - mcp_manager: MCPHostConfigurationManager instance - package_path_or_name: Package path or name - env: Optional environment name - version: Optional version - force_download: Force download even if cached - refresh_registry: Force registry refresh - auto_approve: Skip confirmation prompts - host: Optional comma-separated host list for MCP configuration |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 for error) |
Source code in hatch/cli/cli_package.py
handle_package_list(args)
¶
Handle 'hatch package list' command.
.. deprecated:: This command is deprecated. Use 'hatch env list' instead, which shows packages inline with environment information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - env_manager: HatchEnvironmentManager instance - env: Optional environment name (default: current) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success) |
Source code in hatch/cli/cli_package.py
handle_package_remove(args)
¶
Handle 'hatch package remove' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - env_manager: HatchEnvironmentManager instance - package_name: Name of package to remove - env: Optional environment name (default: current) - dry_run: Preview changes without execution - auto_approve: Skip confirmation prompt |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 for error) |
Reference: R03 §3.1 (03-mutation_output_specification_v0.md)
Source code in hatch/cli/cli_package.py
handle_package_sync(args)
¶
Handle 'hatch package sync' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - env_manager: HatchEnvironmentManager instance - mcp_manager: MCPHostConfigurationManager instance - package_name: Package name to sync - host: Comma-separated host list (required) - env: Optional environment name - dry_run: Preview only - auto_approve: Skip confirmation - no_backup: Skip backup creation |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 for error) |
Source code in hatch/cli/cli_package.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |