A Model Context Protocol (MCP) server that automates optimization and analysis using Optuna. The Optuna MCP Server can be used in the following use cases, for example. - Automated hyperparameter optimization by LLMs - Interactive analysis of Optuna's optimization results via chat interface - Optimize input and output of other MCP tools For details, see the Examples section. The Optuna MCP server c
Add this skill
npx mdskills install optuna/optuna-mcpComprehensive optimization server with rich visualization tools and excellent documentation
1# Optuna MCP Server23[](https://www.python.org)4[](https://pypi.python.org/pypi/optuna-mcp)5[](https://github.com/optuna/optuna-mcp)6[](https://github.com/optuna/optuna-mcp/actions/workflows/tests.yml)78A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) server that automates optimization and analysis using [Optuna](http://optuna.org).910<img width="840" alt="image" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-6.png" />1112## Use Cases1314The Optuna MCP Server can be used in the following use cases, for example.1516- Automated hyperparameter optimization by LLMs17- Interactive analysis of Optuna's optimization results via chat interface18- Optimize input and output of other MCP tools1920For details, see the [Examples section](#examples).2122## Installation2324The Optuna MCP server can be installed using `uv` or Docker.25This section explains how to install the Optuna MCP server, using Claude Desktop as an example MCP client.2627### Usage with uv2829Before starting the installation process, install `uv` from [Astral](https://docs.astral.sh/uv/getting-started/installation/).3031Then, add the Optuna MCP server configuration to the MCP client.32To include it in Claude Desktop, go to Claude > Settings > Developer > Edit Config > `claude_desktop_config.json`33and add the following:3435```json36{37 "mcpServers": {38 "Optuna": {39 "command": "/path/to/uvx",40 "args": [41 "optuna-mcp"42 ]43 }44 }45}46```4748Additionally, you can specify the Optuna storage with the `--storage` argument to persist the results.4950```json51{52 "mcpServers": {53 "Optuna": {54 "command": "/path/to/uvx",55 "args": [56 "optuna-mcp",57 "--storage",58 "sqlite:///optuna.db"59 ]60 }61 }62}63```6465After adding this, please restart Claude Desktop application.66For more information about Claude Desktop, check out [the quickstart page](https://modelcontextprotocol.io/quickstart/user).6768### Usage with Docker6970You can also run the Optuna MCP server using Docker. Make sure you have Docker installed and running on your machine.7172```json73{74 "mcpServers": {75 "Optuna": {76 "command": "docker",77 "args": [78 "run",79 "-i",80 "--rm",81 "--net=host",82 "-v",83 "/PATH/TO/LOCAL/DIRECTORY/WHICH/INCLUDES/DB/FILE:/app/workspace",84 "optuna/optuna-mcp:latest",85 "--storage",86 "sqlite:////app/workspace/optuna.db"87 ]88 }89 }90}91```9293## Tools provided by Optuna MCP9495The Optuna MCP provides the following tools.96Specifically, it offers primitive functions of Optuna such as Study, Trial, Visualization, and Dashboard.97Since MCP clients know the list of tools and the details of each tool, users do not need to remember those details.9899### Study100101- **create_study** - Create a new Optuna study with the given study_name and directions.102 If the study already exists, it will be simply loaded.103 - `study_name` : name of the study (string, required).104 - `directions`: The directions of optimization (list of literal strings minimize/maximize, optional).105- **set_sampler** - Set the sampler for the study.106 - `name` : the name of the sampler (string, required).107- **get_all_study_names** - Get all study names from the storage.108- **set_metric_names** - Set metric_names. Metric_names are labels used to distinguish what each objective value is.109 - `metric_names` : The list of metric names for each objective (list of strings, required).110- **get_metric_names** - Get metric_names.111 - No parameters required.112- **get_directions** - Get the directions of the study.113 - No parameters required.114- **get_trials** - Get all trials in a CSV format.115 - No parameters required.116- **best_trial** - Get the best trial.117 - No parameters required.118- **best_trials** - Return trials located at the Pareto front in the study.119 - No parameters required.120121### Trial122123- **ask** - Suggest new parameters using Optuna.124 - `search_space` : the search space for Optuna (dictionary, required).125- **tell** - Report the result of a trial.126 - `trial_number` : the trial number (integer, required).127 - `values` : the result of the trial (float or list of floats, required).128- **set_trial_user_attr** - Set user attributes for a trial.129 - `trial_number`: the trial number (integer, required).130 - `key`: the key of the user attribute (string, required).131 - `value`: the value of the user attribute (any type, required).132- **get_trial_user_attrs** - Get user attributes in a trial.133 - `trial_number`: the trial number (integer, required).134135### Visualization136137- **plot_optimization_history** - Return the optimization history plot as an image.138 - `target`: index to specify which value to display (integer, optional).139 - `target_name`: target’s name to display on the axis label (string, optional).140- **plot_hypervolume_history** - Return the hypervolume history plot as an image.141 - `reference_point` : a list of reference points to calculate the hypervolume (list of floats, required).142- **plot_pareto_front** - Return the Pareto front plot as an image for multi-objective optimization.143 - `target_names`: objective name list used as the axis titles (list of strings, optional).144 - `include_dominated_trials`: a flag to include all dominated trial's objective values (boolean, optional).145 - `targets`: a list of indices to specify the objective values to display. (list of integers, optional).146- **plot_contour** - Return the contour plot as an image.147 - `params` : parameter list to visualize (list of strings, optional).148 - `target` : an index to specify the value to display (integer, required).149 - `target_name` : target’s name to display on the color bar (string, required).150- **plot_parallel_coordinate** - Return the parallel coordinate plot as an image.151 - `params` : parameter list to visualize (list of strings, optional).152 - `target` : an index to specify the value to display (integer, required).153 - `target_name` : target’s name to display on the axis label and the legend (string, required).154- **plot_slice** - Return the slice plot as an image.155 - `params` : parameter list to visualize (list of strings, optional).156 - `target` : an index to specify the value to display (integer, required).157 - `target_name` : target’s name to display on the axis label (string, required).158- **plot_param_importances** - Return the parameter importances plot as an image.159 - `params` : parameter list to visualize (list of strings, optional).160 - `target` : an index to specify the value to display (integer/null, optional).161 - `target_name` : target’s name to display on the legend (string, required).162- **plot_edf** - Return the EDF plot as an image.163 - `target` : an index to specify the value to display (integer, required).164 - `target_name` : target’s name to display on the axis label (string, required).165- **plot_timeline** - Return the timeline plot as an image.166 - No parameters required.167- **plot_rank** - Return the rank plot as an image.168 - `params` : parameter list to visualize (list of strings, optional).169 - `target` : an index to specify the value to display (integer, required).170 - `target_name` : target’s name to display on the color bar (string, required).171172### Web Dashboard173174- **launch_optuna_dashboard** - Launch the Optuna dashboard.175 - `port`: server port (integer, optional, default: 58080).176177## Examples178179- [Optimizing the 2D-Sphere function](#optimizing-the-2d-sphere-function)180- [Starting the Optuna dashboard and analyzing optimization results](#starting-the-optuna-dashboard-and-analyzing-optimization-results)181- [Optimizing the FFmpeg encoding parameters](#optimizing-the-ffmpeg-encoding-parameters)182- [Optimizing the Cookie Recipe](#optimizing-the-cookie-recipe)183- [Optimizing the Matplotlib Configuration](#optimizing-the-matplotlib-configuration)184185### Optimizing the 2D-Sphere Function186187Here we present a simple example of optimizing the 2D-Sphere function, along with example prompts and the summary of the LLM responses.188189| User prompt | Output in Claude |190| - | - |191| (Launch Claude Desktop) | <img alt="1" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-1.png" /> |192| Please create an Optuna study named "Optimize-2D-Sphere" for minimization. | <img alt="2" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-2.png" /> |193| Please suggest two float parameters x, y in [-1, 1]. | <img alt="3" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-3.png" /> |194| Please report the objective value x\*\*2 + y\*\*2. To calculate the value, please use the JavaScript interpreter and do not round the values. | <img alt="4" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-4.png" /> |195| Please suggest another parameter set and evaluate it. | <img alt="5" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-5.png" /> |196| Please plot the optimization history so far. | <img alt="6" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/sphere2d/images/sphere2d-6.png" /> |197198### Starting the Optuna Dashboard and Analyzing Optimization Results199200You can also start the [Optuna dashboard](https://github.com/optuna/optuna-dashboard) via the MCP server to analyze the optimization results interactively.201202| User prompt | Output in Claude |203| - | - |204| Please launch the Optuna dashboard. | <img alt="7" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/optuna-dashboard/images/optuna-dashboard-1.png" /> |205206By default, the Optuna dashboard will be launched on port 58080.207You can access it by navigating to `http://localhost:58080` in your web browser as shown below:208<img alt="8" src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/optuna-dashboard/images/optuna-dashboard-2.png" />209210Optuna dashboard provides various visualizations to analyze the optimization results, such as optimization history, parameter importances, and more.211212### Optimizing the FFmpeg Encoding Parameters213214215216This demo showcases how to use the Optuna MCP server to automatically find optimal FFmpeg encoding parameters. It optimizes x264 encoding options to maximize video quality (measured by the SSIM score) while keeping encoding time reasonable.217218Check out [examples/ffmpeg](https://github.com/optuna/optuna-mcp/tree/main/examples/ffmpeg/README.md) for details.219220### Optimizing the Cookie Recipe221222223224In this example, we will optimize a cookie recipe, referencing the paper titled "[Bayesian Optimization for a Better Dessert](https://research.google/pubs/bayesian-optimization-for-a-better-dessert/)".225226Check out [examples/cookie-recipe](https://github.com/optuna/optuna-mcp/tree/main/examples/cookie-recipe/README.md) for details.227228### Optimizing the Matplotlib Configuration229230<table>231 <caption>Default and optimized figures by Optuna MCP.</caption>232 <tr>233 <td><img src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/auto-matplotlib/images/first-plot.png" alt=""></td>234 <td><img src="https://raw.githubusercontent.com/optuna/optuna-mcp/main/examples/auto-matplotlib/images/best-plot.png" alt=""></td>235 </tr>236</table>237238This example optimizes a Matplotlib configuration.239240Check out [examples/auto-matplotlib](https://github.com/optuna/optuna-mcp/tree/main/examples/auto-matplotlib/README.md) for details.241242## License243244MIT License (see [LICENSE](./LICENSE)).245246
Full transparency — inspect the skill content before installing.