MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / dev

Function dev

src/mcp/cli/cli.py:221–300  ·  view source on GitHub ↗

Run an MCP server with the MCP Inspector.

(
    file_spec: str = typer.Argument(
        ...,
        help="Python file to run, optionally with :object suffix",
    ),
    with_editable: Annotated[
        Path | None,
        typer.Option(
            "--with-editable",
            "-e",
            help="Directory containing pyproject.toml to install in editable mode",
            exists=True,
            file_okay=False,
            resolve_path=True,
        ),
    ] = None,
    with_packages: Annotated[
        list[str],
        typer.Option(
            "--with",
            help="Additional packages to install",
        ),
    ] = [],
)

Source from the content-addressed store, hash-verified

219
220@app.command()
221def dev(
222 file_spec: str = typer.Argument(
223 ...,
224 help="Python file to run, optionally with :object suffix",
225 ),
226 with_editable: Annotated[
227 Path | None,
228 typer.Option(
229 "--with-editable",
230 "-e",
231 help="Directory containing pyproject.toml to install in editable mode",
232 exists=True,
233 file_okay=False,
234 resolve_path=True,
235 ),
236 ] = None,
237 with_packages: Annotated[
238 list[str],
239 typer.Option(
240 "--with",
241 help="Additional packages to install",
242 ),
243 ] = [],
244) -> None: # pragma: no cover
245 """Run an MCP server with the MCP Inspector."""
246 file, server_object = _parse_file_path(file_spec)
247
248 logger.debug(
249 "Starting dev server",
250 extra={
251 "file": str(file),
252 "server_object": server_object,
253 "with_editable": str(with_editable) if with_editable else None,
254 "with_packages": with_packages,
255 },
256 )
257
258 try:
259 # Import server to get dependencies
260 server = _import_server(file, server_object)
261 if hasattr(server, "dependencies"):
262 with_packages = list(set(with_packages + server.dependencies))
263
264 uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)
265
266 # Get the correct npx command
267 npx_cmd = _get_npx_command()
268 if not npx_cmd:
269 logger.error(
270 "npx not found. Please ensure Node.js and npm are properly installed and added to your system PATH."
271 )
272 sys.exit(1)
273
274 # Run the MCP Inspector command with shell=True on Windows
275 shell = sys.platform == "win32"
276 process = subprocess.run(
277 [npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,
278 check=True,

Callers

nothing calls this directly

Calls 8

_parse_file_pathFunction · 0.85
_import_serverFunction · 0.85
_build_uv_commandFunction · 0.85
_get_npx_commandFunction · 0.85
debugMethod · 0.80
errorMethod · 0.80
exitMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected