fastmcp/docs
Jeremiah Lowin 4262cfc16a
Add fastmcp generate-cli command (#3065)
* Add `fastmcp generate-cli` command

Connects to any MCP server, reads its tool/resource/prompt schemas,
and writes a standalone Python CLI script with typed subcommands.

* docs: add generate-cli documentation

* docs: add generate-cli documentation; skip Windows executable test

* fix: address PR review feedback

- Sanitize tool and parameter names to valid Python identifiers
- Replace bare except Exception with specific exception types
- Escape server name in generated string literals
- Handle trailing colon edge case in _derive_server_name
- Clarify in docs that generated CLI is a client, not a bundled server

* Fix string escaping issues in generate-cli

- Use single-quoted docstrings to avoid triple-quote escaping issues
- Escape quotes in app_name derived from server_name
- Add tests for descriptions with quotes and server names with quotes

Addresses CodeRabbit review comments about insufficient escaping.

* Implement smart parameter handling for generate-cli

- Simple types (str, int, float, bool): Direct typed flags
- Arrays of simple types (list[str], list[int]): Repeatable flags via cyclopts
- Complex types (objects, nested arrays): Accept JSON strings with parsing
- JSON schema shown in help text for complex parameters
- Proper escaping of newlines and quotes in help text
- Filter out None and empty list defaults when calling tools

This gives typed, discoverable CLIs for common cases while handling
complex schemas via JSON input.

* Update generate-cli docs to explain smart parameter handling

- Document simple types as direct typed flags
- Document arrays of simple types as repeatable flags
- Document complex types as JSON strings with schema in help
- Add examples showing all three patterns

* Fix Codex review issues in generate-cli

High priority fixes:
- Complex type defaults: Serialize dict/list defaults to JSON strings
- List params: Preserve help metadata with Annotated wrapper
- Name collisions: Detect and error on sanitized name conflicts
- JSON parsing: Use isinstance check for safety with defaults

Added tests for:
- Complex types with default values
- Parameter name collision detection
- Updated existing tests to match new format

* Use pydantic_core.to_json for consistency

- Generator now uses pydantic_core.to_json() instead of json.dumps()
- Consistent with rest of fastmcp codebase
- Generated CLI still uses plain json module (standalone script)

* Move local imports to module level in generate-cli

* Handle union item types and Python keyword collisions in generate-cli
2026-02-03 21:08:51 -05:00
..
.cursor/rules Clean up parameter documentation 2025-06-22 20:59:53 -04:00
assets Update FastMCP Cloud references to Prefect Horizon (#2978) 2026-01-21 20:52:08 -05:00
clients Add fastmcp generate-cli command (#3065) 2026-02-03 21:08:51 -05:00
community Update docs (#2094) 2025-10-14 16:38:21 -07:00
css Restructure documentation for FastMCP 3.0 (#2951) 2026-01-19 21:33:35 -05:00
deployment Pin httpx < 1.0 and simplify beta install docs (#2975) 2026-01-21 21:08:46 -05:00
development Remove OpenAPI timeout parameter, make client optional, surface timeout errors (#3067) 2026-02-03 21:08:09 -05:00
getting-started Pin httpx < 1.0 and simplify beta install docs (#2975) 2026-01-21 21:08:46 -05:00
integrations Add AzureJWTVerifier for Managed Identity token verification (#3058) 2026-02-02 19:59:13 -05:00
patterns Add fastmcp list and fastmcp call CLI commands (#3054) 2026-02-01 18:30:14 -05:00
public/schemas/fastmcp.json chore: Update fastmcp.json schema (#1955) 2025-09-29 20:12:24 -04:00
python-sdk chore: Update SDK documentation (#2995) 2026-02-03 21:08:20 -05:00
servers Add AzureJWTVerifier for Managed Identity token verification (#3058) 2026-02-02 19:59:13 -05:00
snippets Reorganize docs around provider architecture (#2723) 2025-12-25 09:00:20 -05:00
tutorials Remove trailing slashes from MCP endpoint URLs in docs (#2277) 2025-10-27 10:36:47 -04:00
v2 Add release notes for v2.14.4 and v2.14.5 (#3064) 2026-02-03 10:47:06 -05:00
.ccignore Add comprehensive OAuth 2.1 authentication system with WorkOS integration (#1327) 2025-08-01 17:06:55 -04:00
changelog.mdx Add release notes for v2.14.4 and v2.14.5 (#3064) 2026-02-03 10:47:06 -05:00
docs.json Add fastmcp generate-cli command (#3065) 2026-02-03 21:08:51 -05:00
updates.mdx Add release notes for v2.14.4 and v2.14.5 (#3064) 2026-02-03 10:47:06 -05:00
v2-banner.js Restructure documentation for FastMCP 3.0 (#2951) 2026-01-19 21:33:35 -05:00