assafelovic/gpt-researcher · critical · ValueError
MCPRetriever requires a researcher instance with cfg attribu
Error message
MCPRetriever requires a researcher instance with cfg attribute containing LLM configuration
What it means
ValueError raised by MCPRetriever._get_config() when the retriever was constructed without a researcher instance (or with one lacking a cfg attribute). The retriever needs the researcher's config to obtain LLM settings for its two-stage search, so it treats a missing config as a critical, non-recoverable error.
Source
Thrown at gpt_researcher/retrievers/mcp/retriever.py:114
List[Dict[str, Any]]: List of MCP server configurations.
"""
if self.researcher and hasattr(self.researcher, 'mcp_configs'):
return self.researcher.mcp_configs or []
return []
def _get_config(self):
"""
Get configuration from the researcher instance.
Returns:
Config: Configuration object with LLM settings.
"""
if self.researcher and hasattr(self.researcher, 'cfg'):
return self.researcher.cfg
# If no config available, this is a critical error
logger.error("No config found in researcher instance. MCPRetriever requires a researcher instance with cfg attribute.")
raise ValueError("MCPRetriever requires a researcher instance with cfg attribute containing LLM configuration")
async def search_async(self, max_results: int = 10) -> List[Dict[str, str]]:
"""
Perform an async search using MCP tools with intelligent two-stage approach.
Args:
max_results: Maximum number of results to return.
Returns:
List[Dict[str, str]]: The search results.
"""
# Check if we have any server configurations
if not self.mcp_configs:
error_msg = "No MCP server configurations available. Please provide mcp_configs parameter to GPTResearcher."
logger.error(error_msg)
await self.streamer.stream_error("MCP retriever cannot proceed without server configurations.")
return [] # Return empty instead of raising to allow research to continue
View on GitHub (pinned to 6f998577d5)
Solutions
- Pass the researcher instance: MCPRetriever(query, researcher=self.researcher).
- If testing, use a simple stub: types.SimpleNamespace(cfg=your_cfg) as the researcher.
- Ensure you construct retrievers through the standard GPTResearcher flow so cfg is populated.
Example fix
# before retriever = MCPRetriever(query="...") # after retriever = MCPRetriever(query="...", researcher=researcher_instance) # tests: MCPRetriever(q, researcher=SimpleNamespace(cfg=test_cfg))
Defensive patterns
Strategy: type-guard
Validate before calling
assert researcher is not None and hasattr(researcher, "cfg"), "researcher with cfg required"
Type guard
def has_cfg(r) -> bool:
return r is not None and hasattr(r, "cfg") and r.cfg is not None Try / catch
try:
retriever = MCPRetriever(query, researcher=researcher)
except ValueError as e:
if "cfg attribute" in str(e):
raise TypeError("Pass the GPTResearcher instance") from e
raise Prevention
- Always construct retrievers through the researcher flow that injects cfg.
- In tests, stub the researcher with SimpleNamespace(cfg=...).
- Guard hasattr(researcher, 'cfg') before constructing MCPRetriever.
When it happens
Trigger: Creating MCPRetriever(query) without passing the researcher, or passing a mock/stand-in object that has no cfg attribute; __init__ calls _get_config() immediately.
Common situations: Using the retriever standalone in tests or scripts, refactoring that drops the researcher argument, or constructing it with a None researcher expecting a default config path.
Related errors
- Error parsing SearxNG response
- SerpApi API key not found. Please set the SERPAPI_API_KEY en
- Serper API key not found. Please set the SERPER_API_KEY envi
- Unable to import {pkg_kebab}. Please install with `pip insta
- Xquik API key not found. Please set the XQUIK_API_KEY enviro
AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28).
Data as JSON: /api/errors/3de076eab7f482c0.
Report an issue: GitHub.