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

Function install

src/mcp/cli/cli.py:361–486  ·  view source on GitHub ↗

Install an MCP server in the Claude desktop app. Environment variables are preserved once added and only updated if new values are explicitly provided.

(
    file_spec: str = typer.Argument(
        ...,
        help="Python file to run, optionally with :object suffix",
    ),
    server_name: Annotated[
        str | None,
        typer.Option(
            "--name",
            "-n",
            help="Custom name for the server (defaults to server's name attribute or file name)",
        ),
    ] = None,
    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",
        ),
    ] = [],
    env_vars: Annotated[
        list[str],
        typer.Option(
            "--env-var",
            "-v",
            help="Environment variables in KEY=VALUE format",
        ),
    ] = [],
    env_file: Annotated[
        Path | None,
        typer.Option(
            "--env-file",
            "-f",
            help="Load environment variables from a .env file",
            exists=True,
            file_okay=True,
            dir_okay=False,
            resolve_path=True,
        ),
    ] = None,
)

Source from the content-addressed store, hash-verified

359
360@app.command()
361def install(
362 file_spec: str = typer.Argument(
363 ...,
364 help="Python file to run, optionally with :object suffix",
365 ),
366 server_name: Annotated[
367 str | None,
368 typer.Option(
369 "--name",
370 "-n",
371 help="Custom name for the server (defaults to server's name attribute or file name)",
372 ),
373 ] = None,
374 with_editable: Annotated[
375 Path | None,
376 typer.Option(
377 "--with-editable",
378 "-e",
379 help="Directory containing pyproject.toml to install in editable mode",
380 exists=True,
381 file_okay=False,
382 resolve_path=True,
383 ),
384 ] = None,
385 with_packages: Annotated[
386 list[str],
387 typer.Option(
388 "--with",
389 help="Additional packages to install",
390 ),
391 ] = [],
392 env_vars: Annotated[
393 list[str],
394 typer.Option(
395 "--env-var",
396 "-v",
397 help="Environment variables in KEY=VALUE format",
398 ),
399 ] = [],
400 env_file: Annotated[
401 Path | None,
402 typer.Option(
403 "--env-file",
404 "-f",
405 help="Load environment variables from a .env file",
406 exists=True,
407 file_okay=True,
408 dir_okay=False,
409 resolve_path=True,
410 ),
411 ] = None,
412) -> None: # pragma: no cover
413 """Install an MCP server in the Claude desktop app.
414
415 Environment variables are preserved once added and only updated if new values
416 are explicitly provided.
417 """
418 file, server_object = _parse_file_path(file_spec)

Callers

nothing calls this directly

Calls 7

_parse_file_pathFunction · 0.85
_import_serverFunction · 0.85
_parse_env_varFunction · 0.85
debugMethod · 0.80
errorMethod · 0.80
infoMethod · 0.80
exitMethod · 0.45

Tested by

no test coverage detected