02: Configuring Hatch Packages on MCP Hosts¶
Concepts covered:
- Hatch package deployment with automatic dependency resolution
hatch package add --hostandhatch package synccommands- Guaranteed dependency installation (Python, apt, Docker, other Hatch packages)
- Package-first deployment advantages over direct configuration
Skills you will practice:
- Using
hatch package add --hostfor direct deployment - Using
hatch package syncfor existing packages - Validating complete dependency resolution
- Testing package functionality across different host platforms
This article covers the preferred method for deploying MCP servers to host platforms using Hatch packages. This approach guarantees that all dependencies (Python packages, system packages, Docker containers, and other Hatch packages) are correctly installed before MCP host deployment.
Why Package-First Deployment?¶
Automatic Dependency Resolution¶
Hatch packages include complete dependency specifications that are automatically resolved during deployment:
# Package deployment handles ALL dependencies automatically
hatch package add my-weather-server --host claude-desktop
# ✅ Installs Python dependencies (requests, numpy, etc.)
# ✅ Installs system dependencies (curl, git, etc.)
# ✅ Installs Docker containers if specified
# ✅ Installs other Hatch package dependencies
# ✅ Configures MCP server on Claude Desktop
Comparison with Direct Configuration¶
Package Deployment (Recommended): - ✅ Automatic dependency resolution - ✅ Guaranteed compatibility - ✅ Single command deployment - ✅ Environment isolation - ✅ Rollback capabilities
Direct Configuration (Advanced): - ❌ Manual dependency management required - ❌ No compatibility guarantees - ❌ Multiple setup steps - ❌ Potential environment conflicts - ❌ Limited rollback options
Step 1: Deploy Package to Single Host¶
Use the package you created in Tutorial 03 for this exercise.
Basic Package Deployment¶
Deploy your package directly to a host platform:
# Navigate to your package directory from Tutorial 03
cd my_new_package
# Deploy to Claude Desktop with automatic dependency resolution
hatch package add . --host claude-desktop
Expected Output:
[SUCCESS] Operation completed:
[ADDED] Package 'my_new_package'
Configuring MCP server for package 'my_new_package' on 1 host(s)...
✓ Configured my_new_package on claude-desktop
Verify Deployment¶
Check that your package is properly configured:
# List configured servers on Claude Desktop
hatch mcp list servers --host claude-desktop
# Verify package installation
hatch package list
You should see your package listed in both the MCP server configuration and the installed packages.
Step 2: Deploy to Multiple Hosts¶
Deploy your package to multiple host platforms simultaneously:
# Deploy to multiple hosts
hatch package add . --host claude-desktop,cursor,vscode
# Deploy to all available hosts
hatch package add . --host all
Expected Behavior: - Dependencies are resolved once and applied to all hosts - Each host receives appropriate configuration format - All hosts are updated simultaneously - Backup files are created for each host
Step 3: Sync Existing Packages¶
If you have packages already installed in your environment, use hatch package sync to deploy them to hosts:
List Available Packages¶
Sync Specific Package¶
Note: The hatch package sync command requires a package name. To sync all packages from an environment to hosts, use hatch mcp sync --from-env <env_name> --to-host <hosts> (covered in Tutorial 04-04).
Step 4: Validate Dependency Resolution¶
Check Dependency Installation¶
Verify that all dependencies were correctly installed:
# Check Python environment
hatch env current
python -c "import requests, numpy; print('Dependencies available')"
# Check system dependencies (Linux/macOS)
which curl
which git
# Verify package functionality
python -c "
import sys
sys.path.insert(0, '.')
from my_new_package.tools import get_weather
print('Package tools accessible')
"
Test MCP Server Functionality¶
Test that your MCP server works correctly with the host platform:
- Open Claude Desktop (or your target host)
- Check MCP server status in the application settings
- Test server functionality by using the tools you implemented
- Verify error handling by testing edge cases
Step 5: Environment-Specific Deployment¶
Deploy packages with environment-specific configurations:
Development Environment¶
# Switch to development environment
hatch env use development
# Deploy with development settings
hatch package add . --host claude-desktop
Production Environment¶
# Switch to production environment
hatch env use production
# Deploy with production settings
hatch package add . --host claude-desktop,cursor
Key Difference: Each environment maintains separate MCP server configurations, allowing you to test different versions or configurations without conflicts.
Step 6: Troubleshooting Package Deployment¶
Common Issues and Solutions¶
Dependency Installation Failures:
# Check dependency resolution
hatch package add . --host claude-desktop --dry-run
# View detailed dependency information
hatch validate .
Host Configuration Errors:
# Verify host availability
hatch mcp list hosts
# Check host-specific requirements
hatch mcp configure --help
Package Validation Issues:
Recovery Procedures¶
Rollback Failed Deployment:
# Remove problematic configuration
hatch mcp remove server my-new-package --host claude-desktop
# Restore from backup if needed
# (Backups are created automatically)
Clean Environment Reset
# Remove all MCP configurations for host
hatch mcp remove host claude-desktop
# Redeploy packages from the a hatch environment
hatch mcp sync --from-env env_name --to-host claude-desktop
Note: The hatch mcp sync command only syncs packages from one environment (or one host) at a time. If you want to re-sync other packages, you must run the command several times.
Best Practices¶
Package Development Workflow¶
- Develop and test locally using Tutorial 03 methods
- Validate package structure with
hatch validate . - Deploy to development host with
hatch package add . --host claude-desktop - Test functionality in host application
- Deploy to production hosts when ready
Dependency Management¶
- Use specific version pins for critical dependencies
- Test dependency resolution with
--dry-runbefore deployment - Keep package metadata current as dependencies change
- Document system requirements in package documentation
Environment Isolation¶
- Use separate environments for development, testing, and production
- Deploy environment-specific packages to appropriate hosts
- Maintain environment boundaries to prevent configuration conflicts
Next Steps¶
You now understand the preferred method for deploying MCP servers using Hatch packages with automatic dependency resolution. This approach provides the most reliable and maintainable deployment workflow.
Continue to: Tutorial 04-03: Configuring Arbitrary Servers to learn the alternative direct configuration method for non-Hatch MCP servers.
Related Documentation: - Package Commands Reference - Complete command syntax - Package Authoring Tutorial - Creating packages for deployment