diff --git a/packages/demo-server/components/StockDashboard.tsx b/packages/demo-server/components/StockDashboard.tsx index a1a1abc..242c30c 100644 --- a/packages/demo-server/components/StockDashboard.tsx +++ b/packages/demo-server/components/StockDashboard.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { generateMockStockData } from './stock-utils'; -import { callTool, sendPrompt, useProps } from '@mcp-ui/library/ui'; +import { callTool, sendPrompt, useProps } from 'mcp-ui-kit/ui'; // Types for props passed from the tool handler diff --git a/packages/library/server/bundle.ts b/packages/library/server/bundle.ts index c813d0c..53f6081 100644 --- a/packages/library/server/bundle.ts +++ b/packages/library/server/bundle.ts @@ -7,6 +7,7 @@ const bundleCache = new Map(); const isDev = process.env.NODE_ENV !== 'production'; async function runBuild(entryPath: string): Promise> { + console.log('[mcp-ui-kit] runBuild called for:', entryPath); return esbuild.build({ entryPoints: [entryPath], bundle: true, @@ -23,15 +24,24 @@ async function runBuild(entryPath: string): Promise { + console.log('[mcp-ui-kit] bundleComponent called for:', entryPath); + console.log('[mcp-ui-kit] isDev:', isDev, 'NODE_ENV:', process.env.NODE_ENV); + console.log('[mcp-ui-kit] Cache has entry:', bundleCache.has(entryPath)); + if (!isDev && bundleCache.has(entryPath)) { + console.log('[mcp-ui-kit] Returning cached bundle'); return bundleCache.get(entryPath)!; } let result: esbuild.BuildResult<{ write: false }>; try { + console.log('[mcp-ui-kit] Attempting first build...'); result = await runBuild(entryPath); + console.log('[mcp-ui-kit] First build succeeded'); } catch (error) { + console.log('[mcp-ui-kit] First build failed:', error instanceof Error ? error.message : error); + // Handle esbuild service errors in serverless environments (Vercel, Lambda, etc.) // This happens when the serverless runtime freezes/stops the esbuild subprocess. const isServiceError = error instanceof Error && ( @@ -39,20 +49,26 @@ export async function bundleComponent(entryPath: string): Promise { error.message.includes('service is no longer running') || error.message.includes('The service') ); + console.log('[mcp-ui-kit] Is service error:', isServiceError); + if (isServiceError) { // Force stop the dead service, then retry - esbuild will start fresh + console.log('[mcp-ui-kit] Stopping esbuild service and retrying...'); await esbuild.stop(); result = await runBuild(entryPath); + console.log('[mcp-ui-kit] Retry succeeded'); } else { throw error; } } const bundledJS = result.outputFiles[0].text; + console.log('[mcp-ui-kit] Bundle size:', bundledJS.length, 'bytes'); // Only cache in production mode if (!isDev) { bundleCache.set(entryPath, bundledJS); + console.log('[mcp-ui-kit] Bundle cached'); } return bundledJS;