@@ -10,6 +10,8 @@ import { setupRoutes } from './connect'
10
10
11
11
export * from './types'
12
12
13
+ const CONSOLE_LOG_PREFIX = c . cyan . bold ` ➜ MCP: `
14
+
13
15
export function ViteMcp ( options : ViteMcpOptions = { } ) : Plugin {
14
16
const {
15
17
printUrl = true ,
@@ -31,14 +33,11 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
31
33
const protocol = vite . config . server . https ? 'https' : 'http'
32
34
const sseUrl = `${ protocol } ://${ options . host || 'localhost' } :${ options . port || port } ${ mcpRoute } /sse`
33
35
34
- await updateConfigs ( root , sseUrl , options )
35
-
36
36
if ( printUrl ) {
37
- setTimeout ( ( ) => {
38
- // eslint-disable-next-line no-console
39
- console . log ( `${ c . yellow . bold ` ➜ MCP: ` } Server is running at ${ sseUrl } ` )
40
- } , 300 )
37
+ // eslint-disable-next-line no-console
38
+ console . log ( `${ CONSOLE_LOG_PREFIX } ${ c . gray ( `Mcp server is running at ${ c . green ( sseUrl ) } ` ) } ` )
41
39
}
40
+ await updateConfigs ( root , sseUrl , options )
42
41
} ,
43
42
}
44
43
}
@@ -47,6 +46,7 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
47
46
const {
48
47
updateConfig = 'auto' ,
49
48
updateConfigServerName = 'vite' ,
49
+ updateConfigAdditionalServers = [ ] ,
50
50
} = options
51
51
52
52
if ( updateConfig === false )
@@ -70,7 +70,12 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
70
70
: { }
71
71
mcp . mcpServers ||= { }
72
72
mcp . mcpServers [ updateConfigServerName || 'vite' ] = { url : sseUrl }
73
+ for ( const server of updateConfigAdditionalServers ) {
74
+ mcp . mcpServers [ server . name ] = { url : server . url }
75
+ }
73
76
await fs . writeFile ( join ( root , '.cursor/mcp.json' ) , `${ JSON . stringify ( mcp , null , 2 ) } \n` )
77
+ // eslint-disable-next-line no-console
78
+ console . log ( `${ CONSOLE_LOG_PREFIX } ${ c . gray ( `Updated config file ${ join ( root , '.cursor/mcp.json' ) } ` ) } ` )
74
79
}
75
80
76
81
// VSCode
@@ -84,7 +89,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
84
89
type : 'sse' ,
85
90
url : sseUrl ,
86
91
}
92
+ for ( const server of updateConfigAdditionalServers ) {
93
+ mcp . servers [ server . name ] = {
94
+ type : 'sse' ,
95
+ url : server . url ,
96
+ }
97
+ }
87
98
await fs . writeFile ( join ( root , '.vscode/mcp.json' ) , `${ JSON . stringify ( mcp , null , 2 ) } \n` )
99
+ // eslint-disable-next-line no-console
100
+ console . log ( `${ CONSOLE_LOG_PREFIX } ${ c . gray ( `Updated config file ${ join ( root , '.vscode/mcp.json' ) } ` ) } ` )
88
101
}
89
102
90
103
// Windsurf
@@ -98,10 +111,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
98
111
: { }
99
112
config . mcpServers ||= { }
100
113
config . mcpServers [ updateConfigServerName || 'vite' ] = { url : sseUrl }
114
+ for ( const server of updateConfigAdditionalServers ) {
115
+ config . mcpServers [ server . name ] = { url : server . url }
116
+ }
101
117
await fs . writeFile ( windsurfConfigPath , `${ JSON . stringify ( config , null , 2 ) } \n` )
118
+ // eslint-disable-next-line no-console
119
+ console . log ( `${ CONSOLE_LOG_PREFIX } ${ c . gray ( `Updated config file ${ windsurfConfigPath } ` ) } ` )
102
120
}
103
121
catch ( e ) {
104
- console . error ( `${ c . red . bold ( ' ➜ MCP (Windsurf): ' ) } Failed to update ${ windsurfConfigPath } ` , e )
122
+ console . error ( `${ CONSOLE_LOG_PREFIX } ${ c . red ( ` Failed to update ${ windsurfConfigPath } ` ) } ` , e )
105
123
}
106
124
}
107
125
}
0 commit comments