davlloyd/vcenter-mcp
If you are the rightful owner of vcenter-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.
MCP Server for VMware VCenter Tooling is designed to facilitate seamless integration and management of VMware VCenter environments using the Model Context Protocol (MCP).
vCenter MCP Server
A Model Context Protocol (MCP) server for VMware vCenter that provides read-only access to vCenter resources including clusters, resource pools, and virtual machines.
Features
- Read-only access to vCenter resources
- Cloud Foundry deployment support for Tanzu Cloud Foundry
- Flexible credential management via environment variables or Cloud Foundry service bindings
- vCenter REST API integration for all operations
- FastMCP framework for MCP protocol support
- MVC architecture following software design best practices
- Comprehensive testing with pytest
- Type hints throughout the codebase
Supported Operations
- List all clusters - Get all clusters in vCenter
- List VMs in cluster - Get all virtual machines in a specific cluster
- List resource pools - Get all resource pools in a specific cluster
- List VMs in resource pool - Get all virtual machines in a specific resource pool
- Get vCenter status - Get connection status and basic statistics
Project Structure (MVC Architecture)
vcenter-mcp/
āāā main/ # Main application package
ā āāā __init__.py
ā āāā __main__.py # Application entry point
ā āāā server_factory.py # Server creation and MVC initialization
ā āāā models/ # Data models (M in MVC)
ā ā āāā __init__.py
ā ā āāā vcenter_config.py # Configuration and data models
ā āāā views/ # Presentation layer (V in MVC)
ā ā āāā __init__.py
ā ā āāā mcp_tools.py # MCP tools and formatting
ā āāā controllers/ # Business logic (C in MVC)
ā ā āāā __init__.py
ā ā āāā vcenter_controller.py # Main controller
ā āāā services/ # Service layer
ā ā āāā __init__.py
ā ā āāā vcenter_service.py # vCenter API service
ā āāā config/ # Configuration management
ā āāā __init__.py
ā āāā config_manager.py # Configuration and credentials
āāā tests/ # Test suite
ā āāā __init__.py
ā āāā test_config.py # Configuration tests
ā āāā test_mvc_structure.py # MVC structure tests
āāā app.py # Legacy entry point
āāā test_connection.py # Connection testing utility
āāā config.env.example # Environment configuration template
āāā setup_env.py # Environment setup script
āāā requirements.txt # Python dependencies
āāā setup.py # Package setup
āāā pyproject.toml # Modern Python packaging
āāā manifest.yml # Cloud Foundry manifest
āāā Procfile # Cloud Foundry process
āāā runtime.txt # Python runtime version
āāā README.md # This file
Architecture Overview
MVC Pattern Implementation
-
Models (
main/models/
): Data structures and configuration modelsVCenterConfig
: Configuration for vCenter connectionCluster
,ResourcePool
,VirtualMachine
: Data models for vCenter resources
-
Views (
main/views/
): Presentation layer for MCP toolsMCPToolsView
: Handles MCP tool registration and data formatting- Formats data for display to MCP clients
-
Controllers (
main/controllers/
): Business logic and coordinationVCenterController
: Main controller that coordinates between models and views- Handles data transformation and business rules
-
Services (
main/services/
): Data access layerVCenterService
: Handles vCenter REST API interactions- Manages HTTP requests and responses
-
Config (
main/config/
): Configuration managementConfigManager
: Handles credentials and environment configuration- Supports Cloud Foundry service bindings
-
Server Factory (
main/server_factory.py
): Application initializationcreate_mcp_server()
: Creates and configures the MCP server- Handles proper MVC component initialization
- Resolves circular import issues
Prerequisites
- Python 3.12+ (Required - tested with Python 3.12.3, Cloud Foundry uses python-3.12.*)
- VMware vCenter server with REST API access
- vCenter credentials (username/password)
Installation
Development Installation
- Clone this repository:
git clone <repository-url>
cd vcenter-mcp
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install in development mode:
pip install -e .
- Install development dependencies:
pip install -e ".[dev]"
Production Installation
pip install vcenter-mcp
Configuration
Environment Setup
The easiest way to set up your environment is using the provided setup script:
# Interactive setup
python setup_env.py
# View current configuration (passwords are masked)
python setup_env.py show
Manual Environment Variables
Alternatively, you can manually set the following environment variables for vCenter access:
export VCENTER_HOST="https://your-vcenter-server.com"
export VCENTER_USERNAME="your-username"
export VCENTER_PASSWORD="your-password"
# Optional configuration
export VCENTER_VERIFY_SSL="true" # Default: true
export VCENTER_TIMEOUT="30" # Default: 30 seconds
export LOG_LEVEL="INFO" # Default: INFO
Using .env File
Create a .env
file in the project root with the following content:
# Copy from config.env.example and update with your values
VCENTER_HOST=https://your-vcenter-server.com
VCENTER_USERNAME=your-username
VCENTER_PASSWORD=your-password
VCENTER_VERIFY_SSL=true
VCENTER_TIMEOUT=30
LOG_LEVEL=INFO
Cloud Foundry Service Binding
Alternatively, you can bind to a vCenter service in Cloud Foundry. The service should provide credentials in the following format:
{
"host": "https://your-vcenter-server.com",
"username": "your-username",
"password": "your-password"
}
Usage
Command Line
Run the MCP server:
# Using the package
python -m main
# Using the console script (if installed)
vcenter-mcp
# Using the legacy entry point
python app.py
Programmatic Usage
from main.config.config_manager import ConfigManager
from main.controllers.vcenter_controller import VCenterController
# Get configuration
config_manager = ConfigManager()
config = config_manager.get_vcenter_config()
# Create controller and run MCP server
controller = VCenterController(config)
app = controller.create_mcp_server()
app.run()
Testing Configuration
After setting up your environment, test your vCenter connection:
# Test connection and basic API calls
python test_connection.py
# View current configuration (passwords are masked)
python setup_env.py show
Cloud Foundry Deployment
The application is configured for Cloud Foundry with flexible Python versioning:
- Runtime:
python-3.12.*
(allows automatic updates to any 3.12.x version) - Buildpack:
python_buildpack
- Memory: 256M
- Disk: 512M
- Transport: HTTP using FastMCP's async
http
transport (compatible with Spring AI WebMVC) - Health Check: HTTP endpoint at
/health
Deploy to Tanzu Cloud Foundry
- Login to your Cloud Foundry instance:
cf login -a https://api.your-cf-instance.com
- Set the target organization and space:
cf target -o your-org -s your-space
- Deploy the application:
cf push
Environment Variables in Cloud Foundry
Set environment variables for vCenter access:
cf set-env vcenter-mcp-server VCENTER_HOST "https://your-vcenter-server.com"
cf set-env vcenter-mcp-server VCENTER_USERNAME "your-username"
cf set-env vcenter-mcp-server VCENTER_PASSWORD "your-password"
Optional: Bind to vCenter Service
If you have a vCenter service available in your Cloud Foundry marketplace:
cf create-service vcenter-service standard vcenter-service
cf bind-service vcenter-mcp-server vcenter-service
MCP Tools
The MCP server provides the following tools with proper names and descriptions for better discovery:
1. List Clusters (list_clusters
)
Description: List all clusters in vCenter. Returns a formatted list of all available clusters with their names and IDs.
Usage:
list_clusters()
2. List VMs in Cluster (list_vms_in_cluster
)
Description: List all virtual machines in a specific cluster. Requires the cluster name as input and returns a formatted list of VMs with their names and power states.
Usage:
list_vms_in_cluster(cluster_name: str)
3. List Resource Pools (list_resource_pools
)
Description: List all resource pools in a specific cluster. Requires the cluster name as input and returns a formatted list of resource pools with their names and IDs.
Usage:
list_resource_pools(cluster_name: str)
4. List VMs in Resource Pool (list_vms_in_resource_pool
)
Description: List all virtual machines in a specific resource pool. Requires the resource pool name as input and returns a formatted list of VMs with their names and power states.
Usage:
list_vms_in_resource_pool(resource_pool_name: str)
5. Get vCenter Status (get_vcenter_status
)
Description: Get vCenter connection status and basic information. Returns connection status, host information, and counts of clusters, resource pools, and virtual machines.
Usage:
get_vcenter_status()
MCP Client Connection
Cloud Foundry Deployment
When deployed to Cloud Foundry, the MCP server is accessible via HTTPS transport:
- URL:
https://vcenter-mcp-server.apps.tas.tanzu.rocks
(port 443) - Transport:
http
(async) - Protocol: MCP over HTTPS
Local Development
For local development, the server runs on:
- Host:
0.0.0.0
(default, configurable viaHOST
environment variable) - Port:
8080
(default, configurable viaPORT
environment variable) - Transport:
http
(async)
Note: Cloud Foundry sets the PORT
environment variable for health checks, while external access is routed through HTTPS on port 443. The application must use the PORT
environment variable to ensure health checks work correctly. The server defaults to port 8080 but can be overridden with the PORT
environment variable.
Development
Python Version
This project requires Python 3.12+ and has been tested with Python 3.12.3. For Cloud Foundry deployment, the runtime is set to python-3.12.*
to allow automatic minor version updates.
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=main
# Run specific test file
pytest tests/test_mvc_structure.py
Code Quality
# Format code
black main/ tests/
# Lint code
flake8 main/ tests/
# Type checking
mypy main/
Building the Package
# Build wheel
python -m build
# Install from wheel
pip install dist/vcenter_mcp-*.whl
API Endpoints
Health Check Endpoint
GET /health
- Application health status (returns JSON with status information)
MCP Protocol Endpoint
The server uses FastMCP's async http
transport for MCP protocol communication over HTTP, compatible with Spring AI WebMVC MCP servers.
vCenter REST API Endpoints
The server uses the vCenter REST API with the following endpoints:
GET /rest/vcenter/cluster
- List clustersGET /rest/vcenter/resource-pool
- List resource poolsGET /rest/vcenter/vm
- List virtual machines
Security Considerations
- The server operates in read-only mode
- Credentials are stored securely in environment variables or service bindings
- SSL verification is enabled by default
- No persistent storage of sensitive data
- All API requests are logged for debugging
Troubleshooting
Common Issues
- Connection failed: Verify vCenter host URL and credentials
- SSL certificate errors: Ensure vCenter has valid SSL certificates
- Authentication failed: Check username and password
- API access denied: Verify user has appropriate permissions
- MCP client timeout: Ensure the client is configured to use
http
transport (compatible with Spring AI WebMVC) - Cloud Foundry deployment issues: Check that the app is running and accessible via HTTPS on port 443
Logs
Check application logs for detailed error information:
# Local development
python -m main
# Cloud Foundry
cf logs vcenter-mcp-server --recent
Debug Mode
Enable debug logging:
export LOG_LEVEL=DEBUG
python -m main
Contributing
- Fork the repository
- Create a feature branch
- Make your changes following the MVC pattern
- Add tests for new functionality
- Run the test suite
- Submit a pull request
Development Setup
# Clone and setup
git clone <your-fork-url>
cd vcenter-mcp
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black main/ tests/
Adding New Features
When adding new features, follow the MVC pattern:
- Models: Add new data models in
main/models/
- Services: Add API interactions in
main/services/
- Controllers: Add business logic in
main/controllers/
- Views: Add presentation logic in
main/views/
- Tests: Add corresponding tests in
tests/
License
[Add your license information here]
Changelog
1.0.0
- Initial release
- MVC architecture implementation
- Comprehensive testing
- Cloud Foundry deployment support
- FastMCP integration