Skip to content

MCP tool result attachments ignore resource URI for filename #507

Description

@vsevolodkolonistov

QuickApps version

latest

What steps will reproduce the bug?

Configure a Quick App with an MCP toolset whose tools return file attachments as EmbeddedResource with BlobResourceContents

Ensure the MCP tool sets a descriptive filename in the resource.uri] field (e.g. file:///my_report_ar_20260812-153000.docx), so the downstream consumer can use it as the attachment name.

Trigger a conversation that causes the agent to call the MCP tool and produce a file attachment in the response.

Observe the resulting attachment filename surfaced in the chat UI - it follows the pattern <tool_name>-. instead of using the filename from the resource.uri field.

What is the expected behavior?

When an MCP tool returns an EmbeddedResource containing BlobResourceContents with a uri field (e.g. file:///my_report_ar_20260812-153000.docx), the orchestrator should extract the filename from the URI's path segment and use it as the attachment title. This allows MCP tools to control the output filename and provide meaningful, descriptive names to the end user. Only when the uri field is absent or empty should the orchestrator fall back to generating a default filename based on the tool name and timestamp.

What do you see instead?

<tool_name>-.

Additional information

Suggested fix:

In the _content_to_attachment method of the MCP tool executor (src/quickapp/mcp_tooling/_mcp_tool.py), when processing a resource-type content item, the resource.uri field should be parsed to extract the filename before falling back to the default filename generator.

The existing helper filename_from_url_path (already available in common/utils) extracts the URL-decoded last path segment from a URI. The following change fixes the issue for me, however I cannot tell what side effects it may have:

from quickapp.common.utils import (
filename_from_url_path,
generate_attachment_filename,
matches_type,
)
...
uri_str = str(resource.uri) if getattr(resource, "uri", None) else ""
uri_filename = filename_from_url_path(uri_str) if uri_str else None
title = uri_filename or generate_attachment_filename(
getattr(resource, "mimeType", None), base_filename=self.__tool.name
)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions