~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(mcp): thread settings_snapshot to analyze_documents (#3683)
LearningCircuitedd0dfe7201a
diff --git a/src/local_deep_research/mcp/server.py b/src/local_deep_research/mcp/server.pyindex b3287584cd..29eff6baef 100644--- a/src/local_deep_research/mcp/server.py+++ b/src/local_deep_research/mcp/server.py@@ -530,10 +530,17 @@ def analyze_documents(f"Analyzing documents in '{collection_name}' for query: {query[:100]}...")+ # Build a settings snapshot the same way the other MCP tools do.+ # Without this, analyze_documents falls back to JSON defaults ++ # LDR_* env vars and silently ignores user-configured providers,+ # API keys, and embedding model. Mirrors quick_research (line 278).+ settings = create_settings_snapshot()+result = ldr_analyze_documents(query=query,collection_name=collection_name,max_results=max_results,+ settings_snapshot=settings,)return {diff --git a/tests/mcp/test_server.py b/tests/mcp/test_server.pyindex 79432be4cf..9c0a52b701 100644--- a/tests/mcp/test_server.py+++ b/tests/mcp/test_server.py@@ -616,3 +616,139 @@ class TestSettingsOverrides:assert result["search.iterations"] == 2assert "search.search_strategy" not in resultassert "llm.temperature" not in result+++class TestMcpToolToResearchFunctionContext:+ """Contract tests: every MCP tool that calls a research function must+ build a settings_snapshot via create_settings_snapshot() and thread it+ to the underlying call. Without this, the user's stored settings (LLM+ provider/model, API keys, embedding model, etc.) are silently ignored+ and the tool falls back to JSON defaults + LDR_* env vars.++ Pattern: capture-list mock (assertions run on a captured kwargs dict+ after the response, not inside the mock itself — the MCP tool's broad+ ``except Exception`` would otherwise swallow AssertionError).+ """++ def test_quick_research_threads_settings_snapshot(self):+ """quick_research → ldr_quick_summary must include settings_snapshot."""+ from local_deep_research.mcp.server import quick_research++ captured = {}++ def _capture(*args, **kwargs):+ captured["args"] = args+ captured["kwargs"] = kwargs+ return {+ "summary": "ok",+ "findings": [],+ "sources": [],+ "iterations": 0,+ "formatted_findings": "",+ }++ with patch(+ "local_deep_research.mcp.server.ldr_quick_summary",+ side_effect=_capture,+ ):+ result = quick_research(query="test query")++ assert result["status"] == "success"+ assert "settings_snapshot" in captured["kwargs"], (+ f"ldr_quick_summary called without settings_snapshot. "+ f"kwargs: {list(captured['kwargs'].keys())}"+ )+ assert captured["kwargs"]["settings_snapshot"] is not None++ def test_detailed_research_threads_settings_snapshot(self):+ """detailed_research → ldr_detailed_research must include settings_snapshot."""+ from local_deep_research.mcp.server import detailed_research++ captured = {}++ def _capture(*args, **kwargs):+ captured["args"] = args+ captured["kwargs"] = kwargs+ return {+ "query": "test",+ "research_id": "test-123",+ "summary": "ok",+ "findings": [],+ "iterations": 0,+ "questions": {},+ "formatted_findings": "",+ "sources": [],+ "metadata": {},+ }++ with patch(+ "local_deep_research.mcp.server.ldr_detailed_research",+ side_effect=_capture,+ ):+ result = detailed_research(query="test query")++ assert result["status"] == "success"+ assert "settings_snapshot" in captured["kwargs"], (+ f"ldr_detailed_research called without settings_snapshot. "+ f"kwargs: {list(captured['kwargs'].keys())}"+ )+ assert captured["kwargs"]["settings_snapshot"] is not None++ def test_generate_report_threads_settings_snapshot(self):+ """generate_report → ldr_generate_report must include settings_snapshot."""+ from local_deep_research.mcp.server import generate_report++ captured = {}++ def _capture(*args, **kwargs):+ captured["args"] = args+ captured["kwargs"] = kwargs+ return {"content": "# Report", "metadata": {}}++ with patch(+ "local_deep_research.mcp.server.ldr_generate_report",+ side_effect=_capture,+ ):+ result = generate_report(query="test query")++ assert result["status"] == "success"+ assert "settings_snapshot" in captured["kwargs"], (+ f"ldr_generate_report called without settings_snapshot. "+ f"kwargs: {list(captured['kwargs'].keys())}"+ )+ assert captured["kwargs"]["settings_snapshot"] is not None++ def test_analyze_documents_threads_settings_snapshot(self):+ """analyze_documents → ldr_analyze_documents must include+ settings_snapshot. This is the regression fence for the bug that+ previously omitted user context from the call."""+ from local_deep_research.mcp.server import analyze_documents++ captured = {}++ def _capture(*args, **kwargs):+ captured["args"] = args+ captured["kwargs"] = kwargs+ return {+ "summary": "ok",+ "documents": [],+ "collection": "test",+ "document_count": 0,+ }++ with patch(+ "local_deep_research.mcp.server.ldr_analyze_documents",+ side_effect=_capture,+ ):+ result = analyze_documents(+ query="test query",+ collection_name="test_collection",+ )++ assert result["status"] == "success"+ assert "settings_snapshot" in captured["kwargs"], (+ f"ldr_analyze_documents called without settings_snapshot — "+ f"user-configured embedding model / LLM provider are ignored. "+ f"kwargs: {list(captured['kwargs'].keys())}"+ )+ assert captured["kwargs"]["settings_snapshot"] is not None