Skip to content

Commit d3eb6b5

Browse files
authored
feat: support the windsurf mcp config (#15)
1 parent 77c7a04 commit d3eb6b5

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

packages/nuxt-mcp/src/module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export interface ModuleOptions {
2222
* @default true
2323
*/
2424
updateVSCodeMcpJson?: boolean
25+
/**
26+
* Update MCP url to `~/.codeium/windsurf/mcp_config.json` automatically
27+
*
28+
* @default true
29+
*/
30+
updateWindsurfMcpJson?: boolean
2531
}
2632

2733
export interface ModuleHooks {
@@ -36,6 +42,7 @@ export default defineNuxtModule<ModuleOptions>({
3642
defaults: {
3743
updateCursorMcpJson: true,
3844
updateVSCodeMcpJson: true,
45+
updateWindsurfMcpJson: true,
3946
},
4047
async setup(options, nuxt) {
4148
const unimport = promiseWithResolve<Unimport>()
@@ -58,6 +65,10 @@ export default defineNuxtModule<ModuleOptions>({
5865
enabled: !!options.updateVSCodeMcpJson,
5966
serverName: 'nuxt',
6067
},
68+
updateWindsurfMcpJson: {
69+
enabled: !!options.updateWindsurfMcpJson,
70+
serverName: 'nuxt',
71+
},
6172
mcpServerInfo: {
6273
name: 'nuxt',
6374
version,

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Plugin, ViteDevServer } from 'vite'
22
import type { ViteMcpOptions } from './types'
33
import { existsSync } from 'node:fs'
44
import fs from 'node:fs/promises'
5+
import { homedir } from 'node:os'
56
import c from 'ansis'
67
import { join } from 'pathe'
78
import { searchForWorkspaceRoot } from 'vite'
@@ -14,6 +15,7 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
1415
mcpPath = '/__mcp',
1516
updateCursorMcpJson = true,
1617
updateVSCodeMcpJson = true,
18+
updateWindsurfMcpJson = true,
1719
printUrl = true,
1820
mcpServer = (vite: ViteDevServer) => import('./server').then(m => m.createMcpServerDefault(options, vite)),
1921
} = options
@@ -26,6 +28,10 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
2628
? { enabled: updateVSCodeMcpJson }
2729
: updateVSCodeMcpJson
2830

31+
const windsurfMcpOptions = typeof updateWindsurfMcpJson === 'boolean'
32+
? { enabled: updateWindsurfMcpJson }
33+
: updateWindsurfMcpJson
34+
2935
return {
3036
name: 'vite-plugin-mcp',
3137
async configureServer(vite) {
@@ -65,6 +71,25 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
6571
}
6672
}
6773

74+
if (windsurfMcpOptions.enabled) {
75+
const windsurfDir = join(homedir(), '.codeium', 'windsurf')
76+
const windsurfConfigPath = join(windsurfDir, 'mcp_config.json')
77+
try {
78+
if (!existsSync(windsurfDir)) {
79+
await fs.mkdir(windsurfDir, { recursive: true })
80+
}
81+
const config = existsSync(windsurfConfigPath)
82+
? JSON.parse(await fs.readFile(windsurfConfigPath, 'utf-8').catch(() => '{}') || '{}')
83+
: {}
84+
config.mcpServers ||= {}
85+
config.mcpServers[windsurfMcpOptions.serverName || 'vite'] = { url: sseUrl }
86+
await fs.writeFile(windsurfConfigPath, `${JSON.stringify(config, null, 2)}\n`)
87+
}
88+
catch (e) {
89+
console.error(`${c.red.bold(' ➜ MCP (Windsurf): ')}Failed to update ${windsurfConfigPath}`, e)
90+
}
91+
}
92+
6893
if (printUrl) {
6994
setTimeout(() => {
7095
// eslint-disable-next-line no-console

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,18 @@ export interface ViteMcpOptions {
7171
*/
7272
serverName?: string
7373
}
74+
75+
/**
76+
* Update the address of the MCP server in the Windsurf config file `~/.codeium/windsurf/mcp_config.json`,
77+
* if Windsurf config file exists.
78+
*
79+
* @default true
80+
*/
81+
updateWindsurfMcpJson?: boolean | {
82+
enabled: boolean
83+
/**
84+
* The name of the MCP server, default is `vite`
85+
*/
86+
serverName?: string
87+
}
7488
}

0 commit comments

Comments
 (0)