Skip to content

fix(cli): parse module:object server specs in _parse_file_path - #3969

Open
mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/3966-parse-file-path
Open

mia03ther wants to merge 2 commits into
modelcontextprotocol:mainfrom
mia03ther:fix/3966-parse-file-path

Conversation

@mia03ther

Copy link
Copy Markdown

Fixes #3966.

_parse_file_path() split the file spec 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 (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:app case to test_parse_file_path_accepts_valid_specs, plus a colon-in-directory case and a missing-file-with-module:object case. tests/cli/test_utils.py: 13 passed; src/mcp/cli/cli.py coverage 100%, ruff and pyright clean.

_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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Comment thread tests/cli/test_utils.py Resolved
Comment thread src/mcp/cli/cli.py Resolved
…path

If the whole file spec is an existing file, take it as-is instead of
splitting on its colons: a colon can be part of the file path itself.
Also skip the colon-in-directory tests on Windows, where ':' is not
allowed in directory names.
@japan-opendata-lab

Copy link
Copy Markdown

Verified the fix at head 3bcf6c5 against the cases from #3966. One note on method: the dev version at this head could not be pip-installed in my sandbox (it pins a dev build of mcp-types that is not on PyPI), so I executed _parse_file_path taken verbatim from the PR head rather than from an installed package.

Results (Python 3.12.3, Linux x86_64):

  • entry.py → (entry.py, None)
  • entry.py:app → (entry.py, 'app')
  • entry.py:pkg_srv:app → (entry.py, 'pkg_srv:app') — the case that previously exited with "File not found"
  • Colon-in-directory cases also behave as the new tests expect: we:ird/server.py:app → (we:ird/server.py, 'app'), and we:ird/server.py with no suffix → (path, None)
  • A missing file with missing.py:mod:obj still raises SystemExit(1), and the logged path is missing.py:mod — the same last-colon fallback as before this PR.

So the module:object spec now survives parsing intact for _import_server() to consume.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI _parse_file_path() splits with rsplit(":", 1), making _import_server()'s "module:object" syntax unreachable

2 participants