Skip to content

Commit 40b3c31

Browse files
committed
fix: use vite's builtin logger, close #20
1 parent 59d2356 commit 40b3c31

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

.vscode/mcp.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"servers": {
3-
"nuxt-local": {
4-
"type": "sse",
5-
"url": "http://localhost:4000/__mcp/sse"
6-
},
73
"nuxt-docs": {
84
"type": "sse",
95
"url": "https://mcp.nuxt.com/sse"
106
},
117
"vite": {
128
"type": "sse",
139
"url": "http://localhost:5200/__mcp/sse"
10+
},
11+
"nuxt": {
12+
"type": "sse",
13+
"url": "http://localhost:4000/__mcp/sse"
1414
}
1515
}
1616
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { setupRoutes } from './connect'
1010

1111
export * from './types'
1212

13-
const CONSOLE_LOG_PREFIX = c.cyan.bold`MCP: `
13+
const CONSOLE_LOG_PREFIX = c.cyan.bold`[MCP] `
1414

1515
export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
1616
const {
@@ -35,14 +35,19 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
3535

3636
if (printUrl) {
3737
// eslint-disable-next-line no-console
38-
console.log(`${CONSOLE_LOG_PREFIX}${c.gray(`Mcp server is running at ${c.green(sseUrl)}`)}`)
38+
console.log(`${c.cyan` ➜ MCP: `}${c.gray(`Mcp server is running at ${c.green(sseUrl)}`)}`)
3939
}
40-
await updateConfigs(root, sseUrl, options)
40+
await updateConfigs(root, sseUrl, options, vite)
4141
},
4242
}
4343
}
4444

45-
async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptions): Promise<void> {
45+
async function updateConfigs(
46+
root: string,
47+
sseUrl: string,
48+
options: ViteMcpOptions,
49+
vite: ViteDevServer,
50+
): Promise<void> {
4651
const {
4752
updateConfig = 'auto',
4853
updateConfigServerName = 'vite',
@@ -74,8 +79,7 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
7479
mcp.mcpServers[server.name] = { url: server.url }
7580
}
7681
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')}`)}`)
82+
vite.config.logger.info(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${join(root, '.cursor/mcp.json')}`)}`)
7983
}
8084

8185
// VSCode
@@ -96,8 +100,7 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
96100
}
97101
}
98102
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')}`)}`)
103+
vite.config.logger.info(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${join(root, '.vscode/mcp.json')}`)}`)
101104
}
102105

103106
// Windsurf
@@ -115,11 +118,10 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
115118
config.mcpServers[server.name] = { serverUrl: server.url }
116119
}
117120
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}`)}`)
121+
vite.config.logger.info(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${windsurfConfigPath}`)}`)
120122
}
121123
catch (e) {
122-
console.error(`${CONSOLE_LOG_PREFIX}${c.red(`Failed to update ${windsurfConfigPath}`)}`, e)
124+
vite.config.logger.error(`${CONSOLE_LOG_PREFIX}${c.red(`Failed to update ${windsurfConfigPath}`)}${e}`)
123125
}
124126
}
125127
}

0 commit comments

Comments
 (0)