Repository navigation
feat(mcp): add ragflow_list_datasets and ragflow_list_chats tools - #15384
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRAGFlow MCP server gains chat listing: ChangesChat Listing MCP Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
mcp/server/server.py (3)
553-556: 💤 Low valueRedundant dataset listing in the tool description.
The full
dataset_descriptionis already embedded in theragflow_retrievaltool description (Line 494). Appending it again here duplicates the entire dataset list across two tool descriptions, inflating the advertised tool payload (and token usage) for clients. Since this tool already returns datasets at call time, consider a static description without the appended list.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@mcp/server/server.py` around lines 553 - 556, The tool definition for types.Tool with name "ragflow_list_datasets" is appending dataset_description redundantly (duplicate of the long list already present in the ragflow_retrieval tool); remove the concatenation of dataset_description from the ragflow_list_datasets description and replace it with a concise static sentence (e.g., "Returns a list of accessible datasets with IDs, names and short descriptions.") so the full dataset list remains only in the ragflow_retrieval tool and you avoid inflating the tool payload.
488-488: ⚡ Quick win
list_toolsnow fails entirely if/chatserrors.
list_chatsraises on any non-200/non-zero response, and this call happens during tool discovery. A transient/chatsfailure (or a backend without that endpoint) will now break the entirelist_toolsresponse, making evenragflow_retrievalandragflow_list_datasetsundiscoverable. Consider degrading gracefully so a chat-listing hiccup doesn't take down tool discovery.♻️ Graceful fallback
- chat_description = await connector.list_chats(api_key=api_key) + try: + chat_description = await connector.list_chats(api_key=api_key) + except Exception as exc: + logging.warning("list_tools failed to fetch chat descriptions: %s", exc) + chat_description = ""🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@mcp/server/server.py` at line 488, When calling connector.list_chats(api_key=api_key) from the list_tools flow, wrap the call in a try/except to prevent a failing /chats endpoint from aborting tool discovery: catch the exception raised by connector.list_chats, log a warning or debug message including the error, and set chat_description (or the variable used downstream) to an empty list or None so the rest of list_tools (e.g., ragflow_retrieval and ragflow_list_datasets discovery) can proceed; ensure you reference connector.list_chats and the chat_description variable within the list_tools function so downstream logic handles the empty/None value gracefully.
167-167: 💤 Low value
descserialization is consistent (butjson.dumpsis redundant).
httpxencodes booleanparamsvalues as lowercase"true"/"false".json.dumps(desc)produces the same"true"/"false"strings, so/chatsand/datasetsreceive equivalentdescquery values. You can simplify by passingdescdirectly inlist_chatsfor readability/consistency.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@mcp/server/server.py` at line 167, The params dict currently uses json.dumps(desc) which is redundant because httpx will encode boolean values to "true"/"false"; update the params construction (used by list_chats) to pass desc directly (params = {"page": page, "page_size": page_size, "orderby": orderby, "desc": desc}) and remove the json.dumps call so desc is a plain bool throughout list_chats and related request code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mcp/server/server.py`:
- Around line 165-184: In function list_chats, add logging around the external
call and failure branches: log an info/debug message before/after calling
self._get("/chats", ...) including params and a redacted api_key indicator; log
error messages on non-200 responses and when res_json.get("code") != 0 including
the extracted error_message/res_json.get("message") and context (e.g., page,
page_size, orderby); ensure logs reference list_chats and the HTTP endpoint
"/chats" and keep the raised Exception payload (types.TextContent) unchanged.
---
Nitpick comments:
In `@mcp/server/server.py`:
- Around line 553-556: The tool definition for types.Tool with name
"ragflow_list_datasets" is appending dataset_description redundantly (duplicate
of the long list already present in the ragflow_retrieval tool); remove the
concatenation of dataset_description from the ragflow_list_datasets description
and replace it with a concise static sentence (e.g., "Returns a list of
accessible datasets with IDs, names and short descriptions.") so the full
dataset list remains only in the ragflow_retrieval tool and you avoid inflating
the tool payload.
- Line 488: When calling connector.list_chats(api_key=api_key) from the
list_tools flow, wrap the call in a try/except to prevent a failing /chats
endpoint from aborting tool discovery: catch the exception raised by
connector.list_chats, log a warning or debug message including the error, and
set chat_description (or the variable used downstream) to an empty list or None
so the rest of list_tools (e.g., ragflow_retrieval and ragflow_list_datasets
discovery) can proceed; ensure you reference connector.list_chats and the
chat_description variable within the list_tools function so downstream logic
handles the empty/None value gracefully.
- Line 167: The params dict currently uses json.dumps(desc) which is redundant
because httpx will encode boolean values to "true"/"false"; update the params
construction (used by list_chats) to pass desc directly (params = {"page": page,
"page_size": page_size, "orderby": orderby, "desc": desc}) and remove the
json.dumps call so desc is a plain bool throughout list_chats and related
request code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2628a35f-2e61-429b-80e0-e9569cdece6e
📒 Files selected for processing (1)
mcp/server/server.py
CodeRabbit review flagged that list_chats (new backend flow) lacked logging unlike resolve_dataset_ids and retrieval. Added info/debug logs around the /chats call and on failure paths.
|
This PR currently has merge conflicts with Please run locally: git fetch origin main
git rebase origin/main
# or
git merge origin/mainAfter resolving the conflicts, push to the current head branch and CI will re-run the review checks.
|
Conflicts resolved: - mcp/server/server.py: kept PR's list_chats method and main's _fetch_all_datasets/list_datasets refactor - uv.lock: took main's version (PR introduced no new dependencies; uv lock --check passes)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15384 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Add two new MCP tools to the RAGFlow MCP server:
Implementation
list_chats()method toRAGFlowConnectorlist_tools()andcall_tool()ragflow_retrievalpattern for error handlingUsage via langchain-mcp-adapters