Repository navigation
fix(mcp): handle dict response in list_chats when /chats API returns paginated envelope - #16639
Conversation
…paginated envelope
The /api/v1/chats endpoint returns a paginated envelope:
{data: {chats: [...], total: N}}
But list_chats() assumed data was always a list, causing:
'str' object has no attribute 'get'
when iterating dict keys. This crashed the entire tools/list handler,
making all MCP tools (ragflow_retrieval, ragflow_list_datasets,
ragflow_list_chats) unavailable.
Fix: check if data is a dict and extract the 'chats' key.
|
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 selected for processing (1)
📝 WalkthroughWalkthroughRAGFlowConnector.list_chats now handles the /chats API response's data field being either a list or a dict containing a chats key, normalizing it before computing chat counts and building the result list. ChangesResponse normalization fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16639 +/- ##
=======================================
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:
|
What problem does this PR solve?
Resolves #16638
The MCP server's
list_chats()method inmcp/server/server.pyassumes the/api/v1/chatsREST API returnsdataas a list. However, the/chatsendpoint returns a paginated dict envelope:{"code": 0, "data": {"chats": [...], "total": 1}}When iterating a dict, Python yields its keys (strings), causing
'str' object has no attribute 'get'to be raised ondata.get("id"). Sincelist_chats()is called insidelist_tools(), this exception crashes the entiretools/listhandler, making all three MCP tools (ragflow_retrieval,ragflow_list_datasets,ragflow_list_chats) unavailable to every MCP client.What is changed?
Added a type check before iterating: if
datais a dict, extract thechatskey; otherwise use it directly as a list. This handles both the current dict response shape and any future list response.How was it tested?
tools/listreturns error'str' object has no attribute 'get'.tools/listsuccessfully returns all 3 tools (ragflow_retrieval,ragflow_list_datasets,ragflow_list_chats) with correct dataset and chat descriptions.Additional context
list_chatstool.