Skip to content

Commit 3990c01

Browse files
committed
feat!: unified options for each editor to updateConfig. Removed updateCursorMcpJson, updateVSCodeMcpJson, updateWindsurfMcpJson
1 parent ebe2b53 commit 3990c01

File tree

3 files changed

+87
-133
lines changed

3 files changed

+87
-133
lines changed

packages/nuxt-mcp/src/module.ts

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
11
import type { Nitro } from 'nitropack'
22
import type { Unimport } from 'unimport'
3+
import type { ViteMcpOptions } from 'vite-plugin-mcp'
34
import type { McpToolContext } from './types'
45
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
56
import { ViteMcp } from 'vite-plugin-mcp'
6-
import { version } from '../package.json'
77
import { promptNuxtBasic } from './prompts/basic'
88
import { toolsNuxtDotComInfo } from './tools/nuxt-dot-com'
99
import { toolsNuxtRuntime } from './tools/runtime'
1010
import { toolsScaffold } from './tools/scaffold'
1111

12-
export interface ModuleOptions {
13-
/**
14-
* Update MCP url to `.cursor/mcp.json` automatically
15-
*
16-
* @default true
17-
*/
18-
updateCursorMcpJson?: boolean
19-
/**
20-
* Update MCP url to `.vscode/mcp.json` automatically
21-
*
22-
* @default true
23-
*/
24-
updateVSCodeMcpJson?: boolean
25-
/**
26-
* Update MCP url to `~/.codeium/windsurf/mcp_config.json` automatically
27-
*
28-
* @default true
29-
*/
30-
updateWindsurfMcpJson?: boolean
12+
export interface ModuleOptions extends ViteMcpOptions {
3113
}
3214

3315
export interface ModuleHooks {
@@ -39,11 +21,7 @@ export default defineNuxtModule<ModuleOptions>({
3921
name: 'nuxt-mcp',
4022
configKey: 'mcp',
4123
},
42-
defaults: {
43-
updateCursorMcpJson: true,
44-
updateVSCodeMcpJson: true,
45-
updateWindsurfMcpJson: true,
46-
},
24+
defaults: {},
4725
async setup(options, nuxt) {
4826
const unimport = promiseWithResolve<Unimport>()
4927
const nitro = promiseWithResolve<Nitro>()
@@ -56,24 +34,12 @@ export default defineNuxtModule<ModuleOptions>({
5634
})
5735

5836
addVitePlugin(ViteMcp({
37+
updateConfigServerName: 'nuxt-local',
38+
...options,
5939
port: nuxt.options.devServer.port,
60-
updateCursorMcpJson: {
61-
enabled: !!options.updateCursorMcpJson,
62-
serverName: 'nuxt',
63-
},
64-
updateVSCodeMcpJson: {
65-
enabled: !!options.updateVSCodeMcpJson,
66-
serverName: 'nuxt',
67-
},
68-
updateWindsurfMcpJson: {
69-
enabled: !!options.updateWindsurfMcpJson,
70-
serverName: 'nuxt',
71-
},
72-
mcpServerInfo: {
73-
name: 'nuxt',
74-
version,
75-
},
7640
async mcpServerSetup(mcp, vite) {
41+
await options.mcpServerSetup?.(mcp, vite)
42+
7743
const context: McpToolContext = {
7844
unimport: unimport.promise,
7945
nitro: nitro.promise,

packages/vite-plugin-mcp/src/index.ts

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,12 @@ export * from './types'
1212

1313
export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
1414
const {
15-
updateCursorMcpJson = true,
16-
updateVSCodeMcpJson = true,
17-
updateWindsurfMcpJson = true,
1815
printUrl = true,
1916
mcpServer = (vite: ViteDevServer) => import('./server').then(m => m.createMcpServerDefault(options, vite)),
2017
} = options
2118

2219
const mcpRoute = options.mcpRouteRoot ?? options.mcpPath ?? '/__mcp'
2320

24-
const cursorMcpOptions = typeof updateCursorMcpJson == 'boolean'
25-
? { enabled: updateCursorMcpJson }
26-
: updateCursorMcpJson
27-
28-
const vscodeMcpOptions = typeof updateVSCodeMcpJson == 'boolean'
29-
? { enabled: updateVSCodeMcpJson }
30-
: updateVSCodeMcpJson
31-
32-
const windsurfMcpOptions = typeof updateWindsurfMcpJson === 'boolean'
33-
? { enabled: updateWindsurfMcpJson }
34-
: updateWindsurfMcpJson
35-
3621
return {
3722
name: 'vite-plugin-mcp',
3823
async configureServer(vite) {
@@ -46,50 +31,7 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
4631
const protocol = vite.config.server.https ? 'https' : 'http'
4732
const sseUrl = `${protocol}://${options.host || 'localhost'}:${options.port || port}${mcpRoute}/sse`
4833

49-
if (cursorMcpOptions.enabled) {
50-
if (existsSync(join(root, '.cursor'))) {
51-
const mcp = existsSync(join(root, '.cursor/mcp.json'))
52-
? JSON.parse(await fs.readFile(join(root, '.cursor/mcp.json'), 'utf-8') || '{}')
53-
: {}
54-
mcp.mcpServers ||= {}
55-
mcp.mcpServers[cursorMcpOptions.serverName || 'vite'] = { url: sseUrl }
56-
await fs.writeFile(join(root, '.cursor/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
57-
}
58-
}
59-
60-
if (vscodeMcpOptions.enabled) {
61-
const vscodeConfig = join(root, '.vscode/settings.json')
62-
if (existsSync(vscodeConfig)) {
63-
const mcp = existsSync(join(root, '.vscode/mcp.json'))
64-
? JSON.parse(await fs.readFile(join(root, '.vscode/mcp.json'), 'utf-8') || '{}')
65-
: {}
66-
mcp.servers ||= {}
67-
mcp.servers[vscodeMcpOptions.serverName || 'vite'] = {
68-
type: 'sse',
69-
url: sseUrl,
70-
}
71-
await fs.writeFile(join(root, '.vscode/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
72-
}
73-
}
74-
75-
if (windsurfMcpOptions.enabled) {
76-
const windsurfDir = join(homedir(), '.codeium', 'windsurf')
77-
const windsurfConfigPath = join(windsurfDir, 'mcp_config.json')
78-
try {
79-
if (!existsSync(windsurfDir)) {
80-
await fs.mkdir(windsurfDir, { recursive: true })
81-
}
82-
const config = existsSync(windsurfConfigPath)
83-
? JSON.parse(await fs.readFile(windsurfConfigPath, 'utf-8').catch(() => '{}') || '{}')
84-
: {}
85-
config.mcpServers ||= {}
86-
config.mcpServers[windsurfMcpOptions.serverName || 'vite'] = { url: sseUrl }
87-
await fs.writeFile(windsurfConfigPath, `${JSON.stringify(config, null, 2)}\n`)
88-
}
89-
catch (e) {
90-
console.error(`${c.red.bold(' ➜ MCP (Windsurf): ')}Failed to update ${windsurfConfigPath}`, e)
91-
}
92-
}
34+
await updateConfigs(root, sseUrl, options)
9335

9436
if (printUrl) {
9537
setTimeout(() => {
@@ -100,3 +42,66 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
10042
},
10143
}
10244
}
45+
46+
async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptions): Promise<void> {
47+
const {
48+
updateConfig = 'auto',
49+
updateConfigServerName = 'vite',
50+
} = options
51+
52+
if (updateConfig === false)
53+
return
54+
55+
const configs = updateConfig === 'auto'
56+
? [
57+
existsSync(join(root, '.cursor')) ? 'cursor' as const : null,
58+
existsSync(join(root, '.vscode')) ? 'vscode' as const : null,
59+
existsSync(join(homedir(), '.codeium', 'windsurf')) ? 'windsurf' as const : null,
60+
].filter(x => x !== null)
61+
: Array.isArray(updateConfig)
62+
? updateConfig
63+
: []
64+
65+
// Cursor
66+
if (configs.includes('cursor')) {
67+
await fs.mkdir(join(root, '.cursor'), { recursive: true })
68+
const mcp = existsSync(join(root, '.cursor/mcp.json'))
69+
? JSON.parse(await fs.readFile(join(root, '.cursor/mcp.json'), 'utf-8') || '{}')
70+
: {}
71+
mcp.mcpServers ||= {}
72+
mcp.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
73+
await fs.writeFile(join(root, '.cursor/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
74+
}
75+
76+
// VSCode
77+
if (configs.includes('vscode')) {
78+
await fs.mkdir(join(root, '.vscode'), { recursive: true })
79+
const mcp = existsSync(join(root, '.vscode/mcp.json'))
80+
? JSON.parse(await fs.readFile(join(root, '.vscode/mcp.json'), 'utf-8') || '{}')
81+
: {}
82+
mcp.servers ||= {}
83+
mcp.servers[updateConfigServerName || 'vite'] = {
84+
type: 'sse',
85+
url: sseUrl,
86+
}
87+
await fs.writeFile(join(root, '.vscode/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
88+
}
89+
90+
// Windsurf
91+
if (configs.includes('windsurf')) {
92+
const windsurfDir = join(homedir(), '.codeium', 'windsurf')
93+
const windsurfConfigPath = join(windsurfDir, 'mcp_config.json')
94+
try {
95+
await fs.mkdir(windsurfDir, { recursive: true })
96+
const config = existsSync(windsurfConfigPath)
97+
? JSON.parse(await fs.readFile(windsurfConfigPath, 'utf-8').catch(() => '{}') || '{}')
98+
: {}
99+
config.mcpServers ||= {}
100+
config.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
101+
await fs.writeFile(windsurfConfigPath, `${JSON.stringify(config, null, 2)}\n`)
102+
}
103+
catch (e) {
104+
console.error(`${c.red.bold(' ➜ MCP (Windsurf): ')}Failed to update ${windsurfConfigPath}`, e)
105+
}
106+
}
107+
}

packages/vite-plugin-mcp/src/types.ts

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33
import type { Implementation as McpServerInfo } from '@modelcontextprotocol/sdk/types.js'
44
import type { ViteDevServer } from 'vite'
55

6+
export type SupportedUpdateConfigType = 'cursor' | 'vscode' | 'windsurf'
7+
8+
export type MaybeArray<T> = T | T[]
9+
610
export type { McpServer }
711

812
export interface ViteMcpOptions {
@@ -45,46 +49,25 @@ export interface ViteMcpOptions {
4549
mcpRouteRoot?: string
4650

4751
/**
48-
* Update the address of the MCP server in the cursor config file `.cursor/mcp.json`,
49-
* if `.cursor` folder exists.
52+
* The config types to update
5053
*
51-
* @default true
52-
*/
53-
updateCursorMcpJson?: boolean | {
54-
enabled: boolean
55-
/**
56-
* The name of the MCP server, default is `vite`
57-
*/
58-
serverName?: string
59-
}
60-
61-
/**
62-
* Update the address of the MCP server in the VSCode config file `settings.json`,
63-
* if VSCode config file exists.
54+
* - `auto` - Automatically update the config files if they exists
55+
* - `cursor` - Update the cursor config file `.cursor/mcp.json`
56+
* - `vscode` - Update the VSCode config file `.vscode/settings.json`
57+
* - `windsurf` - Update the Windsurf config file `~/.codeium/windsurf/mcp_config.json`
6458
*
65-
* @default true
59+
* @default 'auto'
6660
*/
67-
updateVSCodeMcpJson?: boolean | {
68-
enabled: boolean
69-
/**
70-
* The name of the MCP server, default is `vite`
71-
*/
72-
serverName?: string
73-
}
61+
updateConfig?: 'auto' | false | MaybeArray<SupportedUpdateConfigType>
7462

7563
/**
76-
* Update the address of the MCP server in the Windsurf config file `~/.codeium/windsurf/mcp_config.json`,
77-
* if Windsurf config file exists.
64+
* The name of the MCP server when updating the config files
7865
*
79-
* @default true
66+
* @default 'vite'
8067
*/
81-
updateWindsurfMcpJson?: boolean | {
82-
enabled: boolean
83-
/**
84-
* The name of the MCP server, default is `vite`
85-
*/
86-
serverName?: string
87-
}
68+
updateConfigServerName?: string
69+
70+
// --------- DEPRECATED ---------
8871

8972
/**
9073
* @deprecated Use `mcpRouteRoot` instead

0 commit comments

Comments
 (0)