From bbcd65b9b4cb68fbaa726f4a3132d842b2c41793 Mon Sep 17 00:00:00 2001 From: 20syldev Date: Thu, 9 Apr 2026 20:47:15 +0200 Subject: [PATCH] fix: use project directory name as MCP server name in monorepos In a monorepo with multiple Nuxt apps, every app was writing its MCP entry under the same key ('nuxt') in .cursor/mcp.json, .vscode/mcp.json and .mcp.json. Each new dev server start would overwrite the previous app's entry, leaving only one server registered. Derive the default updateConfigServerName from the project's root directory basename (e.g. 'nuxt-app-web', 'nuxt-app-admin') so that each app gets its own stable key. Users can still set updateConfigServerName explicitly in their nuxt.config to choose a custom name. Fixes #31 --- packages/nuxt-mcp-dev/src/module.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/nuxt-mcp-dev/src/module.ts b/packages/nuxt-mcp-dev/src/module.ts index c20ad13..43a6156 100644 --- a/packages/nuxt-mcp-dev/src/module.ts +++ b/packages/nuxt-mcp-dev/src/module.ts @@ -2,6 +2,7 @@ import type { Nitro } from 'nitropack' import type { Unimport } from 'unimport' import type { ViteMcpOptions } from 'vite-plugin-mcp' import type { McpToolContext } from './types' +import { basename } from 'node:path' import { addVitePlugin, defineNuxtModule } from '@nuxt/kit' import { ViteMcp } from 'vite-plugin-mcp' import { promptNuxtBasic } from './prompts/basic' @@ -44,8 +45,14 @@ export default defineNuxtModule({ nitro.resolve(_nitro) }) + // Derive a unique server name from the project directory so that multiple + // Nuxt apps in a monorepo each get their own entry in the MCP config file + // instead of overwriting each other's "nuxt" key. Falls back to 'nuxt' + // when the user has explicitly set updateConfigServerName. + const defaultServerName = `nuxt-${basename(nuxt.options.rootDir)}` + addVitePlugin(ViteMcp({ - updateConfigServerName: 'nuxt', + updateConfigServerName: defaultServerName, ...options, updateConfigAdditionalServers: [ ...options.updateConfigAdditionalServers || [],