💻 feat: Deeper MCP UI integration in the Chat UI (#9669)

* 💻 feat: deeper MCP UI integration in the chat UI using plugins

---------

Co-authored-by: Samuel Path <samuel.path@shopify.com>
Co-authored-by: Pierre-Luc Godin <pierreluc.godin@shopify.com>

* 💻 refactor: Migrate MCP UI resources from index-based to ID-based referencing

- Replace index-based resource markers with stable resource IDs
- Update plugin to parse \ui{resourceId} format instead of \ui0
- Refactor components to use useMessagesOperations instead of useSubmitMessage
- Add ShareMessagesProvider for UI resources in share view
- Add useConversationUIResources hook for cross-turn resource lookups
- Update parsers to generate resource IDs from content hashes
- Update all tests to use resource IDs instead of indices
- Add sandbox permissions for iframe popups
- Remove deprecated MCP tool context instructions

---------

Co-authored-by: Pierre-Luc Godin <pierreluc.godin@shopify.com>
This commit is contained in:
Samuel Path 2025-12-11 22:02:38 +01:00 committed by Danny Avila
parent 4a0fbb07bc
commit 304bba853c
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
27 changed files with 1545 additions and 122 deletions

View file

@ -0,0 +1,44 @@
import React, { useMemo } from 'react';
import type { TMessage } from 'librechat-data-provider';
import { MessagesViewContext } from '~/Providers/MessagesViewContext';
import type { MessagesViewContextValue } from '~/Providers/MessagesViewContext';
interface ShareMessagesProviderProps {
messages: TMessage[];
children: React.ReactNode;
}
/**
* Minimal MessagesViewContext provider for share view.
* Provides conversation data needed by message components.
* Uses the same MessagesViewContext as the main app for compatibility with existing hooks.
*
* Note: conversationId is set to undefined because share view is read-only and doesn't
* need to check Recoil state for in-flight messages during streaming.
*/
export function ShareMessagesProvider({ messages, children }: ShareMessagesProviderProps) {
const contextValue = useMemo<MessagesViewContextValue>(
() => ({
conversation: { conversationId: 'shared-conversation' },
conversationId: undefined,
// These are required by the context but not used in share view
ask: () => Promise.resolve(),
regenerate: () => {},
handleContinue: () => {},
latestMessage: messages[messages.length - 1] ?? null,
isSubmitting: false,
isSubmittingFamily: false,
abortScroll: false,
setAbortScroll: () => {},
index: 0,
setLatestMessage: () => {},
getMessages: () => messages,
setMessages: () => {},
}),
[messages],
);
return (
<MessagesViewContext.Provider value={contextValue}>{children}</MessagesViewContext.Provider>
);
}

View file

@ -21,6 +21,7 @@ import { ShareArtifactsContainer } from './ShareArtifacts';
import { useLocalize, useDocumentTitle } from '~/hooks';
import { useGetStartupConfig } from '~/data-provider';
import { ShareContext } from '~/Providers';
import { ShareMessagesProvider } from './ShareMessagesProvider';
import MessagesView from './MessagesView';
import Footer from '../Chat/Footer';
import { cn } from '~/utils';
@ -108,7 +109,9 @@ function SharedView() {
onLangChange={handleLangChange}
settingsLabel={localize('com_nav_settings')}
/>
<MessagesView messagesTree={messagesTree} conversationId={data.conversationId} />
<ShareMessagesProvider messages={data.messages}>
<MessagesView messagesTree={messagesTree} conversationId="shared-conversation" />
</ShareMessagesProvider>
</>
);
} else {