Skip to content

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

Backlog

Description

@saryeljaramany

Initial Checks

Release line

2.x (current stable)

Description

In src/mcp/cli/cli.py, _import_server() documents and implements "module:object" syntax for server_object (lines 124 and 180-191):

  • Docstring: server_object: Optional object name in format "module:object" or just "object"
  • Branch: if ":" in server_object: module_name, object_name = server_object.split(":", 1)

However, all CLI entrypoints (dev at line 246, run at line 328, and install at line 418) first pass file_spec to _parse_file_path() (cli.py:88-116), which splits on the last colon:

if ":" in (file_spec[2:] if has_windows_drive else file_spec):
    file_str, server_object = file_spec.rsplit(":", 1)

Because rsplit(":", 1) only strips the final :object segment, passing entry.py:pkg_srv:app splits into file_str="entry.py:pkg_srv" and server_object="app", then fails file_path.exists() and exits with File not found (SystemExit(1)). As a result, _import_server()'s "module:object" branch is unreachable from the CLI.

(Expected behavior: either split on the first non-drive colon after the file path so server_object can contain module:object, or update _import_server() / CLI help if "module:object" is no longer intended to be supported.)

(AI assistance disclosure: AI tools were used to assist in local reproduction and analysis; I have verified the behavior and reproduction output locally.)

Example Code

import tempfile
from pathlib import Path
from mcp.cli.cli import _parse_file_path

with tempfile.TemporaryDirectory() as tmp:
    tmp_path = Path(tmp)
    (tmp_path / "entry.py").write_text("x = 1\n", encoding="utf-8")
    (tmp_path / "pkg_srv.py").write_text(
        "from mcp.server.mcpserver import MCPServer\napp = MCPServer('demo')\n",
        encoding="utf-8",
    )

    # Works:
    print(_parse_file_path(f"{tmp_path / 'entry.py'}:app"))

    # Fails with: File not found: ...\entry.py:pkg_srv -> SystemExit(1)
    _parse_file_path(f"{tmp_path / 'entry.py'}:pkg_srv:app")

Python & MCP Python SDK

Python 3.14.3, Windows 11 (Windows-11-10.0.26300-SP0), mcp main (0.0.1.dev1+77001c9)

Activity

  1. japan-opendata-lab commented on Dec 3, 2026

    @japan-opendata-lab

    Reproduced on the released mcp 2.3.0 package (Python 3.12.3, Linux x86_64) — the _parse_file_path code there is identical to the version on main quoted above:

    • entry.py → (entry.py, None)
    • entry.py:app → (entry.py, 'app')
    • entry.py:pkg_srv:app → logs File not found: .../entry.py:pkg_srv and raises SystemExit(1), exactly as reported.

    One extra check that may help pin down where the fix belongs: calling _import_server(entry_path, "pkg_srv:app") directly, bypassing _parse_file_path, works fine — it imports pkg_srv and returns the MCPServer('demo') instance. So the module:object branch itself is functional; only the CLI parsing step makes it unreachable.

  2. mia03ther commented on Dec 3, 2026

    @mia03ther

    I'd like to take this on — could you assign #3966 to me? I'll put up a PR fixing _parse_file_path() so the module:object syntax reaches _import_server().

  3. mia03ther commented on Dec 3, 2026

    @mia03ther

    PR opened: #3969 — fixes _parse_file_path() so entry.py:pkg_srv:app parses as file entry.py + server object pkg_srv:app.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions