Fix MCP fn_wrapper to pass None for optional params with UNSET defaults#21051
Fix MCP fn_wrapper to pass None for optional params with UNSET defaults#21051daniellok-db merged 2 commits intomlflow:masterfrom
Conversation
Signed-off-by: Yang Geonhee <abab_1212@naver.com>
🛠 DevTools 🛠
Install mlflow from this PRFor Databricks, use the following command: |
| kwargs[param.name] = param.default | ||
| if param.name not in kwargs: | ||
| if param.default is click_unset: | ||
| kwargs[param.name] = None |
There was a problem hiding this comment.
what's the difference here? previously would kwargs simply not contain param.name? what error does that cause?
There was a problem hiding this comment.
could you include a test case that demonstrates where it was failing before?
There was a problem hiding this comment.
Yes — kwargs simply didn't contain the param, so command.callback(**kwargs) raises e.g. TypeError: get_experiment() missing 1 required positional argument: 'experiment_name'.
Signed-off-by: Yang Geonhee <abab_1212@naver.com>
|
Added a unit test that simulates |
| kwargs[param.name] = param.default | ||
| if param.name not in kwargs: | ||
| if param.default is click_unset: | ||
| kwargs[param.name] = None |
There was a problem hiding this comment.
could you include a test case that demonstrates where it was failing before?
|
Documentation preview for 366ada2 is available at: More info
|
…ts (mlflow#21051) Signed-off-by: Yang Geonhee <abab_1212@naver.com>
…ts (mlflow#21051) Signed-off-by: Yang Geonhee <abab_1212@naver.com>
…ts (#21051) Signed-off-by: Yang Geonhee <abab_1212@naver.com>
Related Issues/PRs
Resolve #21050
What changes are proposed in this pull request?
This PR fixes
mlflow/mcp/server.py:fn_wrapperto handle Click 8.3.0+click.core.Sentinel.UNSETdefaults without breaking callback invocation.When a parameter is missing from
kwargs:param.default is Sentinel.UNSET, this PR setskwargs[param.name] = None.kwargs[param.name] = param.default(existing behavior).This avoids passing
UNSETinto callbacks while ensuring omitted optional params are still present forcommand.callback(**kwargs).How is this PR tested?
Verified on Click 8.3.1.
Python-level
TypeError: get_experiment() missing 1 required positional argument: 'experiment_name'End-to-end MCP tool calls
get_experimentsucceeds when exactly one ofexperiment_id/experiment_nameis provided, and fails with the expected Click validation error when both/neither are provided.search_traces,list_scorers, andcreate_runbehave as expected with optional params omitted / flags set / defaults applied.Does this PR require documentation update?
Does this PR require updating the MLflow Skills repository?
Release Notes
Is this a user-facing change?
Fixes MCP tool invocation on Click 8.3.0+ when optional parameters are omitted by treating
Sentinel.UNSETdefaults asNoneinfn_wrapper.What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityHow should the PR be classified in the release notes? Choose one:
rn/bug-fix- A user-facing bug fix worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.