feat(mcp): add Prompts API and ragflow_list_datasets tool for intelligent retrieval routing#13440
Open
Louisym wants to merge 4 commits intoinfiniflow:mainfrom
Open
feat(mcp): add Prompts API and ragflow_list_datasets tool for intelligent retrieval routing#13440Louisym wants to merge 4 commits intoinfiniflow:mainfrom
Louisym wants to merge 4 commits intoinfiniflow:mainfrom
Conversation
…gent retrieval routing Add MCP Prompts support to the RAGFlow MCP server, enabling LLM clients to white-box the retrieval process via standardized list_prompts and get_prompt handlers. Changes: - mcp/server/server.py: implement list_prompts and get_prompt handlers exposing a ragflow_retrieval_skill prompt that assembles a 4-step SOP (dataset listing -> intent analysis -> retrieval -> answer synthesis) with dynamic dataset injection via ragflow_list_datasets tool call; add ragflow_list_datasets tool returning full KB metadata - test/__init__.py: make test/ a proper Python package - test/benchmark/mcp_skill_eval.py: A/B benchmark comparing global search (baseline) vs MCP-skill-guided routing using ragas metrics - test/benchmark/wixqa_eval.py: WixQA-based benchmark (Wix/WixQA on HuggingFace, 100 questions across 2 KBs); routing improves context precision +2.0%, recall +4.5%, and reduces avg latency by 9.2% - wixqa_benchmark_report.md: benchmark results report
…gent retrieval routing - Implement list_prompts / get_prompt handlers exposing ragflow_retrieval_skill prompt - Dynamically inject live KB snapshot, parameter tuning guide, routing rules, and self-healing rules - Add ragflow_list_datasets tool for LLM-driven KB discovery - Refactor list_datasets() with shared _fetch_datasets_raw() + _normalize_dataset_item() helpers - Add ragas>=0.2.0 and openai>=1.0.0 to test dependency group - Add test/benchmark/mcp_skill_eval.py: A/B benchmark (global search vs precise routing) evaluated on WixQA dataset with gpt-4o as ragas judge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the RAGFlow MCP Server "white-box" to connected LLM clients by implementing
the MCP Prompts specification and adding a dataset discovery tool.
Before: clients saw a single opaque
ragflow_retrievaltool with no guidance on whichknowledge bases exist, how to tune parameters, or how to recover from failures.
After: clients can request a live SOP prompt (
ragflow_retrieval_skill) that injects:Changes
mcp/server/server.pyragflow_list_datasets— lets the LLM proactively refresh the KB list andget full metadata (name, document_count, chunk_count, embedding_model, language)
@app.list_prompts()— exposesragflow_retrieval_skillprompt with optionalintentargument (precise/broad/auto)@app.get_prompt()— dynamically assembles a 4-module SOP prompt with a liveKB snapshot on every call
list_datasets()— extended return fields and extracted shared helpersto eliminate code duplication; also populates the dataset metadata cache as a side effect
test/benchmark/mcp_skill_eval.py(new)context_precision,context_recall) with OpenAIgpt-4oas judge LLMtest/benchmark/infrastructure (HttpClient, dataset helpers, metrics)test/benchmark/wixqa_eval.py(new)(200 expert-written + 200 simulated customer support Q&A pairs)
Benchmark Results
Evaluated on 100 questions from Wix/WixQA
across 2 knowledge bases. Judged by
gpt-4ovia ragas.Latency percentiles:
Routing consistently reduces noise (precision ↑), improves information coverage (recall ↑),
and cuts latency at every percentile by eliminating unnecessary KB searches.
Test Plan
list_promptsreturnsragflow_retrieval_skillwithintentargumentget_promptreturns a prompt containing current KB listintent=precisevsintent=broadproduces different threshold guidanceragflow_list_datasetstool returns full metadata JSON arrayOPENAI_API_KEY=xxx uv run python test/benchmark/wixqa_eval.py --base-url http://127.0.0.1:9380 --api-key ragflow-xxx