mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-08 20:34:48 +08:00
fix(agent): enable MCP file preview via doc_id (#15399)
## Summary
MCP-wrapped agents could only force-download files looked up by
`doc_id`. This adds an explicit preview path and inline response headers
for previewable file types.
- **New** `GET /api/v1/agents/attachments/{attachment_id}/preview` —
inline preview for PDFs, images, and other safe types (pass `ext` and/or
`mime_type`)
- **Improved** `GET /api/v1/documents/{doc_id}/preview` — sets inline
disposition using the document filename
- **Improved** attachment download routing — resolves `mime_type` /
`ext` query params (no default `markdown`), supports
`disposition=inline`
- **DocGenerator output** — includes URL-encoded `preview_url` for MCP
clients
- **Legacy `/document/download/...` aliases** — still use download
semantics; MCP clients should call `/preview` explicitly
Fixes #15398
## Test plan
- [x] `pytest test/unit_test/api/utils/test_file_response_headers.py`
(6/6)
---------
Co-authored-by: MkDev11 <mkdev11@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Ling Qin <qinling0210@163.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from xml.sax.saxutils import escape
|
||||
|
||||
from agent.component.base import ComponentParamBase
|
||||
from api.utils.api_utils import timeout
|
||||
from api.utils.file_response import agent_attachment_preview_path
|
||||
from common import settings
|
||||
from common.misc_utils import get_uuid
|
||||
from .message import Message
|
||||
@@ -136,6 +137,7 @@ class DocGenerator(Message, ABC):
|
||||
"mime_type": mime_type,
|
||||
"size": file_size,
|
||||
"base64": file_base64,
|
||||
"preview_url": agent_attachment_preview_path(doc_id, ext=output_format, mime_type=mime_type),
|
||||
"include_download_info_in_content": self._param.include_download_info_in_content,
|
||||
}
|
||||
self.set_output("doc_id", doc_id)
|
||||
|
||||
Reference in New Issue
Block a user