A secure Mixed Integer Programming (MIP) optimization server using the Model Context Protocol (MCP) with PuLP and Pyodide WebAssembly security.
- About
- Features
- Getting Started
- Usage
- Examples
- Development
- Architecture
- Contributing
- License
- Authors
- Acknowledgments
MIP MCP Server enables Large Language Models (LLMs) to execute PuLP optimization code and solve Mixed Integer Programming problems through a secure, standardized interface. The server uses Pyodide WebAssembly for complete process isolation while providing access to powerful optimization capabilities via SCIP solver.
- Security First: Complete WebAssembly sandbox isolation
- LLM Integration: Native Model Context Protocol support
- High Performance: SCIP solver with customizable parameters
- Zero Configuration: Automatic problem detection and solving
- Production Ready: Comprehensive testing and validation
- 🛡️ Secure Execution: Pyodide WebAssembly sandbox with complete process isolation
- 📊 PuLP Support: Full compatibility with PuLP optimization library
- 🔍 Auto Detection: Automatic problem detection from PuLP objects
- ⚡ SCIP Integration: High-performance optimization solving with pyscipopt
- 🌐 MCP Protocol: Standards-based LLM integration via Model Context Protocol
- 🎛️ Flexible Parameters: Customizable solver settings and validation options
- 📁 Format Support: Automatic LP/MPS format detection and generation
- 📈 Progress Reporting: Real-time optimization progress with 10-second intervals
- ✅ Solution Validation: Built-in constraint validation with configurable tolerance
- Python 3.12 or higher
- uv (recommended) or pip
- Node.js (for Pyodide WebAssembly execution)
git clone https://github.com/yourusername/mip-mcp.git
cd mip-mcp
uv sync
git clone https://github.com/yourusername/mip-mcp.git
cd mip-mcp
pip install -e .
For direct execution without local installation:
# Method 1: Automatic dependency installation (recommended)
uvx --from git+https://github.com/ohtaman/mip-mcp.git mip-mcp
# Method 2: Manual setup if automatic installation fails
git clone https://github.com/ohtaman/mip-mcp.git
cd mip-mcp
npm install # Install Node.js dependencies
uvx --from . mip-mcp
Note: When using uvx with GitHub repositories, Node.js dependencies (pyodide) are automatically installed on first run. If automatic installation fails, ensure you have npm installed and run npm install
manually.
Start the MCP server:
# Using uv
uv run mip-mcp
# Using pip installation
mip-mcp
The server will start and listen for MCP connections, providing optimization tools to connected LLM clients.
Execute PuLP optimization code in a secure WebAssembly environment.
# Example PuLP code
import pulp
prob = pulp.LpProblem("Simple_LP", pulp.LpMaximize)
x = pulp.LpVariable("x", lowBound=0)
y = pulp.LpVariable("y", lowBound=0)
prob += 3*x + 2*y # Objective
prob += 2*x + y <= 100 # Constraint
prob += x + y <= 80 # Constraint
Parameters:
code
(str): PuLP Python code to executedata
(dict, optional): Input data for the optimization problemsolver_params
(dict, optional): SCIP solver parametersvalidate_solution
(bool, default=True): Enable solution validationvalidation_tolerance
(float, default=1e-6): Numerical toleranceinclude_solver_output
(bool, default=False): Include detailed solver statistics
Retrieve information about the available SCIP solver including version and capabilities.
Validate PuLP code for syntax errors, security issues, and Pyodide compatibility.
Get example PuLP code snippets demonstrating various optimization problem types.
Create config/default.yaml
to customize server behavior:
server:
name: "mip-mcp"
version: "0.1.0"
timeout: 60
solver:
default: "scip"
timeout: 300
parameters:
threads: 4
gap: 0.01
time_limit: 600
security:
enable_validation: true
execution_timeout: 60
allowed_imports:
- pulp
- math
- numpy
logging:
level: "INFO"
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
import pulp
# Create problem
prob = pulp.LpProblem("Diet_Problem", pulp.LpMinimize)
# Variables
x1 = pulp.LpVariable("Bread", lowBound=0)
x2 = pulp.LpVariable("Milk", lowBound=0)
# Objective function
prob += 0.15*x1 + 0.25*x2
# Constraints
prob += 4*x1 + 3*x2 >= 10 # Protein
prob += 2*x1 + 2*x2 >= 8 # Carbs
import pulp
# Knapsack problem
prob = pulp.LpProblem("Knapsack", pulp.LpMaximize)
# Binary variables for items
items = ['item1', 'item2', 'item3']
x = pulp.LpVariable.dicts("x", items, cat='Binary')
# Objective: maximize value
values = {'item1': 10, 'item2': 20, 'item3': 15}
prob += pulp.lpSum([values[i] * x[i] for i in items])
# Constraint: weight limit
weights = {'item1': 5, 'item2': 8, 'item3': 3}
prob += pulp.lpSum([weights[i] * x[i] for i in items]) <= 10
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=src/mip_mcp --cov-report=html
# Run specific test file
uv run pytest tests/unit/test_handlers.py -v
# Format code and fix issues
make format
# Run linting checks
make lint
# Check code formatting without changes
make lint-check
# Or use Ruff directly
uv run ruff format src/ tests/
uv run ruff check --fix src/ tests/
# Install development dependencies
uv sync --group dev
# Install pre-commit hooks (recommended)
make pre-commit-install
# OR use pre-commit directly
uv run pre-commit install
This project uses pre-commit hooks to automatically check code quality before commits:
# Install pre-commit hooks
make pre-commit-install
# Run pre-commit on all files
make pre-commit-run
# Update hook versions
make pre-commit-update
The pre-commit hooks will automatically:
- Format code with Ruff
- Fix linting issues
- Check for trailing whitespace
- Validate YAML and TOML files
- Check for merge conflicts
- Remove debug statements
If pre-commit hooks fail, fix the issues and commit again. To skip hooks in emergencies:
git commit --no-verify -m "Emergency commit"
src/mip_mcp/
├── __init__.py # Package initialization
├── mcp_server.py # Main MCP server entry point
├── server.py # FastMCP server implementation
├── exceptions.py # Custom exception classes
├── handlers/ # MCP request handlers
│ ├── __init__.py
│ └── execute_code.py # Code execution handler
├── executor/ # Code execution engines
│ ├── __init__.py
│ └── pyodide_executor.py # Pyodide WebAssembly executor
├── solvers/ # Optimization solver interfaces
│ ├── __init__.py
│ ├── base.py # Base solver interface
│ └── scip_solver.py # SCIP solver implementation
├── models/ # Data models and schemas
│ ├── __init__.py
│ ├── config.py # Configuration models
│ ├── responses.py # API response models
│ └── solution.py # Solution data models
├── utils/ # Utility functions
│ ├── __init__.py
│ ├── config_manager.py # Configuration management
│ ├── library_detector.py # Library detection utilities
│ ├── logger.py # Logging configuration
│ └── solution_validator.py # Solution validation
└── config/ # Configuration files
└── default.yaml # Default configuration
- MCP Server: FastMCP-based server implementing Model Context Protocol
- Pyodide Executor: WebAssembly-based secure code execution engine
- SCIP Solver: High-performance optimization solver integration
- Handlers: Request processing and response generation
- Models: Pydantic-based data validation and serialization
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for your changes
- Ensure all tests pass
- Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow PEP 8 style guidelines
- Add type hints for all functions
- Write comprehensive tests
- Update documentation as needed
- Ensure security best practices
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- ohtaman - Initial work - ohtaman
- PuLP - Python Linear Programming library
- SCIP - Solving Constraint Integer Programs
- Pyodide - Python scientific stack in WebAssembly
- FastMCP - Fast Model Context Protocol implementation
- Model Context Protocol - Standard for LLM-tool integration