Skip to content

Falsy-but-valid values silently dropped by or operator in config merging #3832

@strawgate

Description

@strawgate

Several places use x or default to merge user-provided values with defaults. This silently drops falsy-but-valid values like port=0 (OS-assigned port), host="" (all interfaces), and description="" (explicitly cleared).

run_http() — port=0 and host="" ignored

# src/fastmcp/server/mixins/transport.py:266-267
host = host or fastmcp.settings.host    # host="" becomes "127.0.0.1"
port = port or fastmcp.settings.port    # port=0 becomes 8000

port=0 is the standard way to request an OS-assigned port. host="" binds to all interfaces. Both are silently replaced.

CLI run command — same pattern

# src/fastmcp/cli/cli.py:604-609
final_host = host or config.deployment.host
final_port = port or config.deployment.port
final_path = path or config.deployment.path

fastmcp run server.py --port 0 silently uses the config port instead.

Tool/resource/prompt description — empty string falls through to docstring

# src/fastmcp/tools/function_tool.py:225
description=metadata.description or parsed_fn.description

# src/fastmcp/resources/function_resource.py:199
description=metadata.description or inspect.getdoc(fn)

# src/fastmcp/prompts/function_prompt.py:155
description = metadata.description or inspect.getdoc(fn)
@mcp.tool(description="")
def my_tool() -> str:
    """This docstring should NOT be used as description"""
    return "hello"

# description is "This docstring should NOT be used as description"

Fix

Replace x or default with x if x is not None else default in all affected locations.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.cliRelated to FastMCP CLI commands (run, dev, install) or CLI functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions