{"record":{"id":"4603953869344968","repo":"OpenBB-finance/OpenBB","slug":"error-the-factory-function-name-must-be-provided","errorCode":null,"errorMessage":"Error: The factory function name must be provided to the --name parameter when the factory flag is set.","messagePattern":"Error: The factory function name must be provided to the --name parameter when the factory flag is set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py","lineNumber":228,"sourceCode":"                            _kwargs[key] = value\n                    except (json.JSONDecodeError, ValueError):\n                        _kwargs[key] = value\n            else:\n                _kwargs[key] = True\n\n    # Extract and handle app import arguments\n    _app_path = _kwargs.pop(\"app\", None)\n    _name = _kwargs.pop(\"name\", \"app\")\n    _factory = _kwargs.pop(\"factory\", False)\n\n    imported_app = None\n    if _app_path:\n        if \":\" in _app_path:\n            _app_instance_name = _app_path.split(\":\")[-1]\n            _name = _app_instance_name if _app_instance_name else _name\n\n        if _factory and not _name:\n            raise ValueError(\n                \"Error: The factory function name must be provided to the --name parameter when the factory flag is set.\"\n            )\n        imported_app = import_app(_app_path, _name, _factory)\n\n    # Extract MCP-specific arguments\n    transport = _kwargs.pop(\"transport\", \"streamable-http\")\n    allowed_categories = _kwargs.pop(\"allowed_categories\", None)\n    default_categories = _kwargs.pop(\"default_categories\", \"all\")\n    tool_discovery = _kwargs.pop(\"tool_discovery\", False)\n    system_prompt = _kwargs.pop(\"system_prompt\", None)\n    server_prompts = _kwargs.pop(\"server_prompts\", None)\n\n    class Args:\n        \"\"\"Container for parsed command line arguments.\"\"\"\n\n        def __init__(self):\n            \"\"\"Initialize the Args container.\"\"\"\n            self.imported_app = imported_app","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py#L210-L246","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the empty --name argument or give it a real value: --name create_app","In scripts, default the variable: --name \"${APP_NAME:-app}\"","If you rely on colon notation 'main.py:create_app', you can drop --name entirely"],"exampleFix":"# before\nopenbb-mcp --app main.py --factory --name \"$APP_NAME\"   # APP_NAME unset\n\n# after\nopenbb-mcp --app main.py:create_app --factory","handlingStrategy":"validation","validationCode":"import os\n\nname = os.environ.get(\"APP_NAME\", \"app\").strip()\nif factory and not name:\n    name = \"app\"  # or fail fast with a clear message before spawning the CLI\ncli_args = [\"--app\", app_path, \"--name\", name] + ([\"--factory\"] if factory else [])","typeGuard":"def factory_invocation_valid(name: str | None, factory: bool) -> bool:\n    return not factory or bool(name)","tryCatchPattern":"try:\n    serve(**kwargs)\nexcept ValueError as e:\n    if \"factory function name must be provided\" in str(e):\n        kwargs[\"name\"] = \"app\"\n        serve(**kwargs)\n    else:\n        raise","preventionTips":["Default empty shell variables: --name \"${APP_NAME:-app}\"","Prefer module:attr colon notation over separate --name when using --factory","Add a launch-script check: [ -n \"$APP_NAME\" ] || exit 1"],"tags":["cli","arguments","factory","shell-script"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}