wtsi-hgi/softpack-mcp
If you are the rightful owner of softpack-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Softpack MCP Server is a FastAPI-based server that connects language models with the spack package manager, facilitating seamless interaction through the Model Context Protocol (MCP).
search_packages
Search for available spack packages.
install_package
Install a spack package with variants.
list_packages
List installed packages.
get_package_info
Get comprehensive package information, including dependencies and build details.
uninstall_package
Remove installed packages.
Softpack MCP Server
A FastAPI-based MCP (Model Context Protocol) server that enables LLMs to interact with spack package management commands. This server is part of the Softpack ecosystem and provides a bridge between language models and the spack package manager.
Features
- š FastAPI Integration: Modern async/await web framework
- š§ MCP Protocol: Seamless integration with language models
- š¦ Spack Commands: Direct interface to spack package management
- š Structured Logging: Comprehensive logging with rotation
- š”ļø Error Handling: Robust exception handling and validation
- š Security: CORS and authentication support
- š Auto Documentation: Interactive API docs with Swagger UI
MCP Tools Available
The server exposes the following tools to LLMs:
Spack Package Management
search_packages
- Search for available spack packagesinstall_package
- Install a spack package with variantsinstall_package_stream
- NEW! Install a spack package with real-time streaming outputlist_packages
- List installed packagesget_package_info
- Get comprehensive package information (includes dependencies, variants, build details)uninstall_package
- Remove installed packagescopy_existing_package
- NEW! Copy existing spack packages from builtin packages to session without using spack create
Quick Start
Prerequisites
- Python 3.8+
- Spack package manager installed
Installation
-
Clone the repository:
git clone <repository-url> cd softpack-mcp
-
Initialize the project:
make init
This will:
- Install dependencies with uv
- Set up pre-commit hooks
- Create necessary directories
- Create a
.env
file with default values
Running the Server
Development Mode
make debug
Production Mode
make prod
API Documentation
Once the server is running, visit:
- Interactive API Docs: http://localhost:8000/docs
- MCP Endpoint: http://localhost:8000/mcp
MCP Integration
This server implements the Model Context Protocol (MCP), allowing language models to:
- Discover Tools: Automatically detect available spack commands
- Execute Commands: Run spack operations through structured API calls
- Get Results: Receive formatted responses with error handling
Example MCP Tool Usage
{
"tool": "install_package",
"parameters": {
"package_name": "python",
"version": "3.11.0",
"variants": ["+shared", "+optimizations"],
"dependencies": ["zlib", "openssl"]
}
}
Streaming Installation
The server now supports real-time streaming of spack installation progress using Server-Sent Events (SSE). This allows you to see installation progress as it happens, rather than waiting for completion.
Streaming Endpoint
POST /spack/install/stream
Features
- Real-time Progress: See installation output as it happens
- Event Types: Different event types (start, output, error, complete)
- Timestamps: Each event includes a timestamp
- Success Tracking: Final event indicates installation success/failure
Example Usage
# Using curl
curl -X POST "http://localhost:8000/spack/install/stream" \
-H "Content-Type: application/json" \
-d '{"package_name": "zlib", "version": "1.2.13"}' \
--no-buffer
Example Client
See examples/streaming_client.py
for a complete Python client example.
Event Types
start
: Installation startedoutput
: Standard output from spackerror
: Error output from spackcomplete
: Installation completed (with success status)
Benefits
- Real-time Feedback: No need to wait for completion to see progress
- Better UX: Users can see what's happening during long installations
- Debugging: Easier to identify where installations fail
- Monitoring: Can be used for monitoring and logging systems
Copy Existing Packages
The server now supports copying existing spack packages from builtin packages to session directories without using spack create
. This functionality mimics the create()
function from the .zshrc
file but skips the spack create
step.
Copy Package Endpoint
POST /spack/copy-package
Features
- Direct Copy: Copies existing packages from builtin packages to session
- Legacy Spack Support: Automatically checks out legacy spack commit
78f95ff38d591cbe956a726f4a93f57d21840f86
before copying packages - Automatic Modifications: Applies the same modifications as the shell function:
- Comments out
c
,cxx
, andfortran
build dependencies - Removes
: EnvironmentModifications
from class definitions - Removes
checked_by
from license lines - Comments out
from spack_repo.builtin
imports
- Comments out
- Patch Files: Automatically copies any
.patch
files - Session Isolation: Works within isolated session directories
Example Usage
# Using curl
curl -X POST "http://localhost:8000/spack/copy-package" \
-H "Content-Type: application/json" \
-d '{"package_name": "zlib", "session_id": "your-session-id"}'
Example Response
{
"success": true,
"message": "Successfully copied package 'zlib' to session your-session-id",
"package_name": "zlib",
"source_path": "repos/spack_repo/builtin/packages/zlib",
"destination_path": "spack-repo/packages/zlib",
"recipe_path": "spack-repo/packages/zlib/package.py",
"copy_details": {
"patch_files": ["w_patch.patch", "configure-cc.patch"],
"legacy_commit": "78f95ff38d591cbe956a726f4a93f57d21840f86",
"git_checkout_success": true,
"modifications_applied": [
"commented_out_c_cxx_fortran_dependencies",
"removed_environment_modifications",
"removed_checked_by_from_licenses",
"commented_out_spack_repo_builtin_imports"
]
}
}
Example Client
See examples/copy_package_example.py
for a complete Python client example.
Benefits
- Faster Setup: No need to run
spack create
for existing packages - Consistent Modifications: Applies the same modifications as the shell function
- Session Isolation: Works within isolated session directories
- Patch Preservation: Automatically copies patch files
- Error Handling: Proper error handling for missing packages or sessions
Development
Setup Development Environment
# Initialize the project (installs dependencies and sets up pre-commit)
make init
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=softpack_mcp
Code Quality
# Format and lint code
uv run ruff check . --fix
uv run ruff format .
# Run pre-commit on all files
uv run pre-commit run --all-files
Project Structure
softpack-mcp/
āāā softpack_mcp/ # Main application package
ā āāā __init__.py
ā āāā main.py # FastAPI application
ā āāā config.py # Configuration management
ā āāā models/ # Pydantic models
ā ā āāā requests.py # Request models
ā ā āāā responses.py # Response models
ā āāā tools/ # MCP tool implementations
ā ā āāā spack.py # Spack tool endpoints
ā āāā services/ # Business logic layer
ā ā āāā spack_service.py # Spack service
ā āāā utils/ # Utility modules
ā āāā logging.py # Logging configuration
ā āāā exceptions.py # Custom exceptions
āāā examples/ # Example scripts and clients
ā āāā streaming_client.py # Streaming installation example
ā āāā README.md # Examples documentation
āāā tests/ # Test suite
āāā pyproject.toml # Project configuration
āāā README.md # This file
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
pytest
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the file for details.
Support
- š§ Email:
- š Issues: GitHub Issues
- š Documentation: API Docs
Acknowledgments
- Built with FastAPI
- Spack package manager support
- Part of the Softpack ecosystem
Development Setup
Pre-commit Hooks
This project uses ruff
for code formatting and linting via pre-commit hooks.
# Initialize the project
make init
# Run pre-commit on all files
uv run pre-commit run --all-files
Ruff Configuration
The project uses ruff for:
- Code formatting (replaces black)
- Import sorting (replaces isort)
- Linting (includes pycodestyle, pyflakes, flake8-bugbear, etc.)
Configuration is in pyproject.toml
under [tool.ruff]
.
Logging
This project uses structured logging with automatic log rotation.
Features:
- Colored console output
- Structured logging with context
- Automatic log rotation
- Exception tracing
Manual Ruff Usage
You can also run ruff directly:
# Check and fix issues
uv run ruff check . --fix
# Format code
uv run ruff format .