Skip to content

Commit c90bb7f

Browse files
committed
feat(vite): support .vscode/mcp.json
1 parent c686290 commit c90bb7f

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

packages/nuxt-mcp/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export default defineNuxtConfig({
2121

2222
Then the MCP server will be available at `http://localhost:3000/__mcp/sse`.
2323

24-
If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
24+
- If you are using VSCode, create a `.vscode/mcp.json` file in your project root, this plugin will automatically update it for you.
25+
- If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
2526

2627
## Module Hooks
2728

28-
For other modules to provide information to MCP, you can use the `mcp:setup` hook.
29+
For other modules to provide additional information to MCP, you can use the `mcp:setup` hook.
2930

3031
```ts
3132
// src/module.ts

packages/nuxt-mcp/src/module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export interface ModuleOptions {
1515
* @default true
1616
*/
1717
updateCursorMcpJson?: boolean
18+
/**
19+
* Update MCP url to `.vscode/mcp.json` automatically
20+
*
21+
* @default true
22+
*/
23+
updateVSCodeMcpJson?: boolean
1824
}
1925

2026
export interface ModuleHooks {
@@ -28,6 +34,7 @@ export default defineNuxtModule<ModuleOptions>({
2834
},
2935
defaults: {
3036
updateCursorMcpJson: true,
37+
updateVSCodeMcpJson: true,
3138
},
3239
async setup(options, nuxt) {
3340
const unimport = promiseWithResolve<Unimport>()
@@ -46,6 +53,10 @@ export default defineNuxtModule<ModuleOptions>({
4653
enabled: !!options.updateCursorMcpJson,
4754
serverName: 'nuxt',
4855
},
56+
updateVSCodeMcpJson: {
57+
enabled: !!options.updateVSCodeMcpJson,
58+
serverName: 'nuxt',
59+
},
4960
mcpServerInfo: {
5061
name: 'nuxt',
5162
version,

packages/vite-plugin-mcp/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export default defineConfig({
2424

2525
Then the MCP server will be available at `http://localhost:5173/__mcp/sse`.
2626

27-
If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
27+
- If you are using VSCode, create a `.vscode/mcp.json` file in your project root, this plugin will automatically update it for you.
28+
- If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
2829

2930
## Sponsors
3031

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
1313
const {
1414
mcpPath = '/__mcp',
1515
updateCursorMcpJson = true,
16+
updateVSCodeMcpJson = true,
1617
printUrl = true,
1718
mcpServer = (vite: ViteDevServer) => import('./server').then(m => m.createMcpServerDefault(options, vite)),
1819
} = options
@@ -21,6 +22,10 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
2122
? { enabled: updateCursorMcpJson }
2223
: updateCursorMcpJson
2324

25+
const vscodeMcpOptions = typeof updateVSCodeMcpJson == 'boolean'
26+
? { enabled: updateVSCodeMcpJson }
27+
: updateVSCodeMcpJson
28+
2429
return {
2530
name: 'vite-plugin-mcp',
2631
async configureServer(vite) {
@@ -44,6 +49,21 @@ export function ViteMcp(options: ViteMcpOptions = {}): Plugin {
4449
}
4550
}
4651

52+
if (vscodeMcpOptions.enabled) {
53+
const vscodeConfig = join(root, '.vscode/settings.json')
54+
if (existsSync(vscodeConfig)) {
55+
const mcp = existsSync(join(root, '.vscode/mcp.json'))
56+
? JSON.parse(await fs.readFile(join(root, '.vscode/mcp.json'), 'utf-8') || '{}')
57+
: {}
58+
mcp.servers ||= {}
59+
mcp.servers[vscodeMcpOptions.serverName || 'vite'] = {
60+
type: 'sse',
61+
url: sseUrl,
62+
}
63+
await fs.writeFile(join(root, '.vscode/mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
64+
}
65+
}
66+
4767
if (printUrl) {
4868
setTimeout(() => {
4969
// 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
@@ -57,4 +57,18 @@ export interface ViteMcpOptions {
5757
*/
5858
serverName?: string
5959
}
60+
61+
/**
62+
* Update the address of the MCP server in the VSCode config file `settings.json`,
63+
* if VSCode config file exists.
64+
*
65+
* @default true
66+
*/
67+
updateVSCodeMcpJson?: boolean | {
68+
enabled: boolean
69+
/**
70+
* The name of the MCP server, default is `vite`
71+
*/
72+
serverName?: string
73+
}
6074
}

0 commit comments

Comments
 (0)