{"record":{"id":"78d8b09616622b15","repo":"OpenBB-finance/OpenBB","slug":"error-the-app-file-app-path-does-not-contain","errorCode":null,"errorMessage":"Error: The app file '{app_path}' does not contain an '{name}' instance","messagePattern":"Error: The app file '(.+?)' does not contain an '(.+?)' instance","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py","lineNumber":74,"sourceCode":"                raise FileNotFoundError(  # pylint: disable=raise-missing-from\n                    f\"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists\"\n                )\n\n            module = _load_module_from_file_path(file_path)\n\n    # Case 2: File path (e.g., \"main.py\" or \"my_app/main.py\")\n    else:\n        if not Path(app_path).is_absolute():\n            cwd = Path.cwd()\n            app_path = str(cwd.joinpath(app_path).resolve())\n\n        if not Path(app_path).exists():\n            raise FileNotFoundError(f\"Error: The app file '{app_path}' does not exist\")\n\n        module = _load_module_from_file_path(app_path)\n\n    if not hasattr(module, name):\n        raise AttributeError(\n            f\"Error: The app file '{app_path}' does not contain an '{name}' instance\"\n        )\n\n    app_or_factory = getattr(module, name)\n\n    # Here we use the same approach as uvicorn to handle factory functions.\n    # This prevents us from relying on explicit type annotations.\n    # See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py\n    try:\n        app = app_or_factory()\n        if not factory:\n            print(  # noqa: T201\n                \"\\n\\n[WARNING]   \"\n                \"App factory detected. Using it, but please consider setting the --factory flag explicitly.\\n\"\n            )\n    except TypeError:\n        if factory:\n            raise TypeError(  # pylint: disable=raise-missing-from","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py#L56-L92","documentation":"AttributeError raised after the app module was successfully imported/loaded, but it has no attribute with the requested name (default 'app', or the part after ':' in 'module:attr' notation, or the --name value). The importer then cannot retrieve the FastAPI instance to serve.","triggerScenarios":"--app main.py where main.py creates the app under a different variable (e.g. 'application' or 'api'); --app my_app.main:create_app without that function existing; --name app when the file names it 'fastapi_app'. The check is a plain hasattr on the loaded module.","commonSituations":"Following a tutorial whose variable name differs from your project's, refactoring that renames the app variable, using a factory function name that was misspelled, assuming 'app' is exported by a package's __init__ when it is defined in a submodule.","solutions":["Match the name: use colon notation --app main.py:application or pass --name application","Or add 'app = application' (an alias) in the module so the default name works","For factories, export the factory function by its exact name and add --factory"],"exampleFix":"# before\n# main.py:  application = FastAPI()\nopenbb-mcp --app ./main.py            # looks for 'app'\n\n# after\nopenbb-mcp --app ./main.py:application","handlingStrategy":"validation","validationCode":"import runpy  # or import the module explicitly\nmod = importlib.import_module(module_name) if module_importable else runpy.run_path(file_path)\nif not hasattr(mod, attr_name):\n    available = [n for n in dir(mod) if isinstance(getattr(mod, n), FastAPI)]\n    raise ValueError(f\"no '{attr_name}' attr; FastAPI instances found: {available}\")","typeGuard":"def module_exposes_app(module, name: str) -> bool:\n    return hasattr(module, name)","tryCatchPattern":"try:\n    app = import_app(\"./main.py\", \"app\")\nexcept AttributeError as e:\n    if \"does not contain\" in str(e):\n        import runpy\n        mod = runpy.run_path(\"./main.py\")\n        candidates = [n for n, v in mod.items() if isinstance(v, FastAPI)]\n        app = import_app(f\"./main.py:{candidates[0]}\", candidates[0])\n    else:\n        raise","preventionTips":["Standardize on the variable name 'app' across your services","Use colon notation main.py:application to state the name explicitly in the command","Lint for 'app = FastAPI(' in the entry module during CI"],"tags":["python","cli","attribute-error","fastapi","naming"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}