OpenBB-finance/OpenBB · error · TypeError
Error: The {name} instance in '{app_path}' appears not to be
Error message
Error: The {name} instance in '{app_path}' appears not to be a callable factory function What it means
TypeError raised when the --factory flag is set, the named attribute was found, but calling it raised TypeError — which the importer interprets as 'this attribute is not a callable factory function' (or its signature is not zero-argument callable). The same try/except otherwise silently tolerates calling a non-factory app instance.
Source
Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py:92
raise AttributeError(
f"Error: The app file '{app_path}' does not contain an '{name}' instance"
)
app_or_factory = getattr(module, name)
# Here we use the same approach as uvicorn to handle factory functions.
# This prevents us from relying on explicit type annotations.
# See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py
try:
app = app_or_factory()
if not factory:
print( # noqa: T201
"\n\n[WARNING] "
"App factory detected. Using it, but please consider setting the --factory flag explicitly.\n"
)
except TypeError:
if factory:
raise TypeError( # pylint: disable=raise-missing-from
f"Error: The {name} instance in '{app_path}' appears not to be a callable factory function"
)
app = app_or_factory
if not isinstance(app, FastAPI):
raise TypeError(
f"Error: The {name} instance in '{app_path}' is not an instance of FastAPI"
)
return app
cl_doc = """OpenBB MCP Server
Usage:
>>> python -m openbb_mcp_server [OPTIONS]
>>> openbb-mcp --app ./some_app.py --host 0.0.0.0 --port 8005View on GitHub (pinned to 3e071fcc2c)
Solutions
- If the target is already a FastAPI instance, drop --factory
- If it is a real factory, make it zero-argument callable (read its config from environment/settings inside the function)
- Ensure --name points at the function itself, not at something it returns or wraps
Example fix
# before
def create_app(settings: Settings) -> FastAPI: ...
openbb-mcp --app main.py:create_app --factory
# after
def create_app() -> FastAPI:
settings = Settings()
...
openbb-mcp --app main.py:create_app --factory Defensive patterns
Strategy: type-guard
Validate before calling
import inspect
target = getattr(module, name)
if factory:
if not callable(target):
raise ValueError(f"--factory set but {name!r} is not callable")
try:
inspect.signature(target).bind()
except TypeError:
raise ValueError(f"factory {name!r} must be callable with zero arguments") Type guard
def is_zero_arg_factory(module, name: str) -> bool:
import inspect
target = getattr(module, name, None)
if not callable(target):
return False
try:
inspect.signature(target).bind()
return True
except TypeError:
return False Try / catch
try:
app = import_app("./main.py", "create_app", True)
except TypeError as e:
if "not to be a callable factory" in str(e):
app = import_app("./main.py", "create_app", False) # it is an instance
else:
raise Prevention
- Only pass --factory when the attribute is truly a zero-argument function
- Keep factory functions parameterless; read config from env/settings inside
- Test the exact CLI invocation in CI so factory/name drift is caught early
When it happens
Trigger: --app main.py:create_app --factory where create_app actually requires arguments (create_app(settings)); or the attribute is a plain FastAPI instance (not callable) while --factory was passed; or a factory with a typo'd required parameter.
Common situations: Copy-pasting a --factory command line against code whose factory needs configuration objects, flagging --factory 'just in case' when the target is already an instance, refactoring a factory to take arguments after the launch script was written.
Related errors
- Error: The {name} instance in '{app_path}' is not an instanc
- Failed to load the file specs for '{file_path}'
- Error: Neither module '{module_path}' could be imported nor
- Error: The app file '{app_path}' does not exist
- Error: The app file '{app_path}' does not contain an '{name}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/0ff24bcf19a62847.
Report an issue: GitHub.