SO

Solver MCP Server for Constraint Satisfaction and Optimization

Solve complex constraint satisfaction and optimization problems quickly with an MCP server offering scalable, customizable solvers and flexible APIs.

Quick Install
npx -y @szeider/mcp-solver

Overview

The Solver MCP Server is a lightweight, production-oriented server that exposes constraint satisfaction and optimization solvers over a simple HTTP API. It enables developers to submit models (variables, domains, constraints, objectives), select or tune solver backends, and retrieve solutions programmatically. The server is intended for use where automated reasoning, scheduling, and combinatorial optimization need to be integrated into applications or pipelines.

By centralizing solvers behind a service, teams can scale evaluation across machines, maintain consistent solver configurations, and decouple model construction from solver execution. The server is suitable for batch jobs, interactive services, CI verification checks, and as a backend for optimization-enabled applications.

Features

  • Solve both constraint satisfaction problems (CSP) and constraint optimization problems (COP).
  • Pluggable solver backends (selectable per-request) and configurable time/seed/cutoffs.
  • Simple JSON-based API for submitting models, checking status, and fetching results.
  • Session and model context support: incremental solving and stateful workflows.
  • Concurrency and scalable deployment patterns (Docker-friendly).
  • Logging, metrics endpoints, and health checks for production use.
  • Example clients and request snippets for curl and Python.

Installation / Configuration

Recommended: run with Docker.

Pull and run a container (example image name; replace if you build locally):

docker pull szeider/mcp-solver:latest
docker run -d --name mcp-solver \
  -p 8080:8080 \
  -v /path/to/config.yml:/app/config.yml:ro \
  szeider/mcp-solver:latest

Run from source (typical steps; adapt to repository build system):

git clone https://github.com/szeider/mcp-solver.git
cd mcp-solver
# If the project uses Maven:
mvn clean package -DskipTests
java -jar target/mcp-solver.jar --config=/path/to/config.yml

Example configuration (YAML):

server:
  port: 8080
logging:
  level: INFO
solvers:
  default:
    backend: cp
    time_limit_seconds: 60
    threads: 4
  ilp:
    backend: ilp
    time_limit_seconds: 120
storage:
  max_models: 1000
auth:
  enabled: false

Environment variables can be used to override settings (e.g., SERVER_PORT, SOLVER_DEFAULT_THREADS). See the repo config schema for all options.

Available Resources

  • GitHub repository: https://github.com/szeider/mcp-solver
  • REST API endpoints (see table below)
  • OpenAPI / Swagger spec included in repo (for client generation)
  • Example clients: Python snippets and curl examples included in the examples/ directory
  • Health/metrics endpoints for observability (e.g., /health, /metrics)

Common endpoints

EndpointMethodDescription
/solvePOSTSubmit a model to solve (sync or async)
/status/{id}GETCheck the status of an async job
/result/{id}GETRetrieve solution/result for a job
/modelsGET/POSTStore or list reusable model templates
/healthGETLiveness / readiness probe

API Example

Submit a small optimization problem (minimize x + y with x != y, domains 1..3):

Request (curl):

curl -X POST http://localhost:8080/solve \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "optimize",
    "solver": "default",
    "model": {
      "variables": {
        "x": {"type":"int","domain":[1,3]},
        "y": {"type":"int","domain":[1,3]}
      },
      "constraints": [
        {"type":"distinct","vars":["x","y"]}
      ],
      "objective": {"sense":"minimize","expression":"x + y"}
    },
    "options": {"time_limit_ms":5000}
  }'

Typical response (sync):

{
  "status": "ok",
  "result": {
    "objective_value": 3,
    "assignments": {"x":1,"y":2},
    "solver_info": {"backend":"cp","time_ms":12}
  }
}

For long-running or batch work, submit with “async”: true and poll /status/{id}.

Use Cases

  • Scheduling: assign tasks to machines while respecting capacity, precedence, and resource constraints. Submit models representing tasks, resources, and cost objectives; use solver time limits and multiple retries.
  • Resource allocation: solve allocation problems (network bandwidth, VM placement) where constraints are combinatorial and objectives are cost, load balance, or SLA violation minimization.
  • Test-case generation / verification: derive input configurations that satisfy or break properties (useful for fuzzing and formal testing).
  • Puzzles and combinatorics: prototype and evaluate puzzles (e.g., Sudoku, Latin squares) using the same API as production workloads.
  • Hybrid pipelines: call the server from CI scripts, web backends, or data-processing jobs to add constraint reasoning without embedding heavy solver libraries.

Getting Started Tips

  • Start by modeling small instances to verify correctness before scaling up time limits or parallelism.
  • Use solver options to control seed, number of threads, and time limits—these dramatically affect reproducibility and performance.
  • Persist frequently used model templates with the /models API to avoid reconstructing models repeatedly.
  • Monitor /metrics and logs to identify bottlenecks and tune solver backend choices.

For full reference, examples, and advanced configuration options, see the repository: https://github.com/szeider/mcp-solver.