{"record":{"id":"3de076eab7f482c0","repo":"assafelovic/gpt-researcher","slug":"mcpretriever-requires-a-researcher-instance-with-c","errorCode":null,"errorMessage":"MCPRetriever requires a researcher instance with cfg attribute containing LLM configuration","messagePattern":"MCPRetriever requires a researcher instance with cfg attribute containing LLM configuration","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"gpt_researcher/retrievers/mcp/retriever.py","lineNumber":114,"sourceCode":"            List[Dict[str, Any]]: List of MCP server configurations.\n        \"\"\"\n        if self.researcher and hasattr(self.researcher, 'mcp_configs'):\n            return self.researcher.mcp_configs or []\n        return []\n\n    def _get_config(self):\n        \"\"\"\n        Get configuration from the researcher instance.\n        \n        Returns:\n            Config: Configuration object with LLM settings.\n        \"\"\"\n        if self.researcher and hasattr(self.researcher, 'cfg'):\n            return self.researcher.cfg\n        \n        # If no config available, this is a critical error\n        logger.error(\"No config found in researcher instance. MCPRetriever requires a researcher instance with cfg attribute.\")\n        raise ValueError(\"MCPRetriever requires a researcher instance with cfg attribute containing LLM configuration\")\n\n    async def search_async(self, max_results: int = 10) -> List[Dict[str, str]]:\n        \"\"\"\n        Perform an async search using MCP tools with intelligent two-stage approach.\n        \n        Args:\n            max_results: Maximum number of results to return.\n            \n        Returns:\n            List[Dict[str, str]]: The search results.\n        \"\"\"\n        # Check if we have any server configurations\n        if not self.mcp_configs:\n            error_msg = \"No MCP server configurations available. Please provide mcp_configs parameter to GPTResearcher.\"\n            logger.error(error_msg)\n            await self.streamer.stream_error(\"MCP retriever cannot proceed without server configurations.\")\n            return []  # Return empty instead of raising to allow research to continue\n            ","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/mcp/retriever.py#L96-L132","documentation":"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.","triggerScenarios":"Creating MCPRetriever(query) without passing the researcher, or passing a mock/stand-in object that has no cfg attribute; __init__ calls _get_config() immediately.","commonSituations":"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.","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."],"exampleFix":"# before\nretriever = MCPRetriever(query=\"...\")\n\n# after\nretriever = MCPRetriever(query=\"...\", researcher=researcher_instance)\n# tests: MCPRetriever(q, researcher=SimpleNamespace(cfg=test_cfg))","handlingStrategy":"type-guard","validationCode":"assert researcher is not None and hasattr(researcher, \"cfg\"), \"researcher with cfg required\"","typeGuard":"def has_cfg(r) -> bool:\n    return r is not None and hasattr(r, \"cfg\") and r.cfg is not None","tryCatchPattern":"try:\n    retriever = MCPRetriever(query, researcher=researcher)\nexcept ValueError as e:\n    if \"cfg attribute\" in str(e):\n        raise TypeError(\"Pass the GPTResearcher instance\") from e\n    raise","preventionTips":["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."],"tags":["mcp","retriever","configuration","constructor"],"backgroundTag":"missing-required-constructor-argument","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}