Skip to content

feat(mcp): add ragflow_list_datasets and ragflow_list_chats tools - #15384

Merged
yuzhichang merged 5 commits into
infiniflow:mainfrom
saltsalt123:main
Jul 1, 2026
Merged

yuzhichang merged 5 commits into
infiniflow:mainfrom
saltsalt123:main

Conversation

@saltsalt123

Copy link
Copy Markdown
Contributor

Summary

Add two new MCP tools to the RAGFlow MCP server:

  1. ragflow_list_datasets - List all accessible datasets with IDs, names, descriptions
  2. ragflow_list_chats - List all accessible chat assistants with IDs, names, descriptions

Implementation

  • Added list_chats() method to RAGFlowConnector
  • Registered both tools in list_tools() and call_tool()
  • Follows existing ragflow_retrieval pattern for error handling

Usage via langchain-mcp-adapters

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. labels May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: caec5820-a9d4-4b92-88e9-b965afd2a8d3

📥 Commits

Reviewing files that changed from the base of the PR and between e9911ad and 269d131.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • mcp/server/server.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • mcp/server/server.py

📝 Walkthrough

Walkthrough

RAGFlow MCP server gains chat listing: RAGFlowConnector.list_chats queries the backend /chats endpoint with pagination and ordering and returns newline-delimited JSON entries; the MCP tool list and dispatcher are updated to advertise and handle ragflow_list_datasets and ragflow_list_chats with pagination inputs.

Changes

Chat Listing MCP Support

Layer / File(s) Summary
Chat listing connector method
mcp/server/server.py
RAGFlowConnector.list_chats queries /chats with pagination and ordering, validates HTTP and backend code, and returns newline-delimited JSON for each chat's id, name, and description.
Tool registration and dispatcher updates
mcp/server/server.py
list_tools calls connector.list_chats to build chat descriptions; adds ragflow_list_datasets and ragflow_list_chats tool definitions with page/page_size input schemas; call_tool dispatches these tools, calls the connector, and returns results as types.TextContent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped to fetch the chat parade,
New tools aligned, new queries made.
Pages turn and names alight,
Line-by-line the JSON’s bright.
A tiny hop — the list is made!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description includes a summary of changes and implementation details, but does not follow the repository's required template structure with 'What problem does this PR solve?' and 'Type of change' sections. Add the required template sections: explain the problem/motivation in 'What problem does this PR solve?' and select the appropriate checkbox for 'Type of change' (likely 'New Feature').
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding two new MCP tools (ragflow_list_datasets and ragflow_list_chats) to the server.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
mcp/server/server.py (3)

553-556: 💤 Low value

Redundant dataset listing in the tool description.

The full dataset_description is already embedded in the ragflow_retrieval tool 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_tools now fails entirely if /chats errors.

list_chats raises on any non-200/non-zero response, and this call happens during tool discovery. A transient /chats failure (or a backend without that endpoint) will now break the entire list_tools response, making even ragflow_retrieval and ragflow_list_datasets undiscoverable. 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

desc serialization is consistent (but json.dumps is redundant).

httpx encodes boolean params values as lowercase "true" / "false". json.dumps(desc) produces the same "true" / "false" strings, so /chats and /datasets receive equivalent desc query values. You can simplify by passing desc directly in list_chats for 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

📥 Commits

Reviewing files that changed from the base of the PR and between ea3a5db and e9911ad.

📒 Files selected for processing (1)
  • mcp/server/server.py

Comment thread mcp/server/server.py Resolved
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.
@yuzhichang
yuzhichang self-requested a review June 28, 2026 00:49
@yuzhichang

yuzhichang commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

This PR currently has merge conflicts with main and cannot be auto-synced.

Please run locally:

git fetch origin main
git rebase origin/main
# or
git merge origin/main

After resolving the conflicts, push to the current head branch and CI will re-run the review checks.

Triggered by reviewer yuzhichang (request-for-action)

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)
@yuzhichang yuzhichang added the ci Continue Integration label Jun 30, 2026
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3633d08) to head (485b89b).
⚠️ Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants