Repository navigation
Fix _parse_file_path splitting module:object server specs - #3981
Open
sashaosman wants to merge 1 commit into
Open
sashaosman wants to merge 1 commit into
sashaosman wants to merge 1 commit into
Conversation
_parse_file_path split the file spec on the last colon, so a spec like entry.py:pkg_srv:app was cut into a nonexistent file path and the CLI exited with "File not found". That made the module:object branch in _import_server unreachable from the dev, run, and install commands. Split on the first colon after the file path instead (still skipping a Windows drive letter), so the remainder can carry module:object. Fixes modelcontextprotocol#3966
There was a problem hiding this comment.
1 issue 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="src/mcp/cli/cli.py">
<violation number="1" location="src/mcp/cli/cli.py:106">
P2: This treats the first colon in the argument as the separator, so a valid POSIX spec such as `/tmp/foo:bar.py:app` is parsed as file `/tmp/foo` and object `bar.py:app`. Select the separator based on an existing file prefix or use an unambiguous syntax so colon-containing filenames remain usable.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
| # into the object spec and leave a file path that does not exist. | ||
| rest = file_spec[2:] if has_windows_drive else file_spec | ||
| if ":" in rest: | ||
| split_at = rest.index(":") + (2 if has_windows_drive else 0) |
There was a problem hiding this comment.
P2: This treats the first colon in the argument as the separator, so a valid POSIX spec such as /tmp/foo:bar.py:app is parsed as file /tmp/foo and object bar.py:app. Select the separator based on an existing file prefix or use an unambiguous syntax so colon-containing filenames remain usable.
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 106:
<comment>This treats the first colon in the argument as the separator, so a valid POSIX spec such as `/tmp/foo:bar.py:app` is parsed as file `/tmp/foo` and object `bar.py:app`. Select the separator based on an existing file prefix or use an unambiguous syntax so colon-containing filenames remain usable.</comment>
<file context>
@@ -97,10 +97,14 @@ def _parse_file_path(file_spec: str) -> tuple[Path, str | None]:
+ # into the object spec and leave a file path that does not exist.
+ rest = file_spec[2:] if has_windows_drive else file_spec
+ if ":" in rest:
+ split_at = rest.index(":") + (2 if has_windows_drive else 0)
+ file_str, server_object = file_spec[:split_at], file_spec[split_at + 1 :]
else:
</file context>
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 withrsplit(":", 1), somcp run entry.py:pkg_srv:appwas cut into a file path ofentry.py:pkg_srvand the CLI exited with "File not found". Themodule:objecthandling in_import_server()could never be reached from thedev,run, orinstallcommands.This splits on the first colon after the file path instead (still skipping a Windows drive letter), so the rest of the spec can carry
module:objectthrough to_import_server().Tested: added a
foo.py:pkg.mod:srv_objcase to the existing parametrized test intests/cli/test_utils.py, and verified the patched function against the plain path,file:object,file:module:object, missing file, and directory cases locally (the old code exits on themodule:objectspec, the patched code parses it). Happy to adjust the approach if maintainers would rather resolve the path differently.