Skip to content

Commit 635453d

Browse files
authored
feat: support Claude Code config (#24)
1 parent 040f9ca commit 635453d

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

packages/nuxt-mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineNuxtConfig({
2121

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

24-
> 💡 When using VSCode, Cursor, Windsurf, the module will automatically update the config files for you.
24+
> 💡 When using VSCode, Cursor, Windsurf, Claude Code, the module will automatically update the config files for you.
2525
2626
## Module Hooks
2727

packages/vite-plugin-mcp/README.md

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

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

27-
> 💡 When using VSCode, Cursor, Windsurf, the module will automatically update the config files for you.
27+
> 💡 When using VSCode, Cursor, Windsurf, Claude Code, the module will automatically update the config files for you.
2828
>
2929
> You can configure that in the options with `updateConfig` and `updateConfigServerName`.
3030

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async function updateConfigs(
6262
existsSync(join(root, '.cursor')) ? 'cursor' as const : null,
6363
existsSync(join(root, '.vscode')) ? 'vscode' as const : null,
6464
existsSync(join(homedir(), '.codeium', 'windsurf')) ? 'windsurf' as const : null,
65+
existsSync(join(root, '.mcp.json')) ? 'claude-code' as const : null,
6566
].filter(x => x !== null)
6667
: Array.isArray(updateConfig)
6768
? updateConfig
@@ -124,4 +125,24 @@ async function updateConfigs(
124125
vite.config.logger.error(`${CONSOLE_LOG_PREFIX}${c.red(`Failed to update ${windsurfConfigPath}`)}${e}`)
125126
}
126127
}
128+
129+
// Claude Code
130+
if (configs.includes('claude-code')) {
131+
const mcp = existsSync(join(root, '.mcp.json'))
132+
? JSON.parse(await fs.readFile(join(root, '.mcp.json'), 'utf-8') || '{}')
133+
: {}
134+
mcp.mcpServers ||= {}
135+
mcp.mcpServers[updateConfigServerName || 'vite'] = {
136+
type: 'sse',
137+
url: sseUrl,
138+
}
139+
for (const server of updateConfigAdditionalServers) {
140+
mcp.mcpServers[server.name] = {
141+
type: 'sse',
142+
url: server.url,
143+
}
144+
}
145+
await fs.writeFile(join(root, '.mcp.json'), `${JSON.stringify(mcp, null, 2)}\n`)
146+
vite.config.logger.info(`${CONSOLE_LOG_PREFIX}${c.gray(`Updated config file ${join(root, '.mcp.json')}`)}`)
147+
}
127148
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33
import type { Implementation as McpServerInfo } from '@modelcontextprotocol/sdk/types.js'
44
import type { ViteDevServer } from 'vite'
55

6-
export type SupportedUpdateConfigType = 'cursor' | 'vscode' | 'windsurf'
6+
export type SupportedUpdateConfigType = 'cursor' | 'vscode' | 'windsurf' | 'claude-code'
77

88
export interface UpdateConfigAdditionalServer {
99
name: string
@@ -60,6 +60,7 @@ export interface ViteMcpOptions {
6060
* - `cursor` - Update the cursor config file `.cursor/mcp.json`
6161
* - `vscode` - Update the VSCode config file `.vscode/settings.json`
6262
* - `windsurf` - Update the Windsurf config file `~/.codeium/windsurf/mcp_config.json`
63+
* - `claude-code` - Update the Claude Code config file `.mcp.json`
6364
*
6465
* @default 'auto'
6566
*/

0 commit comments

Comments
 (0)