Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/nuxt-mcp/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export interface ModuleOptions {
* @default true
*/
updateVSCodeMcpJson?: boolean
/**
* Update MCP url to `~/.codeium/windsurf/mcp_config.json` automatically
*
* @default true
*/
updateWindsurfMcpJson?: boolean
}

export interface ModuleHooks {
Expand All @@ -36,6 +42,7 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
updateCursorMcpJson: true,
updateVSCodeMcpJson: true,
updateWindsurfMcpJson: true,
},
async setup(options, nuxt) {
const unimport = promiseWithResolve<Unimport>()
Expand All @@ -58,6 +65,10 @@ export default defineNuxtModule<ModuleOptions>({
enabled: !!options.updateVSCodeMcpJson,
serverName: 'nuxt',
},
updateWindsurfMcpJson: {
enabled: !!options.updateWindsurfMcpJson,
serverName: 'nuxt',
},
mcpServerInfo: {
name: 'nuxt',
version,
Expand Down
25 changes: 25 additions & 0 deletions packages/vite-plugin-mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Plugin, ViteDevServer } from 'vite'
import type { ViteMcpOptions } from './types'
import { existsSync } from 'node:fs'
import fs from 'node:fs/promises'
import { homedir } from 'node:os'
import c from 'ansis'
import { join } from 'pathe'
import { searchForWorkspaceRoot } from 'vite'
Expand All @@ -14,6 +15,7 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
mcpPath = '/__mcp',
updateCursorMcpJson = true,
updateVSCodeMcpJson = true,
updateWindsurfMcpJson = true,
printUrl = true,
mcpServer = (vite: ViteDevServer) => import('./server').then(m => m.createMcpServerDefault(options, vite)),
} = options
Expand All @@ -26,6 +28,10 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
? { enabled: updateVSCodeMcpJson }
: updateVSCodeMcpJson

const windsurfMcpOptions = typeof updateWindsurfMcpJson === 'boolean'
? { enabled: updateWindsurfMcpJson }
: updateWindsurfMcpJson

return {
name: 'vite-plugin-mcp',
async configureServer(vite) {
Expand Down Expand Up @@ -65,6 +71,25 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
}
}

if (windsurfMcpOptions.enabled) {
const windsurfDir = join(homedir(), '.codeium', 'windsurf')
const windsurfConfigPath = join(windsurfDir, 'mcp_config.json')
try {
if (!existsSync(windsurfDir)) {
await fs.mkdir(windsurfDir, { recursive: true })
}
const config = existsSync(windsurfConfigPath)
? JSON.parse(await fs.readFile(windsurfConfigPath, 'utf-8').catch(() => '{}') || '{}')
: {}
config.mcpServers ||= {}
config.mcpServers[windsurfMcpOptions.serverName || 'vite'] = { url: sseUrl }
await fs.writeFile(windsurfConfigPath, `${JSON.stringify(config, null, 2)}\n`)
}
catch (e) {
console.error(`${c.red.bold(' ➜ MCP (Windsurf): ')}Failed to update ${windsurfConfigPath}`, e)
}
}

if (printUrl) {
setTimeout(() => {
// eslint-disable-next-line no-console
Expand Down
14 changes: 14 additions & 0 deletions packages/vite-plugin-mcp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ export interface ViteMcpOptions {
*/
serverName?: string
}

/**
* Update the address of the MCP server in the Windsurf config file `~/.codeium/windsurf/mcp_config.json`,
* if Windsurf config file exists.
*
* @default true
*/
updateWindsurfMcpJson?: boolean | {
enabled: boolean
/**
* The name of the MCP server, default is `vite`
*/
serverName?: string
}
}