Skip to content

[Bug]: MCP server tools/list crashes with "'str' object has no attribute 'get'" — list_chats() mishandles the /chats response shape #16727

Description

@hen1289

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (Language Policy).
  • Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

RAGFlow workspace code commit ID

32c5cb1

RAGFlow image version

v0.26.3

Other environment information

- RAGFlow version: **v0.26.3**
- ragflow-mcp-server: **1.19.0** (from `serverInfo` on `initialize`)
- Deployment: Docker, `--enable-mcpserver --mcp-mode=host`, doc engine = elasticsearch

Actual behavior

Describe the bug

The MCP server crashes on every tools/list call, so no MCP client can load any tools. initialize succeeds, but tools/list returns:

MCP error 0: 'str' object has no attribute 'get'

Server log:

ERROR:mcp.server.streamable_http:Error in message router
...
AttributeError: 'str' object has no attribute 'get'

Root cause

list_tools() in mcp/server/server.py builds its tool descriptions by calling both list_datasets() and list_chats():

@app.list_tools()
async def list_tools(*, connector, api_key):
    dataset_description = await connector.list_datasets(api_key=api_key)
    chat_description = await connector.list_chats(api_key=api_key)   # <-- crashes

list_chats() iterates the REST response's data as if it were a list of chat dicts:

chat_count = len(res_json.get("data", []))
for data in res_json.get("data", []):
    d = {"id": data.get("id"), "name": data.get("name"), "description": data.get("description", "")}

But GET /api/v1/chats returns data as an object, not a list:

{"code": 0, "data": {"chats": [], "total": 0}, "message": "success"}

So the loop iterates the dict's keys ("chats", "total" — strings) and data.get("id") raises 'str' object has no attribute 'get'. Since list_tools() always calls list_chats(), tools/list fails entirely and the MCP server is unusable (host and self-host modes). list_datasets() is unaffected because GET /api/v1/datasets returns data as a list.

Expected behavior

No response

Steps to reproduce

1. Run RAGFlow v0.26.3 with the MCP server enabled (`--enable-mcpserver --mcp-mode=host`).
2. Connect any MCP client (e.g. Claude Code) and request `tools/list`.
3. `initialize` succeeds; `tools/list` fails with the error above.

Additional information

Proposed fix

In list_chats(), read chats from data["chats"]:

chats = res_json.get("data", {}).get("chats", [])
chat_count = len(chats)
for data in chats:
    d = {"id": data.get("id"), "name": data.get("name"), "description": data.get("description", "")}

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't working, pull request that fix bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions