OpenBB-finance/OpenBB · error · ValueError

Error: The factory function name must be provided to the --n

Error message

Error: The factory function name must be provided to the --name parameter when the factory flag is set.

What it means

ValueError from the server's argument handling: the --factory flag was supplied, but the effective instance/function name is empty. The name defaults to 'app', can be overridden by --name, and is replaced by the segment after ':' in 'module:attr' — but only if that segment is non-empty, so this fires essentially only when --name is explicitly set to an empty string.

Source

Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py:228

                            _kwargs[key] = value
                    except (json.JSONDecodeError, ValueError):
                        _kwargs[key] = value
            else:
                _kwargs[key] = True

    # Extract and handle app import arguments
    _app_path = _kwargs.pop("app", None)
    _name = _kwargs.pop("name", "app")
    _factory = _kwargs.pop("factory", False)

    imported_app = None
    if _app_path:
        if ":" in _app_path:
            _app_instance_name = _app_path.split(":")[-1]
            _name = _app_instance_name if _app_instance_name else _name

        if _factory and not _name:
            raise ValueError(
                "Error: The factory function name must be provided to the --name parameter when the factory flag is set."
            )
        imported_app = import_app(_app_path, _name, _factory)

    # Extract MCP-specific arguments
    transport = _kwargs.pop("transport", "streamable-http")
    allowed_categories = _kwargs.pop("allowed_categories", None)
    default_categories = _kwargs.pop("default_categories", "all")
    tool_discovery = _kwargs.pop("tool_discovery", False)
    system_prompt = _kwargs.pop("system_prompt", None)
    server_prompts = _kwargs.pop("server_prompts", None)

    class Args:
        """Container for parsed command line arguments."""

        def __init__(self):
            """Initialize the Args container."""
            self.imported_app = imported_app

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Remove the empty --name argument or give it a real value: --name create_app
  2. In scripts, default the variable: --name "${APP_NAME:-app}"
  3. If you rely on colon notation 'main.py:create_app', you can drop --name entirely

Example fix

# before
openbb-mcp --app main.py --factory --name "$APP_NAME"   # APP_NAME unset

# after
openbb-mcp --app main.py:create_app --factory
Defensive patterns

Strategy: validation

Validate before calling

import os

name = os.environ.get("APP_NAME", "app").strip()
if factory and not name:
    name = "app"  # or fail fast with a clear message before spawning the CLI
cli_args = ["--app", app_path, "--name", name] + (["--factory"] if factory else [])

Type guard

def factory_invocation_valid(name: str | None, factory: bool) -> bool:
    return not factory or bool(name)

Try / catch

try:
    serve(**kwargs)
except ValueError as e:
    if "factory function name must be provided" in str(e):
        kwargs["name"] = "app"
        serve(**kwargs)
    else:
        raise

Prevention

When it happens

Trigger: Invoking with --factory --name "" (empty name), e.g. from a shell script where $APP_NAME expanded to nothing: openbb-mcp --app main.py --factory --name "$APP_NAME". A trailing colon like 'main.py:' alone does not trigger it because the default name is kept.

Common situations: Launcher scripts passing unset environment variables as --name, CI pipelines templating an empty name, users assuming --name is optional-with-empty-meaning when combined with --factory.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/4603953869344968. Report an issue: GitHub.