Run an MCP server. The server can be specified in two ways: 1. Module approach: server.py - runs the module directly, expecting a server.run() call. 2. Import approach: server.py:app - imports and runs the specified server object. Note: This command runs the server directly. You ar
(
file_spec: str = typer.Argument(
...,
help="Python file to run, optionally with :object suffix",
),
transport: Annotated[
str | None,
typer.Option(
"--transport",
"-t",
help="Transport protocol to use (stdio or sse)",
),
] = None,
)
| 302 | |
| 303 | @app.command() |
| 304 | def run( |
| 305 | file_spec: str = typer.Argument( |
| 306 | ..., |
| 307 | help="Python file to run, optionally with :object suffix", |
| 308 | ), |
| 309 | transport: Annotated[ |
| 310 | str | None, |
| 311 | typer.Option( |
| 312 | "--transport", |
| 313 | "-t", |
| 314 | help="Transport protocol to use (stdio or sse)", |
| 315 | ), |
| 316 | ] = None, |
| 317 | ) -> None: # pragma: no cover |
| 318 | """Run an MCP server. |
| 319 | |
| 320 | The server can be specified in two ways: |
| 321 | 1. Module approach: server.py - runs the module directly, expecting a server.run() call. |
| 322 | 2. Import approach: server.py:app - imports and runs the specified server object. |
| 323 | |
| 324 | Note: This command runs the server directly. You are responsible for ensuring |
| 325 | all dependencies are available. |
| 326 | For dependency management, use `mcp install` or `mcp dev` instead. |
| 327 | """ # noqa: E501 |
| 328 | file, server_object = _parse_file_path(file_spec) |
| 329 | |
| 330 | logger.debug( |
| 331 | "Running server", |
| 332 | extra={ |
| 333 | "file": str(file), |
| 334 | "server_object": server_object, |
| 335 | "transport": transport, |
| 336 | }, |
| 337 | ) |
| 338 | |
| 339 | try: |
| 340 | # Import and get server object |
| 341 | server = _import_server(file, server_object) |
| 342 | |
| 343 | # Run the server |
| 344 | kwargs = {} |
| 345 | if transport: |
| 346 | kwargs["transport"] = transport |
| 347 | |
| 348 | server.run(**kwargs) |
| 349 | |
| 350 | except Exception: |
| 351 | logger.exception( |
| 352 | "Failed to run server", |
| 353 | extra={ |
| 354 | "file": str(file), |
| 355 | }, |
| 356 | ) |
| 357 | sys.exit(1) |
| 358 | |
| 359 | |
| 360 | @app.command() |
nothing calls this directly
no test coverage detected