Optuna MCP Server for Hyperparameter Optimization
Optimize hyperparameter search using the MCP server to orchestrate Optuna-based tuning and scale optimization tasks seamlessly.
npx -y @optuna/optuna-mcpOverview
The Optuna MCP Server implements a central Model Context Protocol (MCP) endpoint that coordinates Optuna-based hyperparameter optimization. It provides a lightweight service that exposes a consistent HTTP/gRPC API for creating studies, requesting trial suggestions, and reporting trial outcomes. By separating the suggestion/observation logic from worker code, the MCP server simplifies distributed tuning across fleets of trainers, CI pipelines, and managed compute resources.
This server is useful when you need reproducible, scalable hyperparameter search without embedding Optuna’s storage and suggestion logic inside every training process. The MCP server centralizes study state, persists trials in a database, and makes it easier to orchestrate parallel workers, enforce multi-tenancy, and integrate optimization into existing infrastructure.
Features
- Centralized Optuna study management with persistent storage (SQLAlchemy-backed).
- MCP-compatible API (HTTP and/or gRPC) to perform suggest/observe operations.
- Support for distributed workers: a single server can serve suggestions to multiple clients concurrently.
- Configurable backend storage (SQLite, PostgreSQL, MySQL) to scale from local experiments to production.
- CLI and Docker-friendly deployment patterns for rapid local testing and production rollout.
- Basic observability: logging and configurable log level.
- Authentication and multi-tenant study isolation (configurable through environment settings or middleware).
- Extensible: integrates into CI systems, training orchestration, and model-serving workflows.
Installation / Configuration
Install from PyPI (if released) or run from source.
Install (PyPI)
Run from source (development)
# Start the server with an ASGI server (example uses uvicorn)
Docker (example)
# Build a local image
# Run exposing port 8080 and a SQLite file in a mounted directory
Recommended environment configuration
| Variable | Purpose | Example |
|---|---|---|
| OPTUNA_STORAGE_URL | SQLAlchemy connection string used by Optuna to persist studies | sqlite:////data/optuna.db or postgresql://user:pass@db:5432/optuna |
| MCP_HOST | Host to bind the MCP server | 0.0.0.0 |
| MCP_PORT | Port to expose the service | 8080 |
| LOG_LEVEL | Application log verbosity | INFO, DEBUG |
| AUTH_TOKEN | (Optional) Shared token for simple auth between clients and server | supersecret |
Docker Compose snippet
version: "3.7"
services:
optuna-mcp:
image: optuna-mcp:local
ports:
- "8080:8080"
environment:
- OPTUNA_STORAGE_URL=postgresql://optuna:password@db/optuna
- LOG_LEVEL=INFO
depends_on:
- db
db:
image: postgres:14
environment:
- POSTGRES_USER=optuna
- POSTGRES_PASSWORD=password
- POSTGRES_DB=optuna
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
Available Resources
- Repository: https://github.com/optuna/optuna-mcp
- Optuna docs: https://optuna.readthedocs.io
- MCP specification / API docs: check the repository’s API docs or OpenAPI schema for available endpoints
- Examples and integration tests: included in the repository under examples/ or tests/ (see source)
Use Cases
Distributed hyperparameter tuning across GPU workers
- Deploy a single optuna-mcp server connected to a PostgreSQL instance.
- Start many trainer processes (on different machines or Kubernetes pods) that call the MCP server to request parameter suggestions and then report observed metrics back.
- The server serializes trial allocation and maintains a global view of the study, enabling efficient parallel search.
Automated tuning in CI/CD pipelines
- Use the MCP server to run short hyperparameter sweeps for pull requests.
- Each CI job requests a few trials and reports results; the server stores all runs, so teams can compare tunings and reproduce candidate configurations.
Multi-tenant tuning service inside a platform