@@ -43,6 +43,7 @@ def test_mcp_requirement_leaves_dev_versions_unpinned(monkeypatch: pytest.Monkey
4343 """Dev versions are not published to PyPI, so the requirement falls back to the unpinned package."""
4444 _set_mcp_version (monkeypatch , "2.0.0a2.dev3" )
4545 assert mcp_requirement () == "mcp"
46+ assert mcp_requirement ("mcp[cli]" ) == "mcp[cli]"
4647
4748
4849def test_mcp_requirement_leaves_local_versions_unpinned (monkeypatch : pytest .MonkeyPatch ):
@@ -51,6 +52,17 @@ def test_mcp_requirement_leaves_local_versions_unpinned(monkeypatch: pytest.Monk
5152 assert mcp_requirement () == "mcp"
5253
5354
55+ def test_mcp_requirement_falls_back_when_mcp_is_not_installed (monkeypatch : pytest .MonkeyPatch ):
56+ """Without distribution metadata there is no version to pin, so the requirement stays unpinned."""
57+
58+ def raise_not_found (distribution_name : str ) -> str :
59+ raise importlib .metadata .PackageNotFoundError (distribution_name )
60+
61+ monkeypatch .setattr (importlib .metadata , "version" , raise_not_found )
62+ assert mcp_requirement () == "mcp"
63+ assert mcp_requirement ("mcp[cli]" ) == "mcp[cli]"
64+
65+
5466def _read_server (config_dir : Path , name : str ) -> dict [str , Any ]:
5567 config = json .loads ((config_dir / "claude_desktop_config.json" ).read_text ())
5668 return config ["mcpServers" ][name ]
@@ -75,13 +87,21 @@ def test_file_spec_without_object_suffix(config_dir: Path):
7587
7688
7789def test_with_packages_sorted_and_deduplicated (config_dir : Path ):
78- """Extra packages should appear as --with flags, sorted and deduplicated with mcp[cli] ."""
90+ """Extra packages should appear as sorted --with flags with duplicates removed ."""
7991 assert update_claude_config (file_spec = "s.py:app" , server_name = "s" , with_packages = ["zebra" , "aardvark" , "zebra" ])
8092
8193 args = _read_server (config_dir , "s" )["args" ]
8294 assert args [:8 ] == ["run" , "--frozen" , "--with" , "aardvark" , "--with" , "mcp[cli]==1.2.3" , "--with" , "zebra" ]
8395
8496
97+ def test_explicit_mcp_cli_kept_alongside_pinned_requirement (config_dir : Path ):
98+ """A user-supplied mcp[cli] no longer collapses into the pinned requirement; uv resolves both to the pin."""
99+ assert update_claude_config (file_spec = "s.py:app" , server_name = "s" , with_packages = ["mcp[cli]" ])
100+
101+ args = _read_server (config_dir , "s" )["args" ]
102+ assert args [:6 ] == ["run" , "--frozen" , "--with" , "mcp[cli]" , "--with" , "mcp[cli]==1.2.3" ]
103+
104+
85105def test_with_editable_adds_flag (config_dir : Path , tmp_path : Path ):
86106 """with_editable should add --with-editable after the --with flags."""
87107 editable = tmp_path / "project"
0 commit comments