@@ -27,6 +27,9 @@ app.get('/mcp-use/widgets/:widget', (req, res, next) => {
2727 res . sendFile ( filePath , err => ( err ? next ( ) : undefined ) )
2828} )
2929
30+ // Pass the Express app to MCP for SSE transport
31+ mcp . setExpressApp ( app )
32+
3033// Start Express server
3134const PORT = process . env . PORT || 3000
3235app . listen ( PORT , ( ) => {
@@ -44,7 +47,9 @@ mcp.resource({
4447 name : 'ui-mcp-server' ,
4548 version : '1.0.0' ,
4649 status : 'running' ,
50+ transport : process . env . MCP_TRANSPORT || 'http' ,
4751 uiEndpoint : `http://localhost:${ PORT } /mcp-use/widgets` ,
52+ mcpEndpoint : process . env . MCP_TRANSPORT === 'stdio' ? 'stdio' : `http://localhost:${ PORT } /mcp` ,
4853 availableWidgets : [ 'kanban-board' , 'todo-list' , 'data-visualization' ] ,
4954 timestamp : new Date ( ) . toISOString ( ) ,
5055 } , null , 2 )
@@ -221,7 +226,21 @@ console.log(`🌐 UI Server: http://localhost:${PORT}`)
221226console . log ( '📦 Resources: ui://status, ui://widget/kanban-board, ui://widget/todo-list, ui://widget/data-visualization' )
222227console . log ( '🛠️ Tools: show-kanban, show-todo-list, show-data-viz' )
223228console . log ( '💬 Prompts: ui-development' )
224- console . log ( '✅ Server ready!' )
225229
226- // Start the MCP server
227- mcp . serve ( ) . catch ( console . error )
230+ // Start the MCP server with HTTP by default (use MCP_TRANSPORT=stdio env var for stdio)
231+ console . log ( '📡 Setting up MCP server...' )
232+ mcp . serve ( {
233+ transport : process . env . MCP_TRANSPORT as 'http' | 'stdio' || 'http' ,
234+ endpoint : '/mcp'
235+ } ) . then ( ( ) => {
236+ const transport = process . env . MCP_TRANSPORT || 'http'
237+ if ( transport === 'http' ) {
238+ console . log ( `📡 MCP server accessible at: http://localhost:${ PORT } /mcp` )
239+ console . log ( '✅ Server ready! Connect with MCP clients via HTTP (StreamableHTTP transport)' )
240+ }
241+ else {
242+ console . log ( '✅ Server ready! Connect with MCP clients via stdio' )
243+ }
244+ } ) . catch ( ( error ) => {
245+ console . error ( '❌ Failed to start MCP server:' , error )
246+ } )
0 commit comments