Fix MCP fn_wrapper handling of Click UNSET defaults (#20953)#20962
Fix MCP fn_wrapper handling of Click UNSET defaults (#20953)#20962TomeHirata merged 3 commits intomlflow:masterfrom
Conversation
🛠 DevTools 🛠
Install mlflow from this PRFor Databricks, use the following command: |
|
@yangbaechu Thank you for the contribution! Could you fix the following issue(s)? ⚠ DCO checkThe DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details. |
59addcd to
b35e062
Compare
tests/mcp/test_server.py
Outdated
| @@ -0,0 +1,20 @@ | |||
| from unittest.mock import Mock | |||
There was a problem hiding this comment.
Can we test in test_mcp?
There was a problem hiding this comment.
Done — moved to test_mcp.py
|
|
||
| def fn_wrapper(command: click.Command) -> Callable[..., str]: | ||
| def wrapper(**kwargs: Any) -> str: | ||
| click_unset = getattr(click.core, "UNSET", object()) |
There was a problem hiding this comment.
Is it intentional to use object() as a default?
There was a problem hiding this comment.
Yes — it's a fallback sentinel for click < 8.3.0 where click.core.UNSET doesn't exist. object() ensures it never matches any param.default via is, so the new skip logic only activates on click >= 8.3.0.
Signed-off-by: Yang Geonhee <abab_1212@naver.com>
Signed-off-by: Yang Geonhee <abab_1212@naver.com>
b35e062 to
238a7ac
Compare
|
I moved test_server into test_mcp and updated DCO sign-off to use my legal name and force-pushed to align the PR branch history. |
|
i'm removing the v3.10 label as the release is happening within the next 30 mins or so. it will be included in the next release which shouldn't be too far away |
mlflow/mcp/server.py
Outdated
| @@ -93,6 +95,8 @@ def wrapper(**kwargs: Any) -> str: | |||
| # Fill in defaults for missing optional arguments | |||
| for param in command.params: | |||
| if param.name not in kwargs: | |||
There was a problem hiding this comment.
Can we combine the if condition?
tests/mcp/test_mcp.py
Outdated
|
|
||
| @pytest.mark.asyncio | ||
| async def test_call_tool_with_optional_params_omitted(client: Client): | ||
| """Regression test for click >= 8.3.0 Sentinel.UNSET handling (#20953).""" |
There was a problem hiding this comment.
Let's remove this docstring
Signed-off-by: Yang Geonhee <abab_1212@naver.com>
…lflow#20962) Signed-off-by: Yang Geonhee <abab_1212@naver.com>
…lflow#20962) Signed-off-by: Yang Geonhee <abab_1212@naver.com>
Related Issues/PRs
Resolve #20953
What changes are proposed in this pull request?
This PR fixes MCP
fn_wrapperhandling for Click 8.3+ by skippingclick.core.UNSETwhen filling missing optional params, so callbacks receive their Python defaults (e.g.,None) instead ofSentinel.UNSET. It also adds a regression test intests/mcp/test_server.pyfor the missing-optional-arg path.How is this PR tested?
Manual reproduce run:
Does this PR require documentation update?
Does this PR require updating the MLflow Skills repository?
Release Notes
Is this a user-facing change?
MLflow MCP no longer passes Click 8.3+ Sentinel.UNSET for missing optional tool arguments, preventing callback crashes such as 'Sentinel' object has no attribute 'split'.
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.