Skip to content

Commit e001fd5

Browse files
committed
minor change
1 parent 5434429 commit e001fd5

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

optuna_mcp/server.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class StudyResponse(BaseModel):
6565
study_name: str
6666
sampler_name: (
6767
typing.Literal["TPESampler", "NSGAIISampler", "RandomSampler", "GPSampler"] | None
68-
) = Field(default=None, description="The name of the sampler used in the study, if available.")
68+
) = Field(default=None, description="The name of the sampler used in the study.")
6969
directions: list[str] | None = Field(
70-
default=None, description="The optimization directions for each objective, if available."
70+
default=None, description="The optimization directions for each objective."
7171
)
7272

7373

@@ -77,13 +77,13 @@ class TrialResponse(BaseModel):
7777
default=None, description="The parameter values suggested by the trial."
7878
)
7979
values: list[float] | None = Field(
80-
default=None, description="The objective values of the trial, if available."
80+
default=None, description="The objective values of the trial."
8181
)
8282
user_attrs: dict[str, typing.Any] | None = Field(
83-
default=None, description="User-defined attributes for the trial, if any."
83+
default=None, description="User-defined attributes for the trial."
8484
)
8585
system_attrs: dict[str, typing.Any] | None = Field(
86-
default=None, description="System-defined attributes for the trial, if any."
86+
default=None, description="System-defined attributes for the trial."
8787
)
8888

8989

@@ -214,7 +214,6 @@ def get_trial_user_attrs(trial_number: int) -> TrialResponse:
214214
mcp.study._study_id, trial_number
215215
)
216216
trial = storage.get_trial(trial_id)
217-
# return f"User attributes in trial {trial_number}: {json.dumps(trial.user_attrs)}"
218217
return TrialResponse(
219218
trial_number=trial_number,
220219
user_attrs=trial.user_attrs,
@@ -599,6 +598,3 @@ def main() -> None:
599598

600599
if __name__ == "__main__":
601600
main()
602-
603-
mcp = OptunaMCP("Optuna")
604-
mcp = register_tools(mcp)

tests/test_server.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ async def test_get_all_study_names(mcp: OptunaMCP) -> None:
9696
assert isinstance(result[1], dict)
9797
assert result[1]["result"] == "No storage specified."
9898
else:
99-
assert all(isinstance(result, StudyResponse) for result in result[0])
10099
assert result[0] == []
101100
assert isinstance(result[1], dict)
102101
assert result[1]["result"] == []
@@ -159,7 +158,7 @@ async def test_set_sampler(mcp: OptunaMCP, sampler_name: str) -> None:
159158
assert len(result) == 2
160159
assert isinstance(result[0][0], TextContent)
161160
assert isinstance(StudyResponse(**result[1]), StudyResponse)
162-
assert all(sampler_name == json.loads(result.text)["sampler_name"] for result in result[0])
161+
assert sampler_name == json.loads(result[0][0].text)["sampler_name"]
163162
assert sampler_name == result[1]["sampler_name"]
164163
assert isinstance(mcp.study.sampler, getattr(optuna.samplers, sampler_name))
165164

@@ -251,7 +250,6 @@ async def test_get_trials(mcp: OptunaMCP) -> None:
251250
assert len(result) == 2
252251
assert isinstance(result[0][0], TextContent)
253252
assert isinstance(result[1], dict)
254-
# assert isinstance(result[0], TextContent)
255253
lines_from_text = result[0][0].text.strip().split("\n")
256254
lines_from_dict = result[1]["result"].strip().split("\n")
257255

@@ -290,9 +288,7 @@ async def test_best_trials(mcp: OptunaMCP) -> None:
290288
assert isinstance(result, Sequence)
291289
assert len(result) == 2
292290
assert isinstance(result[0][0], TextContent)
293-
assert all(
294-
isinstance(TrialResponse(**result), TrialResponse) for result in result[1]["result"]
295-
)
291+
assert isinstance(TrialResponse(**result[1]["result"][0]), TrialResponse)
296292

297293

298294
@pytest.mark.anyio

0 commit comments

Comments
 (0)