Skip to content

✂️ refactor: Artifacts and Tool Callbacks to Pass UI Resources#9581

Merged
danny-avila merged 4 commits intodevfrom
refactor/artifacts-ui-resources
Sep 11, 2025
Merged

✂️ refactor: Artifacts and Tool Callbacks to Pass UI Resources#9581
danny-avila merged 4 commits intodevfrom
refactor/artifacts-ui-resources

Conversation

@danny-avila
Copy link
Copy Markdown
Owner

@danny-avila danny-avila commented Sep 11, 2025

Originally #9472


Summary

By @samuelpath

I recently shipped the 2 followings PRs to enable a basic integration with MCP-UI:

The approach I took to pass the UI resources received from the MCP Server tool response to the front-end was to use a content item of type text and passing the UI resources array in a new metadata property.

This worked but the issue is that these content items of type text are passed as such the LLMs. We have been lucky so far since all the LLM providers we've tested silently ignored this unknown metadata property. But there is no guarantee that all providers do, nor that existing providers could enforce stricter payload checks.

In order to work around this, we proposed the following PR in the Agents package: danny-avila/agents#16. It would remove the metadata property just before the call to the LLM would be made. However, this was rightly rejected by @danny-avila who explained that there was a better way, using callbacks.

This PR now uses @danny-avila's recommended approach with the callbacks.

Here's the idea:

  • Create a new artifact type for the UI resources Tools.ui_resources
  • Add the UI Resources as artifacts and not in the LLM content
  • The callback is called after the LLM is being called, in which we can parse the artifacts as LLM content attachment
  • We pass the attachments from ToolCall to ToolCallInfo
  • We parse the attachments of type UI Resources in ToolCallInfo to render them

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

See the 2 PRs mentioned above. The behaviour tested is the same.

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.

@danny-avila danny-avila merged commit 180046a into dev Sep 11, 2025
7 checks passed
@danny-avila danny-avila deleted the refactor/artifacts-ui-resources branch September 11, 2025 18:34
@samuelpath
Copy link
Copy Markdown
Contributor

Thanks @danny-avila, I find the PR cleaner with your follow-up changes!

Also, thank you for 2 things:

  • For cherry-picking my commit and keeping my authorship
  • For adding follow-up commits in an atomic way with a clear separation of concerns

I appreciate how you've been taking some our suggestions into account here for smoother collaboration, this means a lot. Thanks!

arbreton pushed a commit to arbreton/LibreChat that referenced this pull request Oct 9, 2025
…-avila#9581)

* ✂️ refactor: use artifacts and callbacks to pass UI resources

* chore: imports

* refactor: Update UIResource type imports and definitions across components and tests

* refactor: Update ToolCallInfo test data structure and enhance TAttachment type definition

---------

Co-authored-by: Samuel Path <samuel.path@shopify.com>
Guiraud pushed a commit to Guiraud/LibreChat that referenced this pull request Nov 21, 2025
…-avila#9581)

* ✂️ refactor: use artifacts and callbacks to pass UI resources

* chore: imports

* refactor: Update UIResource type imports and definitions across components and tests

* refactor: Update ToolCallInfo test data structure and enhance TAttachment type definition

---------

Co-authored-by: Samuel Path <samuel.path@shopify.com>
patricksn3ll pushed a commit to patricksn3ll/LibreChat that referenced this pull request Dec 11, 2025
…-avila#9581)

* ✂️ refactor: use artifacts and callbacks to pass UI resources

* chore: imports

* refactor: Update UIResource type imports and definitions across components and tests

* refactor: Update ToolCallInfo test data structure and enhance TAttachment type definition

---------

Co-authored-by: Samuel Path <samuel.path@shopify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants