Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion .cursor/mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"vite": {
"url": "http://localhost:5200/__mcp/sse"
},
"nuxt": {
"nuxt-local": {
"url": "http://localhost:4000/__mcp/sse"
},
"nuxt-docs": {
"url": "https://mcp.nuxt.space/sse"
}
}
}
8 changes: 6 additions & 2 deletions .vscode/mcp.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"servers": {
"vite": {
"nuxt-local": {
"type": "sse",
"url": "http://localhost:5200/__mcp/sse"
"url": "http://localhost:4000/__mcp/sse"
},
"nuxt-docs": {
"type": "sse",
"url": "https://mcp.nuxt.space/sse"
}
}
}
25 changes: 23 additions & 2 deletions packages/nuxt-mcp/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import { toolsNuxtRuntime } from './tools/runtime'
import { toolsScaffold } from './tools/scaffold'

export interface ModuleOptions extends ViteMcpOptions {
/**
* Includes the online Nuxt MCP server from https://mcp.nuxt.space/sse
*
* This MCP would provide information about the Nuxt ecosystem, including
* the latest documentation, available modules, etc.
*
* @default true
*/
includeNuxtDocsMcp?: boolean
}

export interface ModuleHooks {
Expand All @@ -21,7 +30,9 @@ export default defineNuxtModule<ModuleOptions>({
name: 'nuxt-mcp',
configKey: 'mcp',
},
defaults: {},
defaults: {
includeNuxtDocsMcp: true,
},
async setup(options, nuxt) {
const unimport = promiseWithResolve<Unimport>()
const nitro = promiseWithResolve<Nitro>()
Expand All @@ -36,6 +47,16 @@ export default defineNuxtModule<ModuleOptions>({
addVitePlugin(ViteMcp({
updateConfigServerName: 'nuxt-local',
...options,
updateConfigAdditionalServers: [
...options.updateConfigAdditionalServers || [],
...(
options.includeNuxtDocsMcp
? [{
name: 'nuxt-docs',
url: 'https://mcp.nuxt.space/sse',
}]
: []),
],
port: nuxt.options.devServer.port,
async mcpServerSetup(mcp, vite) {
await options.mcpServerSetup?.(mcp, vite)
Expand All @@ -57,7 +78,7 @@ export default defineNuxtModule<ModuleOptions>({
// @ts-ignore skip type infer
await nuxt.callHook('mcp:setup', context)
},
}), { client: true })
}), { client: true, server: false })
},
})

Expand Down
32 changes: 25 additions & 7 deletions packages/vite-plugin-mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { setupRoutes } from './connect'

export * from './types'

const CONSOLE_LOG_PREFIX = c.cyan.bold` ➜ MCP: `

export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
const {
printUrl = true,
Expand All @@ -31,14 +33,11 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
const protocol = vite.config.server.https ? 'https' : 'http'
const sseUrl = `${protocol}://${options.host || 'localhost'}:${options.port || port}${mcpRoute}/sse`

await updateConfigs(root, sseUrl, options)

if (printUrl) {
setTimeout(() => {
// eslint-disable-next-line no-console
console.log(`${c.yellow.bold` ➜ MCP: `}Server is running at ${sseUrl}`)
}, 300)
// eslint-disable-next-line no-console
console.log(`${CONSOLE_LOG_PREFIX}${c.gray(`Mcp server is running at ${c.green(sseUrl)}`)}`)
}
await updateConfigs(root, sseUrl, options)
},
}
}
Expand All @@ -47,6 +46,7 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
const {
updateConfig = 'auto',
updateConfigServerName = 'vite',
updateConfigAdditionalServers = [],
} = options

if (updateConfig === false)
Expand All @@ -70,7 +70,12 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
: {}
mcp.mcpServers ||= {}
mcp.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
for (const server of updateConfigAdditionalServers) {
mcp.mcpServers[server.name] = { url: server.url }
}
await fs.writeFile(join(root, '.cursor/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
// eslint-disable-next-line no-console
console.log(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${join(root, '.cursor/mcp.json')}`)}`)
}

// VSCode
Expand All @@ -84,7 +89,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
type: 'sse',
url: sseUrl,
}
for (const server of updateConfigAdditionalServers) {
mcp.servers[server.name] = {
type: 'sse',
url: server.url,
}
}
await fs.writeFile(join(root, '.vscode/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
// eslint-disable-next-line no-console
console.log(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${join(root, '.vscode/mcp.json')}`)}`)
}

// Windsurf
Expand All @@ -98,10 +111,15 @@ async function updateConfigs(root: string, sseUrl: string, options: ViteMcpOptio
: {}
config.mcpServers ||= {}
config.mcpServers[updateConfigServerName || 'vite'] = { url: sseUrl }
for (const server of updateConfigAdditionalServers) {
config.mcpServers[server.name] = { url: server.url }
}
await fs.writeFile(windsurfConfigPath, `${JSON.stringify(config, null, 2)}\n`)
// eslint-disable-next-line no-console
console.log(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${windsurfConfigPath}`)}`)
}
catch (e) {
console.error(`${c.red.bold(' ➜ MCP (Windsurf): ')}Failed to update ${windsurfConfigPath}`, e)
console.error(`${CONSOLE_LOG_PREFIX}${c.red(`Failed to update ${windsurfConfigPath}`)}`, e)
}
}
}
10 changes: 10 additions & 0 deletions packages/vite-plugin-mcp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type { ViteDevServer } from 'vite'

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

export interface UpdateConfigAdditionalServer {
name: string
url: string
}

export type MaybeArray<T> = T | T[]

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

/**
* Additional servers to update the config files
*/
updateConfigAdditionalServers?: UpdateConfigAdditionalServer[]

/**
* The name of the MCP server when updating the config files
*
Expand Down