@@ -178,7 +178,7 @@ async function launchStudio(coursePath: string, options: StudioOptions) {
178178 console . log ( chalk . gray ( ` Express API: ${ expressManager . getConnectionDetails ( ) . url } ` ) ) ;
179179
180180 // Display MCP connection information
181- const mcpInfo = getMCPConnectionInfo ( unpackResult , couchDBManager ) ;
181+ const mcpInfo = getMCPConnectionInfo ( unpackResult , couchDBManager , resolvedPath ) ;
182182 console . log ( chalk . blue ( `🔗 MCP Server: ${ mcpInfo . command } ` ) ) ;
183183 console . log ( chalk . gray ( ` Connect MCP clients using the command above` ) ) ;
184184 console . log ( chalk . gray ( ` Environment variables for MCP:` ) ) ;
@@ -187,7 +187,7 @@ async function launchStudio(coursePath: string, options: StudioOptions) {
187187 } ) ;
188188
189189 // Display .mcp.json content for Claude Code integration
190- const mcpJsonContent = generateMCPJson ( unpackResult , couchDBManager ) ;
190+ const mcpJsonContent = generateMCPJson ( unpackResult , couchDBManager , resolvedPath ) ;
191191 console . log ( chalk . blue ( `📋 .mcp.json content:` ) ) ;
192192 console . log ( chalk . gray ( mcpJsonContent ) ) ;
193193
@@ -1240,18 +1240,63 @@ export default defineConfig({
12401240 console . log ( chalk . gray ( ` Vite config replaced with standalone version` ) ) ;
12411241}
12421242
1243+ /**
1244+ * Determine the correct MCP server executable path/command based on project context
1245+ */
1246+ function resolveMCPExecutable ( projectPath : string ) : {
1247+ command : string ;
1248+ args : string [ ] ;
1249+ isNpx : boolean ;
1250+ } {
1251+ // Check if we're in the monorepo (packages/cli exists)
1252+ const monorepoCliPath = path . join ( projectPath , 'packages' , 'cli' , 'dist' , 'mcp-server.js' ) ;
1253+ if ( fs . existsSync ( monorepoCliPath ) ) {
1254+ return {
1255+ command : './packages/cli/dist/mcp-server.js' ,
1256+ args : [ ] ,
1257+ isNpx : false ,
1258+ } ;
1259+ }
1260+
1261+ // Check if @vue -skuilder/cli is installed as a dependency
1262+ const scaffoldedCliPath = path . join ( projectPath , 'node_modules' , '@vue-skuilder' , 'cli' , 'dist' , 'mcp-server.js' ) ;
1263+ if ( fs . existsSync ( scaffoldedCliPath ) ) {
1264+ return {
1265+ command : './node_modules/@vue-skuilder/cli/dist/mcp-server.js' ,
1266+ args : [ ] ,
1267+ isNpx : false ,
1268+ } ;
1269+ }
1270+
1271+ // Fallback to npx approach
1272+ return {
1273+ command : 'npx' ,
1274+ args : [ '@vue-skuilder/cli' , 'mcp-server' ] ,
1275+ isNpx : true ,
1276+ } ;
1277+ }
1278+
12431279/**
12441280 * Generate MCP connection information for studio session
12451281 */
12461282function getMCPConnectionInfo (
12471283 unpackResult : UnpackResult ,
1248- couchDBManager : CouchDBManager
1284+ couchDBManager : CouchDBManager ,
1285+ projectPath : string
12491286) : { command : string ; env : Record < string , string > } {
1250- const mcpServerPath = path . join ( __dirname , 'mcp-server.js' ) ;
12511287 const couchDetails = couchDBManager . getConnectionDetails ( ) ;
1288+ const executable = resolveMCPExecutable ( projectPath ) ;
1289+
1290+ // Build command string for display
1291+ let commandStr : string ;
1292+ if ( executable . isNpx ) {
1293+ commandStr = `${ executable . command } ${ executable . args . join ( ' ' ) } ${ unpackResult . databaseName } ${ couchDetails . port } ` ;
1294+ } else {
1295+ commandStr = `node ${ executable . command } ${ unpackResult . databaseName } ${ couchDetails . port } ` ;
1296+ }
12521297
12531298 return {
1254- command : `node ${ mcpServerPath } ${ unpackResult . databaseName } ${ couchDetails . port } ` ,
1299+ command : commandStr ,
12551300 env : {
12561301 COUCHDB_SERVER_URL : couchDetails . url . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ,
12571302 COUCHDB_SERVER_PROTOCOL : couchDetails . url . startsWith ( 'https' ) ? 'https' : 'http' ,
@@ -1267,19 +1312,18 @@ function getMCPConnectionInfo(
12671312function generateMCPJson (
12681313 unpackResult : UnpackResult ,
12691314 couchDBManager : CouchDBManager ,
1315+ projectPath : string ,
12701316 serverName : string = 'vue-skuilder-studio'
12711317) : string {
12721318 const couchDetails = couchDBManager . getConnectionDetails ( ) ;
12731319 const port = couchDetails . port || 5985 ;
1274-
1275- // Use relative path to mcp-server.js for portability
1276- const mcpServerRelativePath = './packages/cli/dist/mcp-server.js' ;
1320+ const executable = resolveMCPExecutable ( projectPath ) ;
12771321
12781322 const mcpConfig = {
12791323 mcpServers : {
12801324 [ serverName ] : {
1281- command : mcpServerRelativePath ,
1282- args : [ unpackResult . databaseName , port . toString ( ) ] ,
1325+ command : executable . command ,
1326+ args : [ ... executable . args , unpackResult . databaseName , port . toString ( ) ] ,
12831327 env : {
12841328 COUCHDB_SERVER_URL : couchDetails . url . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ,
12851329 COUCHDB_SERVER_PROTOCOL : couchDetails . url . startsWith ( 'https' ) ? 'https' : 'http' ,
0 commit comments