Skip to main content

fastmcp.cli.generate

Generate a standalone CLI script from an MCP server’s capabilities.

Functions

serialize_transport

Serialize a resolved transport to a Python expression string. Returns (expression, extra_imports) where extra_imports is a set of import lines needed by the expression.

generate_cli_script

Generate the full CLI script source code.

generate_cli_command

Generate a standalone CLI script from an MCP server. Connects to the server, reads its tools/resources/prompts, and writes a Python script that can invoke them directly. Examples: fastmcp generate-cli weather fastmcp generate-cli weather my_cli.py fastmcp generate-cli http://localhost:8000/mcp fastmcp generate-cli server.py output.py -f