best_trials
Identify optimal trials at the Pareto front in Optuna studies for efficient hyperparameter optimization and result analysis through the MCP server.
Instructions
Return trials located at the Pareto front in the study.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- optuna_mcp/server.py:351-371 (handler)The handler function for the 'best_trials' tool. It returns the best trials (Pareto front) from the Optuna study as a list of TrialResponse objects. Registered via @mcp.tool decorator.@mcp.tool(structured_output=True) def best_trials() -> list[TrialResponse]: """Return trials located at the Pareto front in the study.""" if mcp.study is None: raise McpError( ErrorData( code=INTERNAL_ERROR, message="No study has been created. Please create a study first.", ) ) return [ TrialResponse( trial_number=trial.number, params=trial.params, values=trial.values, user_attrs=trial.user_attrs, system_attrs=trial.system_attrs, ) for trial in mcp.study.best_trials ]
- optuna_mcp/server.py:84-98 (schema)Pydantic BaseModel defining the output schema for individual trials returned by the best_trials tool.class TrialResponse(BaseModel): trial_number: int params: dict[str, typing.Any] | None = Field( default=None, description="The parameter values suggested by the trial." ) values: list[float] | None = Field( default=None, description="The objective values of the trial." ) user_attrs: dict[str, typing.Any] | None = Field( default=None, description="User-defined attributes for the trial." ) system_attrs: dict[str, typing.Any] | None = Field( default=None, description="System-defined attributes for the trial." )
- optuna_mcp/server.py:686-686 (registration)The register_tools function is called here, which defines and registers all tools including best_trials via decorators.mcp = register_tools(mcp)