Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
When an Advanced Chat app backed by Knowledge Retrieval is published as an MCP server, tools/call returns only the generated answer text. The retrieved source metadata is persisted by Dify in messages.message_metadata.retriever_resources, but it is not exposed through the MCP response.
This makes downstream MCP clients such as Microsoft Copilot Studio and Teams unable to show citations, document attribution, page/section information, or other provenance to end users. For enterprise RAG use cases, users need to know which manual, policy, or document supports an answer.
For example, the current MCP response is effectively:
{
"content": [
{
"type": "text",
"text": "Move your hand up or down below the inside rearview mirror to turn the reading light on or off."
}
]
}
However, the corresponding Dify message already contains retrieval metadata such as:
- dataset name
- document name
- segment content and position
- retrieval score
- document metadata (for example page, model, version, or other custom metadata)
The current MCP adapter for chat modes extracts only response["answer"], and structured output contains only { "answer": ... }. As a result, the provenance is lost at the MCP boundary.
It would be helpful if MCP responses for RAG-backed Chat / Advanced Chat apps could expose citations and source attribution, for example:
{
"answer": "Move your hand up or down below the inside rearview mirror to turn the reading light on or off.",
"citations": [
{
"dataset_name": "vehicle-manuals",
"document_name": "vehicle-manual.xlsx",
"title": "Turning the reading light on and off",
"page": 272,
"score": 0.70,
"metadata": {
"model": "example-model",
"model_year": "example-year"
}
}
]
}
Suggested behavior:
- Include deduplicated retrieval sources in
structuredContent.citations for MCP clients that support structured output.
- Optionally append a human-readable source section to
TextContent for clients that only render text.
- Avoid exposing internal-only identifiers by default, such as tenant IDs or segment internals; expose user-facing document metadata instead.
- Preserve backward compatibility for apps without retrieval results and for older MCP protocol versions.
- Support both blocking Chat / Advanced Chat responses and streaming Agent Chat responses where retrieval metadata is available.
2. Additional context or comments
Tested with self-hosted Dify 1.16.1 and an Advanced Chat app published as an MCP server. The knowledge retrieval itself works and retriever_resources are correctly saved in message_metadata; only the MCP response omits them.
Related but separate MCP transaction bug: #39787 and #40013. Those address tools/call failing with a closed SQLAlchemy transaction, not citation propagation.
This feature would improve trust, auditability, and compliance for enterprise MCP integrations, especially Microsoft Copilot Studio / Teams, where the MCP tool response is the only source available to the orchestrator.
3. Can you help us with this feature?
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
When an Advanced Chat app backed by Knowledge Retrieval is published as an MCP server,
tools/callreturns only the generated answer text. The retrieved source metadata is persisted by Dify inmessages.message_metadata.retriever_resources, but it is not exposed through the MCP response.This makes downstream MCP clients such as Microsoft Copilot Studio and Teams unable to show citations, document attribution, page/section information, or other provenance to end users. For enterprise RAG use cases, users need to know which manual, policy, or document supports an answer.
For example, the current MCP response is effectively:
{ "content": [ { "type": "text", "text": "Move your hand up or down below the inside rearview mirror to turn the reading light on or off." } ] }However, the corresponding Dify message already contains retrieval metadata such as:
The current MCP adapter for chat modes extracts only
response["answer"], and structured output contains only{ "answer": ... }. As a result, the provenance is lost at the MCP boundary.It would be helpful if MCP responses for RAG-backed Chat / Advanced Chat apps could expose citations and source attribution, for example:
{ "answer": "Move your hand up or down below the inside rearview mirror to turn the reading light on or off.", "citations": [ { "dataset_name": "vehicle-manuals", "document_name": "vehicle-manual.xlsx", "title": "Turning the reading light on and off", "page": 272, "score": 0.70, "metadata": { "model": "example-model", "model_year": "example-year" } } ] }Suggested behavior:
structuredContent.citationsfor MCP clients that support structured output.TextContentfor clients that only render text.2. Additional context or comments
Tested with self-hosted Dify 1.16.1 and an Advanced Chat app published as an MCP server. The knowledge retrieval itself works and
retriever_resourcesare correctly saved inmessage_metadata; only the MCP response omits them.Related but separate MCP transaction bug: #39787 and #40013. Those address
tools/callfailing with a closed SQLAlchemy transaction, not citation propagation.This feature would improve trust, auditability, and compliance for enterprise MCP integrations, especially Microsoft Copilot Studio / Teams, where the MCP tool response is the only source available to the orchestrator.
3. Can you help us with this feature?