-
Notifications
You must be signed in to change notification settings - Fork 327
feat: add proxy option to externalUrl #37
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0a5d631
feat: add proxy option to externalUrl
idosal 3155932
rename
idosal 6c19784
fix sizing
idosal 4380774
add external url
idosal 3a3f4b5
fix docs
idosal 136d72c
security
idosal 401d8b7
fix docs
idosal 8671501
prettier
idosal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <meta | ||
| http-equiv="Content-Security-Policy" | ||
| content="frame-src 'self' https://proxy.mcpui.dev;" | ||
| /> | ||
| <title>MCP-UI Proxy Demo</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
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,29 @@ | ||
| { | ||
| "name": "external-url-demo", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc -b && vite build", | ||
| "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "@mcp-ui/client": "workspace:*", | ||
| "react": "^18.3.1", | ||
| "react-dom": "^18.3.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^18.3.23", | ||
| "@types/react-dom": "^18.3.7", | ||
| "@typescript-eslint/eslint-plugin": "^7.18.0", | ||
| "@typescript-eslint/parser": "^7.18.0", | ||
| "@vitejs/plugin-react": "^4.6.0", | ||
| "eslint": "^9.29.0", | ||
| "eslint-plugin-react-hooks": "^5.2.0", | ||
| "eslint-plugin-react-refresh": "0.4.7", | ||
| "typescript": "~5.8.3", | ||
| "vite": "^6.3.5" | ||
| } | ||
| } |
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,43 @@ | ||
| body { | ||
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; | ||
| max-width: 1200px; | ||
| margin: 0 auto; | ||
| padding: 2rem; | ||
| line-height: 1.6; | ||
| } | ||
| .demo-section { | ||
| margin: 2rem 0; | ||
| padding: 1rem; | ||
| border: 1px solid #ddd; | ||
| border-radius: 8px; | ||
| } | ||
| .demo-section h2 { | ||
| margin-top: 0; | ||
| color: #333; | ||
| } | ||
| iframe { | ||
| width: 100%; | ||
| min-height: 400px; | ||
| border: 1px solid #ccc; | ||
| border-radius: 4px; | ||
| } | ||
| .code { | ||
| background: #f5f5f5; | ||
| padding: 1rem; | ||
| border-radius: 4px; | ||
| font-family: 'Courier New', monospace; | ||
| font-size: 0.9em; | ||
| margin: 1rem 0; | ||
| } | ||
| .toggle { | ||
| background: #007bff; | ||
| color: white; | ||
| border: none; | ||
| padding: 0.5rem 1rem; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| margin: 1rem 0; | ||
| } | ||
| .toggle:hover { | ||
| background: #0056b3; | ||
| } |
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,75 @@ | ||
| import { useState } from 'react'; | ||
| import './App.css'; | ||
| import { UIResourceRenderer } from '@mcp-ui/client'; | ||
|
|
||
| function App() { | ||
| const [useProxy, setUseProxy] = useState(false); | ||
| const resource = { | ||
| mimeType: 'text/uri-list', | ||
| text: 'https://example.com', | ||
| }; | ||
| const proxy = 'https://proxy.mcpui.dev/'; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1>MCP-UI Proxy Demo</h1> | ||
| <p>This demo shows how the proxy functionality works for external URLs in MCP-UI.</p> | ||
| <p> | ||
| <strong>CSP Simulation:</strong> This page includes a Content Security Policy ( | ||
| <code>frame-src 'self' https://proxy.mcpui.dev;</code>) that only allows iframes from this | ||
| origin and <code>https://proxy.mcpui.dev</code>. This demonstrates how the{' '} | ||
| <code>proxy</code> prop can be used to display external content on hosts with strict | ||
| security policies. | ||
| </p> | ||
| <p> | ||
| <code>proxy.mcpui.dev</code> hosts a simple script that renders the provided URL in a nested | ||
| iframe. Hosts can use this script or host their own to achieve the same result. | ||
| </p> | ||
|
|
||
| <div className="demo-section"> | ||
| <h2>Direct URL (No Proxy)</h2> | ||
| <p> | ||
| This iframe attempts to load an external URL directly.{' '} | ||
| <strong>It should be blocked by the browser's Content Security Policy.</strong> | ||
| </p> | ||
| <div className="code"> | ||
| Resource: {`{ mimeType: 'text/uri-list', text: 'https://example.com' }`} | ||
| </div> | ||
| <UIResourceRenderer resource={{ mimeType: 'text/uri-list', text: 'https://example.com' }} /> | ||
| </div> | ||
|
|
||
| <div className="demo-section"> | ||
| <h2>Proxied URL</h2> | ||
| <p>This iframe loads the external URL through the proxy:</p> | ||
| <div className="code"> | ||
| Resource: {`{ mimeType: 'text/uri-list', text: 'https://example.com' }`} | ||
| <br /> | ||
| Proxy: https://proxy.mcpui.dev/ | ||
| <br /> | ||
| Final URL: {`${proxy}?url=${encodeURIComponent(resource.text)}`} | ||
| </div> | ||
| <UIResourceRenderer | ||
| resource={resource} | ||
| htmlProps={{ proxy, style: { width: '500px', height: '500px' } }} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="demo-section"> | ||
| <h2>Interactive Demo</h2> | ||
| <p>Toggle between direct and proxied loading:</p> | ||
| <button className="toggle" onClick={() => setUseProxy(!useProxy)}> | ||
| Toggle Proxy | ||
| </button> | ||
| <div id="demo-container"> | ||
| <UIResourceRenderer resource={resource} htmlProps={useProxy ? { proxy } : {}} /> | ||
| </div> | ||
| <div className="code" id="url-display"> | ||
| Current URL:{' '} | ||
| {useProxy ? `${proxy}?url=${encodeURIComponent(resource.text)}` : resource.text} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
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,12 @@ | ||
| body { | ||
| margin: 0; | ||
| font-family: | ||
| -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', | ||
| 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; | ||
| -webkit-font-smoothing: antialiased; | ||
| -moz-osx-font-smoothing: grayscale; | ||
| } | ||
|
|
||
| code { | ||
| font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; | ||
| } |
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,10 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom/client'; | ||
| import App from './App.tsx'; | ||
| import './index.css'; | ||
|
|
||
| ReactDOM.createRoot(document.getElementById('root')!).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
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,25 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", | ||
| "target": "ES2020", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
| "module": "ESNext", | ||
| "skipLibCheck": true, | ||
|
|
||
| /* Bundler mode */ | ||
| "moduleResolution": "bundler", | ||
| "allowImportingTsExtensions": true, | ||
| "verbatimModuleSyntax": true, | ||
| "moduleDetection": "force", | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
|
|
||
| /* Linting */ | ||
| "strict": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "noFallthroughCasesInSwitch": true | ||
| }, | ||
| "include": ["src"] | ||
| } |
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,4 @@ | ||
| { | ||
| "files": [], | ||
| "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }] | ||
| } |
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,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "composite": true, | ||
| "skipLibCheck": true, | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true | ||
| }, | ||
| "include": ["vite.config.ts"] | ||
| } |
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,7 @@ | ||
| import { defineConfig } from 'vite'; | ||
| import react from '@vitejs/plugin-react'; | ||
|
|
||
| // https://vitejs.dev/config/ | ||
| export default defineConfig({ | ||
| plugins: [react()], | ||
| }); |
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,56 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>MCP-UI Proxy</title> | ||
| <style> | ||
| html, | ||
| body { | ||
| margin: 0; | ||
| height: 100vh; | ||
| width: 100vw; | ||
| } | ||
| body { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| iframe { | ||
| background-color: transparent; | ||
| border: 0px none transparent; | ||
| padding: 0px; | ||
| overflow: hidden; | ||
| flex-grow: 1; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| const target = new URLSearchParams(location.search).get('url'); | ||
|
|
||
| // Validate that the URL is a valid HTTP or HTTPS URL | ||
| function isValidHttpUrl(string) { | ||
| try { | ||
| const url = new URL(string); | ||
| return url.protocol === 'http:' || url.protocol === 'https:'; | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (!target) { | ||
| document.body.textContent = 'Error: missing url parameter'; | ||
| } else if (!isValidHttpUrl(target)) { | ||
| document.body.textContent = 'Error: invalid URL. Only HTTP and HTTPS URLs are allowed.'; | ||
| } else { | ||
| const inner = document.createElement('iframe'); | ||
| inner.src = target; | ||
| inner.style = 'width:100%; height:100%; border:none;'; | ||
| inner.sandbox = 'allow-same-origin allow-scripts'; | ||
idosal marked this conversation as resolved.
Show resolved
Hide resolved
idosal marked this conversation as resolved.
Show resolved
Hide resolved
idosal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| document.body.appendChild(inner); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
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
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.