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).
Softpack MCP Server
A comprehensive FastAPI-based MCP (Model Context Protocol) server that enables LLMs and external services to interact with spack package management commands. This server is part of the Softpack ecosystem and provides a complete bridge between language models and the spack package manager, including session management, recipe building, and Git integration.
Features
- š FastAPI Integration: Modern async/await web framework with automatic API documentation
- š§ MCP Protocol: Seamless integration with language models via fastapi-mcp
- š¦ Spack Commands: Complete interface to spack package management operations
- šÆ Session Management: Isolated workspaces for package development
- š Recipe Building: Interactive recipe creation and management
- š Git Integration: Automated Git operations for package workflows
- š Structured Logging: Comprehensive logging with rotation and context
- š”ļø Error Handling: Robust exception handling and validation
- š Security: CORS and authentication support
- š Auto Documentation: Interactive API docs with Swagger UI
- š Web Wizard Interface: Interactive 6-step wizard for package creation and management
MCP Tools Available
The server exposes the following comprehensive set of tools to LLMs:
Spack Package Management
search_packages
- Search for available spack packageslist_packages
- List installed packagesget_package_info
- Get comprehensive package informationinstall_package
- Install a spack package with variantsinstall_package_stream
- Install with real-time streaming outputuninstall_package
- Remove installed packagesuninstall_package_with_dependents
- Remove package and all dependentscopy_existing_package
- Copy existing packages from builtin to sessionget_package_versions
- Get available versions for a packageget_package_checksums
- Get checksums for package versionscreate_pypi_package
- Create spack package from PyPIcreate_recipe_from_url
- Create spack package from URLvalidate_package
- Validate package recipevalidate_package_stream
- Validate with real-time streaming
Session Management
create_session
- Create isolated development sessionlist_sessions
- List all active sessionsget_session_info
- Get session detailsdelete_session
- Remove session and all contentslist_session_files
- List files in session directory
Recipe Management
create_recipe
- Create new package recipelist_recipes
- List all recipes in sessionread_recipe
- Read recipe contentwrite_recipe
- Write/update recipe contentdelete_recipe
- Remove recipevalidate_recipe
- Validate recipe syntax and contentget_recipe_info
- Get recipe metadata
Git Operations
pull_spack_repo
- Pull latest spack-repo updatesget_git_commit_info
- Get commit information for repositorycreate_pull_request
- Create pull request for package
Access Management
request_collaborator_access
- Request GitHub collaborator access
Quick Start
Prerequisites
- Python 3.10+
- Spack package manager installed
- Git (for repository operations)
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 (Backend Only)
make debug
Production Mode (Backend + Frontend)
make prod
Frontend Only
make frontend
Configuration
Environment Variables
The application uses environment variables for configuration. Copy .env.example
to .env
and modify as needed:
cp .env.example .env
Available Environment Variables
SOFTPACK_HOST
: Backend server host (default:127.0.0.1
)SOFTPACK_PORT
: Backend server port (default:8000
)SOFTPACK_DEBUG
: Enable debug mode (default:false
)SOFTPACK_LOG_LEVEL
: Logging level (default:INFO
)SOFTPACK_SPACK_EXECUTABLE
: Path to spack executable (default:spack
)SOFTPACK_COMMAND_TIMEOUT
: Command execution timeout in seconds (default:300
)API_BASE_URL
: Frontend API base URL (default:http://localhost:8000
)
API Documentation
Once the server is running, visit:
- Interactive API Docs: http://localhost:8000/docs
- ReDoc Documentation: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
- Web Wizard Interface: http://localhost:8001
Web Wizard Interface
The project includes a comprehensive web-based wizard interface (index.html
) that provides an interactive 6-step workflow for creating and managing spack packages:
Wizard Steps
- Package Information - Enter package name and type (Python, R, or Other)
- Recipe Existence Check - Automatically check if recipe already exists in spack-repo
- Recipe Creation/Version Management - Create new recipes or manage versions for existing ones
- Recipe Modification - Interactive recipe editor with syntax highlighting and validation
- Build and Test - Install package and run validation tests with real-time output
- Create Pull Request - Prepare Git operations and request collaborator access
Key Features
- Interactive Recipe Editor - Syntax-highlighted editor with real-time validation
- Real-time Streaming - Live output for package installation and validation
- Automatic Recipe Generation - Support for PyPI packages and existing spack recipes
- Session Management - Isolated workspaces for package development
- Git Integration - Automated branch creation and pull request preparation
- Access Management - Built-in collaborator access request system
- Progress Tracking - Visual progress bar and step-by-step guidance
Accessing the Wizard
The wizard is served on port 8001 and automatically connects to the API server:
# Start both backend and frontend
make prod
# Or start frontend only (requires backend on port 8000)
make frontend
Then visit: http://localhost:8001
Core Features
Session Management
The server provides isolated development sessions for package building:
# Create a new session
curl -X POST "http://localhost:8000/sessions/create" \
-H "Content-Type: application/json" \
-d '{"namespace": "my-packages"}'
# List sessions
curl "http://localhost:8000/sessions/list"
Recipe Building
Interactive recipe creation and management within sessions:
# Create a new recipe
curl -X POST "http://localhost:8000/recipes/{session_id}/{package_name}/create"
# Write recipe content
curl -X PUT "http://localhost:8000/recipes/{session_id}/{package_name}" \
-H "Content-Type: application/json" \
-d '{"content": "class MyPackage(Package): ..."}'
# Validate recipe
curl -X POST "http://localhost:8000/recipes/{session_id}/{package_name}/validate" \
-H "Content-Type: application/json" \
-d '{"content": "class MyPackage(Package): ..."}'
Streaming Operations
Real-time streaming for long-running operations:
# Streaming installation
curl -X POST "http://localhost:8000/spack/install/stream" \
-H "Content-Type: application/json" \
-d '{"package_name": "zlib", "version": "1.2.13"}' \
--no-buffer
# Streaming validation
curl -X POST "http://localhost:8000/spack/validate/stream" \
-H "Content-Type: application/json" \
-d '{"session_id": "my-session", "package_name": "my-package"}' \
--no-buffer
Git Integration
Automated Git operations for package workflows:
# Pull latest spack-repo updates
curl -X POST "http://localhost:8000/git/pull" \
-H "Content-Type: application/json" \
-d '{"repo_path": "/path/to/spack-repo"}'
# Create pull request
curl -X POST "http://localhost:8000/git/pull-request" \
-H "Content-Type: application/json" \
-d '{"package_name": "my-package", "session_id": "my-session"}'
Examples
See the examples/
directory for complete working examples:
session_example.py
- Session management workflowrecipe_example.py
- Recipe creation and validationcopy_package_example.py
- Copying existing packagesstreaming_client.py
- Streaming installation client
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
# Run integration tests
make test-integration
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
ā āāā repos.yaml # Spack repository configuration
ā āāā models/ # Pydantic models
ā ā āāā requests.py # Request models
ā ā āāā responses.py # Response models
ā āāā tools/ # MCP tool implementations
ā ā āāā spack.py # Spack tool endpoints
ā ā āāā sessions.py # Session management
ā ā āāā recipes.py # Recipe management
ā ā āāā git.py # Git operations
ā ā āāā access.py # Access management
ā āāā services/ # Business logic layer
ā ā āāā spack_service.py # Spack service
ā ā āāā session_manager.py # Session management
ā ā āāā git_service.py # Git operations
ā ā āāā access_service.py # Access management
ā āāā utils/ # Utility modules
ā āāā logging.py # Logging configuration
ā āāā exceptions.py # Custom exceptions
āāā examples/ # Example scripts and clients
ā āāā session_example.py # Session management example
ā āāā recipe_example.py # Recipe building example
ā āāā copy_package_example.py # Package copying example
ā āāā streaming_client.py # Streaming client example
ā āāā README.md # Examples documentation
āāā tests/ # Test suite
āāā index.html # Web wizard interface for package creation
āāā serve_frontend.py # Frontend server
āāā run_both.py # Combined server runner
āāā Makefile # Build and run commands
āāā 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
) - Run code quality checks (
uv run pre-commit run --all-files
) - 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: hgi@sanger.ac.uk
- š Issues: GitHub Issues
- š Documentation: API Docs
Acknowledgments
- Built with FastAPI
- MCP integration via fastapi-mcp
- Spack package manager support
- Part of the Softpack ecosystem