Skip to content

Commit ebbd701

Browse files
antfuatinux
andauthored
feat(nuxt): include remote nuxt mcp by default (#17)
Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 081ec3d commit ebbd701

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

.cursor/mcp.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
},
66
"nuxt": {
77
"url": "http://localhost:4000/__mcp/sse"
8+
},
9+
"nuxt-docs": {
10+
"url": "https://mcp.nuxt.com/sse"
811
}
912
}
1013
}

.vscode/mcp.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"servers": {
3-
"vite": {
3+
"nuxt-local": {
44
"type": "sse",
5-
"url": "http://localhost:5200/__mcp/sse"
5+
"url": "http://localhost:4000/__mcp/sse"
6+
},
7+
"nuxt-docs": {
8+
"type": "sse",
9+
"url": "https://mcp.nuxt.com/sse"
610
}
711
}
812
}

packages/nuxt-mcp/src/module.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import { toolsNuxtRuntime } from './tools/runtime'
1010
import { toolsScaffold } from './tools/scaffold'
1111

1212
export interface ModuleOptions extends ViteMcpOptions {
13+
/**
14+
* Includes the online Nuxt MCP server from https://mcp.nuxt.com/sse
15+
*
16+
* This MCP would provide information about the Nuxt ecosystem, including
17+
* the latest documentation, available modules, etc.
18+
*
19+
* @default true
20+
*/
21+
includeNuxtDocsMcp?: boolean
1322
}
1423

1524
export interface ModuleHooks {
@@ -21,7 +30,9 @@ export default defineNuxtModule<ModuleOptions>({
2130
name: 'nuxt-mcp',
2231
configKey: 'mcp',
2332
},
24-
defaults: {},
33+
defaults: {
34+
includeNuxtDocsMcp: true,
35+
},
2536
async setup(options, nuxt) {
2637
const unimport = promiseWithResolve<Unimport>()
2738
const nitro = promiseWithResolve<Nitro>()
@@ -34,8 +45,18 @@ export default defineNuxtModule<ModuleOptions>({
3445
})
3546

3647
addVitePlugin(ViteMcp({
37-
updateConfigServerName: 'nuxt-local',
48+
updateConfigServerName: 'nuxt',
3849
...options,
50+
updateConfigAdditionalServers: [
51+
...options.updateConfigAdditionalServers || [],
52+
...(
53+
options.includeNuxtDocsMcp
54+
? [{
55+
name: 'nuxt-docs',
56+
url: 'https://mcp.nuxt.com/sse',
57+
}]
58+
: []),
59+
],
3960
port: nuxt.options.devServer.port,
4061
async mcpServerSetup(mcp, vite) {
4162
await options.mcpServerSetup?.(mcp, vite)
@@ -57,7 +78,7 @@ export default defineNuxtModule<ModuleOptions>({
5778
// @ts-ignore skip type infer
5879
await nuxt.callHook('mcp:setup', context)
5980
},
60-
}), { client: true })
81+
}), { client: true, server: false })
6182
},
6283
})
6384

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

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

1111
export * from './types'
1212

13+
const CONSOLE_LOG_PREFIX = c.cyan.bold` ➜ MCP: `
14+
1315
export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
1416
const {
1517
printUrl = true,
@@ -31,14 +33,11 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
3133
const protocol = vite.config.server.https ? 'https' : 'http'
3234
const sseUrl = `${protocol}://${options.host || 'localhost'}:${options.port || port}${mcpRoute}/sse`
3335

34-
await updateConfigs(root, sseUrl, options)
35-
3636
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)}`)}`)
4139
}
40+
await updateConfigs(root, sseUrl, options)
4241
},
4342
}
4443
}
@@ -47,6 +46,7 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
4746
const {
4847
updateConfig = 'auto',
4948
updateConfigServerName = 'vite',
49+
updateConfigAdditionalServers = [],
5050
} = options
5151

5252
if (updateConfig === false)
@@ -70,7 +70,12 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
7070
: {}
7171
mcp.mcpServers ||= {}
7272
mcp.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
73+
for (const server of updateConfigAdditionalServers) {
74+
mcp.mcpServers[server.name] = { url: server.url }
75+
}
7376
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')}`)}`)
7479
}
7580

7681
// VSCode
@@ -84,7 +89,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
8489
type: 'sse',
8590
url: sseUrl,
8691
}
92+
for (const server of updateConfigAdditionalServers) {
93+
mcp.servers[server.name] = {
94+
type: 'sse',
95+
url: server.url,
96+
}
97+
}
8798
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')}`)}`)
88101
}
89102

90103
// Windsurf
@@ -98,10 +111,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
98111
: {}
99112
config.mcpServers ||= {}
100113
config.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
114+
for (const server of updateConfigAdditionalServers) {
115+
config.mcpServers[server.name] = { url: server.url }
116+
}
101117
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}`)}`)
102120
}
103121
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)
105123
}
106124
}
107125
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import type { ViteDevServer } from 'vite'
55

66
export type SupportedUpdateConfigType = 'cursor' | 'vscode' | 'windsurf'
77

8+
export interface UpdateConfigAdditionalServer {
9+
name: string
10+
url: string
11+
}
12+
813
export type MaybeArray<T> = T | T[]
914

1015
export type { McpServer }
@@ -60,6 +65,11 @@ export interface ViteMcpOptions {
6065
*/
6166
updateConfig?: 'auto' | false | MaybeArray<SupportedUpdateConfigType>
6267

68+
/**
69+
* Additional servers to update the config files
70+
*/
71+
updateConfigAdditionalServers?: UpdateConfigAdditionalServer[]
72+
6373
/**
6474
* The name of the MCP server when updating the config files
6575
*

0 commit comments

Comments
 (0)