Repository navigation
Conversation
_parse_file_path split on the last colon, so entry.py:pkg_srv:app became file entry.py:pkg_srv and failed with File not found, making the module:object branch of _import_server unreachable from the CLI. Split on the first colon after the file path whose left side is an existing file, falling back to the last-colon split so missing files report the same path as before. Fixes modelcontextprotocol#3966
2 tasks done
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/cli/test_utils.py">
<violation number="1" location="tests/cli/test_utils.py:40">
P2: This test fails on Windows because `:` is not allowed in a directory name, so `file.parent.mkdir()` raises before `_parse_file_path()` runs. Skip this platform-specific case on Windows.</violation>
</file>
<file name="src/mcp/cli/cli.py">
<violation number="1" location="src/mcp/cli/cli.py:105">
P2: An existing colon-containing file passed without an object suffix is still split as object syntax and rejected as missing. Check whether the complete `file_spec` is a file before interpreting its colons.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
|
|
||
| def test_parse_file_path_with_colon_in_directory(tmp_path: Path): | ||
| """Should split after the file path when a directory name contains a colon.""" | ||
| file = tmp_path / "we:ird" / "server.py" |
There was a problem hiding this comment.
P2: This test fails on Windows because : is not allowed in a directory name, so file.parent.mkdir() raises before _parse_file_path() runs. Skip this platform-specific case on Windows.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/cli/test_utils.py, line 40:
<comment>This test fails on Windows because `:` is not allowed in a directory name, so `file.parent.mkdir()` raises before `_parse_file_path()` runs. Skip this platform-specific case on Windows.</comment>
<file context>
@@ -34,6 +35,22 @@ def test_parse_file_path_accepts_valid_specs(tmp_path: Path, spec: str, expected
+def test_parse_file_path_with_colon_in_directory(tmp_path: Path):
+ """Should split after the file path when a directory name contains a colon."""
+ file = tmp_path / "we:ird" / "server.py"
+ file.parent.mkdir()
+ file.write_text("x = 1", encoding="utf-8")
</file context>
Comment on lines
+105
to
+117
| file_str, server_object = file_spec, None | ||
| colon = file_spec.find(":", search_from) | ||
| while colon != -1: | ||
| candidate = file_spec[:colon] | ||
| if Path(candidate).expanduser().is_file(): | ||
| file_str, server_object = candidate, file_spec[colon + 1 :] | ||
| break | ||
| colon = file_spec.find(":", colon + 1) | ||
| else: | ||
| file_str, server_object = file_spec, None | ||
| # No split left an existing file; fall back to the last-colon split so | ||
| # a missing file reports the same path as before. | ||
| if ":" in file_spec[search_from:]: | ||
| file_str, server_object = file_spec.rsplit(":", 1) |
There was a problem hiding this comment.
P2: An existing colon-containing file passed without an object suffix is still split as object syntax and rejected as missing. Check whether the complete file_spec is a file before interpreting its colons.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/mcp/cli/cli.py, line 105:
<comment>An existing colon-containing file passed without an object suffix is still split as object syntax and rejected as missing. Check whether the complete `file_spec` is a file before interpreting its colons.</comment>
<file context>
@@ -89,20 +89,32 @@ def _parse_file_path(file_spec: str) -> tuple[Path, str | None]:
+ # can also appear inside the file path, so take the first split whose left
+ # side is an existing file.
+ search_from = 2 if has_windows_drive else 0
+ file_str, server_object = file_spec, None
+ colon = file_spec.find(":", search_from)
+ while colon != -1:
</file context>
Suggested change
| file_str, server_object = file_spec, None | |
| colon = file_spec.find(":", search_from) | |
| while colon != -1: | |
| candidate = file_spec[:colon] | |
| if Path(candidate).expanduser().is_file(): | |
| file_str, server_object = candidate, file_spec[colon + 1 :] | |
| break | |
| colon = file_spec.find(":", colon + 1) | |
| else: | |
| file_str, server_object = file_spec, None | |
| # No split left an existing file; fall back to the last-colon split so | |
| # a missing file reports the same path as before. | |
| if ":" in file_spec[search_from:]: | |
| file_str, server_object = file_spec.rsplit(":", 1) | |
| if Path(file_spec).expanduser().is_file(): | |
| file_str, server_object = file_spec, None | |
| else: | |
| file_str, server_object = file_spec, None | |
| colon = file_spec.find(":", search_from) | |
| while colon != -1: | |
| candidate = file_spec[:colon] | |
| if Path(candidate).expanduser().is_file(): | |
| file_str, server_object = candidate, file_spec[colon + 1 :] | |
| break | |
| colon = file_spec.find(":", colon + 1) | |
| else: | |
| # No split left an existing file; fall back to the last-colon split so | |
| # a missing file reports the same path as before. | |
| if ":" in file_spec[search_from:]: | |
| file_str, server_object = file_spec.rsplit(":", 1) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3966.
_parse_file_path()split the file spec on the last colon, soentry.py:pkg_srv:appbecame fileentry.py:pkg_srvand failed withFile not found— making themodule:objectbranch of_import_server()unreachable from the CLI (mcp dev/run/install).This splits on the first colon after the file path whose left side is an existing file, so the server object may itself contain a colon. A colon can also appear inside the file path, so each candidate split is checked for an existing file; when no split leaves an existing file it falls back to the last-colon split, so a genuinely missing file reports the same path as before.
Tests: added a
entry.py:pkg_srv:appcase totest_parse_file_path_accepts_valid_specs, plus a colon-in-directory case and a missing-file-with-module:objectcase.tests/cli/test_utils.py: 13 passed;src/mcp/cli/cli.pycoverage 100%,ruffandpyrightclean.