diff --git a/apps/create-webmcp-app/templates/react/src/App.tsx b/apps/create-webmcp-app/templates/react/src/App.tsx index 63873fc..9ed1107 100644 --- a/apps/create-webmcp-app/templates/react/src/App.tsx +++ b/apps/create-webmcp-app/templates/react/src/App.tsx @@ -32,11 +32,9 @@ import { z } from 'zod'; * ``` */ export default function App() { - // Track connection to parent window const [isReady, setIsReady] = useState(false); const [message, setMessage] = useState('Hello from WebMCP Template!'); - // Listen for parent ready event useEffect(() => { const handleMessage = (event: MessageEvent) => { if (event.data?.type === 'parent_ready') { @@ -46,7 +44,6 @@ export default function App() { window.addEventListener('message', handleMessage); - // Notify parent we're ready window.parent.postMessage({ type: 'iframe_ready' }, '*'); return () => window.removeEventListener('message', handleMessage); @@ -109,7 +106,6 @@ export default function App() { }, }); - // Handle UI button click const handleUpdateClick = useCallback(() => { const newMessage = prompt('Enter new message:'); if (newMessage) { @@ -126,7 +122,6 @@ export default function App() {

WebMCP Template

- {/* Connection status */}
{isReady ? (
@@ -141,12 +136,10 @@ export default function App() { )}
- {/* Current message display */}

{message}

- {/* Action buttons */}
- {/* Info about registered tools */}

Registered WebMCP Tools:

    diff --git a/apps/create-webmcp-app/templates/react/src/main.tsx b/apps/create-webmcp-app/templates/react/src/main.tsx index 05df969..f475ef2 100644 --- a/apps/create-webmcp-app/templates/react/src/main.tsx +++ b/apps/create-webmcp-app/templates/react/src/main.tsx @@ -10,17 +10,14 @@ import { createRoot } from 'react-dom/client'; import App from './App.tsx'; import './index.css'; -// Initialize WebMCP transport -// This sets up communication with the parent window via postMessage initializeWebModelContext({ transport: { tabServer: { - allowedOrigins: ['*'], // Allow any origin for iframe communication + allowedOrigins: ['*'], }, }, }); -// Mount React app createRoot(document.getElementById('root')!).render( diff --git a/apps/create-webmcp-app/templates/react/worker/index.ts b/apps/create-webmcp-app/templates/react/worker/index.ts index 2d31a3f..708cfec 100644 --- a/apps/create-webmcp-app/templates/react/worker/index.ts +++ b/apps/create-webmcp-app/templates/react/worker/index.ts @@ -12,7 +12,6 @@ export { TemplateMCP }; */ const app = new Hono<{ Bindings: Env }>(); -// Apply CORS middleware to all routes app.use( '/*', cors({ @@ -22,7 +21,6 @@ app.use( }) ); -// Route SSE (Server-Sent Events) endpoints app.all('/sse/*', async (c) => { return await TemplateMCP.serveSSE('/sse').fetch(c.req.raw, c.env, c.executionCtx); }); @@ -31,17 +29,14 @@ app.all('/sse', async (c) => { return await TemplateMCP.serveSSE('/sse').fetch(c.req.raw, c.env, c.executionCtx); }); -// Route MCP protocol endpoint app.all('/mcp', async (c) => { return await TemplateMCP.serve('/mcp').fetch(c.req.raw, c.env, c.executionCtx); }); -// 404 handler for unmatched routes app.notFound((c) => { return c.json({ error: 'Not found', path: c.req.path }, 404); }); -// Error handler app.onError((error, c) => { console.error('Worker error:', error); return c.json( diff --git a/apps/create-webmcp-app/templates/react/worker/mcpServer.ts b/apps/create-webmcp-app/templates/react/worker/mcpServer.ts index b391e11..d4da04c 100644 --- a/apps/create-webmcp-app/templates/react/worker/mcpServer.ts +++ b/apps/create-webmcp-app/templates/react/worker/mcpServer.ts @@ -49,9 +49,6 @@ Use this as a starting point to build your own interactive apps!`, {}, async () => { try { - // Construct iframe URL from environment variable - // In dev: http://localhost:8888 - // In prod: https://your-worker.workers.dev const iframeUrl = `${this.env.APP_URL}/`; const uiResource = createUIResource({ diff --git a/apps/create-webmcp-app/templates/vanilla/public/index.html b/apps/create-webmcp-app/templates/vanilla/public/index.html index 15e263f..472bfc5 100644 --- a/apps/create-webmcp-app/templates/vanilla/public/index.html +++ b/apps/create-webmcp-app/templates/vanilla/public/index.html @@ -5,10 +5,8 @@ WebMCP Template - Vanilla - -