set_trial_user_attr
Assign user-defined attributes to specific trials for tracking custom metadata during hyperparameter optimization in Optuna MCP Server.
Instructions
Set user attributes for a trial
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | ||
| trial_number | Yes | ||
| value | Yes |
Implementation Reference
- optuna_mcp/server.py:220-237 (handler)The main handler function for the 'set_trial_user_attr' tool. It retrieves the trial ID from the study's storage and calls storage.set_trial_user_attr to set the user attribute for the specified trial.@mcp.tool(structured_output=True) def set_trial_user_attr(trial_number: int, key: str, value: typing.Any) -> str: """Set user attributes for a trial""" if mcp.study is None: raise McpError( ErrorData( code=INTERNAL_ERROR, message="No study has been created. Please create a study first.", ) ) storage = mcp.study._storage trial_id = storage.get_trial_id_from_study_id_trial_number( mcp.study._study_id, trial_number ) storage.set_trial_user_attr(trial_id, key, value) return f"User attribute {key} set to {json.dumps(value)} for trial {trial_number}"