-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add MCP Apps support to Inspector #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cliffhall
wants to merge
33
commits into
main
Choose a base branch
from
claude/issue-1041-20260126-2214
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,048
−55
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d8092cf
Fix MCP Apps rendering issue and add comprehensive logging
github-actions[bot] 689bc3f
Fix MCP Apps iframe rendering issue
github-actions[bot] cc7ab7f
Fix MCP Apps HTML extraction to match spec
github-actions[bot] eb11d46
Add comprehensive tests for MCP Apps support
github-actions[bot] 5cc25db
Add MCP Apps support to Inspector
github-actions[bot] 3b054b4
Prefer structuredContent over content field in tool responses
github-actions[bot] 939f3fa
Revert "Prefer structuredContent over content field in tool responses"
cliffhall b5b5910
feat: integrate @mcp-ui/client for MCP application rendering
cliffhall 9a16f13
Potential fix for code scanning alert no. 37: Client-side cross-site …
cliffhall b4000df
Update package-lock.json
cliffhall 6f4c294
Potential fix for code scanning alert no. 38: Client-side cross-site …
cliffhall 6ec23b8
Potential fix for code scanning alert no. 39: Client-side cross-site …
cliffhall 700d24f
prettier
cliffhall 7871e6e
Update client/src/components/AppsTab.tsx
cliffhall 211ad3c
prettier
cliffhall e5dbe4c
In AppsTab.test.tsx, fetch button by aria-label
cliffhall 7c4e9df
relative imports
cliffhall 4a84f25
Remove sanitization logic from sandbox_proxy.html. It's breaking the …
cliffhall 8b70df5
In sandbox_proxy.html,formatting
cliffhall d7c3ef3
In AppsTab.tsx, if an app has no inputSchema, just show it, otherwise…
cliffhall 529ca11
In AppRenderer.tsx,
cliffhall 853d789
In AppRenderer.test.tsx, and AppsTab.test.tsx
cliffhall b1a4435
Serving the sandbox_proxy.html from a separate port, using the proxy …
cliffhall 00ee07b
In client.js
cliffhall d107fb4
In vite.config.ts
cliffhall 35b7fff
Potential fix for code scanning alert no. 41: Missing rate limiting
cliffhall 9fd260b
In AppRenderer.tsx
cliffhall cde8190
In sandbox_proxy.html
cliffhall 47ed9e0
prettier
cliffhall 1204b86
In AppRenderer.tsx
cliffhall f10a27a
Add logging message handler to AppRenderer
cliffhall 3c076bd
In AppRenderer.tsx
cliffhall 2677536
In AppRenderer.test.tsx
cliffhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { useMemo, useState } from "react"; | ||
| import { Client } from "@modelcontextprotocol/sdk/client/index.js"; | ||
| import { | ||
| Tool, | ||
| ContentBlock, | ||
| ServerNotification, | ||
| LoggingMessageNotificationParams, | ||
| } from "@modelcontextprotocol/sdk/types.js"; | ||
| import { | ||
| AppRenderer as McpUiAppRenderer, | ||
| type McpUiHostContext, | ||
| type RequestHandlerExtra, | ||
| } from "@mcp-ui/client"; | ||
| import { | ||
| type McpUiMessageRequest, | ||
| type McpUiMessageResult, | ||
| } from "@modelcontextprotocol/ext-apps/app-bridge"; | ||
| import { Alert, AlertDescription } from "@/components/ui/alert"; | ||
| import { AlertCircle } from "lucide-react"; | ||
| import { useToast } from "@/lib/hooks/useToast"; | ||
|
|
||
| interface AppRendererProps { | ||
| sandboxPath: string; | ||
| tool: Tool; | ||
| mcpClient: Client | null; | ||
| toolInput?: Record<string, unknown>; | ||
| onNotification?: (notification: ServerNotification) => void; | ||
| } | ||
|
|
||
| const AppRenderer = ({ | ||
| sandboxPath, | ||
| tool, | ||
| mcpClient, | ||
| toolInput, | ||
| onNotification, | ||
| }: AppRendererProps) => { | ||
| const [error, setError] = useState<string | null>(null); | ||
| const { toast } = useToast(); | ||
|
|
||
| const hostContext: McpUiHostContext = useMemo( | ||
| () => ({ | ||
| theme: document.documentElement.classList.contains("dark") | ||
| ? "dark" | ||
| : "light", | ||
| }), | ||
| [], | ||
| ); | ||
|
|
||
| const handleOpenLink = async ({ url }: { url: string }) => { | ||
| let isError = true; | ||
| if (url.startsWith("https://") || url.startsWith("http://")) { | ||
| window.open(url, "_blank"); | ||
| isError = false; | ||
| } | ||
| return { isError }; | ||
| }; | ||
|
|
||
| const handleMessage = async ( | ||
| params: McpUiMessageRequest["params"], | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| _extra: RequestHandlerExtra, | ||
| ): Promise<McpUiMessageResult> => { | ||
| const message = params.content | ||
| .filter((block): block is ContentBlock & { type: "text" } => | ||
| Boolean(block.type === "text"), | ||
| ) | ||
| .map((block) => block.text) | ||
| .join("\n"); | ||
|
|
||
| if (message) { | ||
| toast({ | ||
| description: message, | ||
| }); | ||
| } | ||
|
|
||
| return {}; | ||
| }; | ||
|
|
||
| const handleLoggingMessage = (params: LoggingMessageNotificationParams) => { | ||
| if (onNotification) { | ||
| onNotification({ | ||
| method: "notifications/message", | ||
| params, | ||
| } as ServerNotification); | ||
| } | ||
| }; | ||
|
|
||
| if (!mcpClient) { | ||
| return ( | ||
| <Alert> | ||
| <AlertCircle className="h-4 w-4" /> | ||
| <AlertDescription>Waiting for MCP client...</AlertDescription> | ||
| </Alert> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col h-full"> | ||
| {error && ( | ||
| <Alert variant="destructive" className="mb-4"> | ||
| <AlertCircle className="h-4 w-4" /> | ||
| <AlertDescription>{error}</AlertDescription> | ||
| </Alert> | ||
| )} | ||
|
|
||
| <div | ||
| className="flex-1 border rounded overflow-hidden" | ||
| style={{ minHeight: "400px" }} | ||
| > | ||
| <McpUiAppRenderer | ||
cliffhall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client={mcpClient} | ||
| onOpenLink={handleOpenLink} | ||
| onMessage={handleMessage} | ||
| onLoggingMessage={handleLoggingMessage} | ||
| toolName={tool.name} | ||
| hostContext={hostContext} | ||
| toolInput={toolInput} | ||
| sandbox={{ | ||
| url: new URL(sandboxPath, window.location.origin), | ||
| }} | ||
| onError={(err) => setError(err.message)} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppRenderer; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.