Skip to content

Commit 0a271e8

Browse files
committed
feat: init
1 parent 2ad9f71 commit 0a271e8

File tree

14 files changed

+1419
-116
lines changed

14 files changed

+1419
-116
lines changed

.cursor/mcp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"mcpServers": {
33
"vite": {
4-
"url": "http://localhost:5173/__mcp/sse"
4+
"url": "http://localhost:5200/__mcp/sse"
55
},
66
"nuxt": {
7-
"url": "http://localhost:3000/__mcp/sse"
7+
"url": "http://localhost:4000/__mcp/sse"
88
}
99
}
1010
}

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
# nuxt-mcp
1+
# nuxt-mcp / vite-plugin-mcp
22

33
[![npm version][npm-version-src]][npm-version-href]
44
[![npm downloads][npm-downloads-src]][npm-downloads-href]
55
[![bundle][bundle-src]][bundle-href]
66
[![JSDocs][jsdocs-src]][jsdocs-href]
77
[![License][license-src]][license-href]
88

9-
MCP server helping models to understand your Nuxt app better.
9+
MCP server helping models to understand your Vite/Nuxt app better.
10+
11+
This monorepo contains two packages:
12+
13+
- [`nuxt-mcp`](./packages/nuxt-mcp) - A Nuxt module for adding MCP support to your Nuxt app.
14+
- [`vite-plugin-mcp`](./packages/vite-plugin-mcp) - A Vite plugin for adding MCP support to your Vite app.
15+
16+
> [!IMPORTANT]
17+
> Experimental. Not ready for production.
1018
1119
## Sponsors
1220

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
"lint": "eslint",
1111
"release": "bumpp -r && pnpm -r publish",
1212
"test": "vitest",
13+
"inspect": "npx @modelcontextprotocol/inspector",
1314
"typecheck": "tsc --noEmit",
1415
"prepare": "simple-git-hooks && nr -r dev:prepare"
1516
},
1617
"devDependencies": {
1718
"@antfu/eslint-config": "catalog:cli",
1819
"@antfu/ni": "catalog:cli",
1920
"@antfu/utils": "catalog:utils",
21+
"@modelcontextprotocol/inspector": "catalog:",
2022
"@modelcontextprotocol/sdk": "catalog:prod",
2123
"@types/js-yaml": "catalog:testing",
2224
"@types/node": "catalog:types",

packages/nuxt-mcp/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# nuxt-mcp
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![bundle][bundle-src]][bundle-href]
6+
[![JSDocs][jsdocs-src]][jsdocs-href]
7+
[![License][license-src]][license-href]
8+
9+
MCP server helping models to understand your Nuxt app better.
10+
11+
> [!IMPORTANT]
12+
> Experimental. Not ready for production.
13+
14+
```ts
15+
// nuxt.config.ts
16+
17+
export default defineNuxtConfig({
18+
modules: ['nuxt-mcp'],
19+
})
20+
```
21+
22+
Then the MCP server will be available at `http://localhost:3000/__mcp/sse`.
23+
24+
If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
25+
26+
## Sponsors
27+
28+
<p align="center">
29+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
30+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
31+
</a>
32+
</p>
33+
34+
## License
35+
36+
[MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu)
37+
38+
<!-- Badges -->
39+
40+
[npm-version-src]: https://img.shields.io/npm/v/nuxt-mcp?style=flat&colorA=080f12&colorB=1fa669
41+
[npm-version-href]: https://npmjs.com/package/nuxt-mcp
42+
[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-mcp?style=flat&colorA=080f12&colorB=1fa669
43+
[npm-downloads-href]: https://npmjs.com/package/nuxt-mcp
44+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/nuxt-mcp?style=flat&colorA=080f12&colorB=1fa669&label=minzip
45+
[bundle-href]: https://bundlephobia.com/result?p=nuxt-mcp
46+
[license-src]: https://img.shields.io/github/license/antfu/nuxt-mcp.svg?style=flat&colorA=080f12&colorB=1fa669
47+
[license-href]: https://github.com/antfu/nuxt-mcp/blob/main/LICENSE
48+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
49+
[jsdocs-href]: https://www.jsdocs.io/package/nuxt-mcp

packages/nuxt-mcp/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
"scripts": {
2626
"build": "nuxt-module-build build",
2727
"prepublishOnly": "nr build",
28-
"play": "DEBUG=nuxt:mcp:server nuxi dev playground",
28+
"play": "DEBUG=nuxt:mcp:server,vite:mcp:server PORT=4000 nuxi dev playground",
2929
"play:build": "nuxi build playground",
3030
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground"
3131
},
32+
"peerDependencies": {
33+
"nuxt": ">=3.5.0"
34+
},
3235
"dependencies": {
3336
"@modelcontextprotocol/sdk": "catalog:prod",
3437
"@nuxt/kit": "catalog:nuxt",
3538
"debug": "catalog:",
3639
"pathe": "catalog:",
40+
"unimport": "catalog:",
3741
"vite-plugin-mcp": "workspace:*",
3842
"zod": "catalog:prod"
3943
},

packages/nuxt-mcp/src/module.ts

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,106 @@
1-
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
1+
import type { Component } from '@nuxt/schema'
2+
import type { Unimport } from 'unimport'
23
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
34
import { ViteMcp } from 'vite-plugin-mcp'
45
import { version } from '../package.json'
56

6-
// Module options TypeScript interface definition
7-
export interface ModuleOptions {}
7+
export interface ModuleOptions {
8+
/**
9+
* Update MCP url to `.cursor/mcp.json` automatically
10+
*
11+
* @default true
12+
*/
13+
updateCursorMcpJson?: boolean
14+
}
815

916
export default defineNuxtModule<ModuleOptions>({
1017
meta: {
1118
name: 'nuxt-mcp',
1219
configKey: 'mcp',
1320
},
1421
// Default configuration options of the Nuxt module
15-
defaults: {},
16-
async setup(_options, nuxt) {
22+
defaults: {
23+
updateCursorMcpJson: true,
24+
},
25+
async setup(options, nuxt) {
26+
let unimport: Unimport
27+
let components: Component[] = []
28+
nuxt.hook('imports:context', (_unimport) => {
29+
unimport = _unimport
30+
})
31+
nuxt.hook('components:extend', (_components) => {
32+
components = _components
33+
})
34+
1735
addVitePlugin(ViteMcp({
36+
port: nuxt.options.devServer.port,
37+
updateCursorMcpJson: {
38+
enabled: !!options.updateCursorMcpJson,
39+
serverName: 'nuxt',
40+
},
1841
mcpServerInfo: {
1942
name: 'nuxt',
2043
version,
2144
},
22-
mcpServerSetup(server) {
23-
server.resource(
24-
'nuxt',
25-
new ResourceTemplate('nuxt://{name}', { list: undefined }),
26-
async (uri, { name }) => {
45+
mcpServerSetup(mcp) {
46+
mcp.tool(
47+
'get-nuxt-config',
48+
'Get the Nuxt configuration',
49+
{},
50+
async () => {
2751
return {
28-
contents: [{ uri: uri.href, text: `Hello, ${name}!` }],
52+
content: [{
53+
type: 'text',
54+
text: JSON.stringify({
55+
ssr: !!nuxt.options.ssr,
56+
appDir: nuxt.options.appDir,
57+
srcDir: nuxt.options.srcDir,
58+
rootDir: nuxt.options.rootDir,
59+
alias: nuxt.options.alias,
60+
runtimeConfig: {
61+
public: nuxt.options.runtimeConfig.public,
62+
},
63+
modules: nuxt.options._installedModules.map(i => i.meta.name || (i as any).name).filter(Boolean),
64+
imports: {
65+
autoImport: !!nuxt.options.imports.autoImport,
66+
...nuxt.options.imports,
67+
},
68+
components: nuxt.options.components,
69+
}),
70+
}],
71+
}
72+
},
73+
)
74+
75+
mcp.tool(
76+
'get-nuxt-auto-imports-items',
77+
'Get the Nuxt configuration as JSON',
78+
{},
79+
async () => {
80+
return {
81+
content: [{
82+
type: 'text',
83+
text: JSON.stringify({
84+
items: await unimport.getImports(),
85+
}),
86+
}],
87+
}
88+
},
89+
)
90+
91+
mcp.tool(
92+
'get-nuxt-components',
93+
'Get components registered in the Nuxt app',
94+
{},
95+
async () => {
96+
return {
97+
content: [{
98+
type: 'text',
99+
text: JSON.stringify(components),
100+
}],
29101
}
30102
},
31103
)
32-
},
33-
port: nuxt.options.devServer.port,
34-
updateCursorMcpJson: {
35-
enabled: true,
36-
serverName: 'nuxt',
37104
},
38105
}))
39106
},

packages/vite-plugin-mcp/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vite-plugin-mcp
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![bundle][bundle-src]][bundle-href]
6+
[![JSDocs][jsdocs-src]][jsdocs-href]
7+
[![License][license-src]][license-href]
8+
9+
Vite plugin that enables a MCP server for your Vite app to provide information about your setup and modules graphs.
10+
11+
> [!IMPORTANT]
12+
> Experimental. Not ready for production.
13+
14+
```ts
15+
import { defineConfig } from 'vite'
16+
import { ViteMcp } from 'vite-plugin-mcp'
17+
18+
export default defineConfig({
19+
plugins: [
20+
ViteMcp()
21+
],
22+
})
23+
```
24+
25+
Then the MCP server will be available at `http://localhost:5173/__mcp/sse`.
26+
27+
If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
28+
29+
## Sponsors
30+
31+
<p align="center">
32+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
33+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
34+
</a>
35+
</p>
36+
37+
## License
38+
39+
[MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu)
40+
41+
<!-- Badges -->
42+
43+
[npm-version-src]: https://img.shields.io/npm/v/vite-plugin-mcp?style=flat&colorA=080f12&colorB=1fa669
44+
[npm-version-href]: https://npmjs.com/package/vite-plugin-mcp
45+
[npm-downloads-src]: https://img.shields.io/npm/dm/vite-plugin-mcp?style=flat&colorA=080f12&colorB=1fa669
46+
[npm-downloads-href]: https://npmjs.com/package/vite-plugin-mcp
47+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/vite-plugin-mcp?style=flat&colorA=080f12&colorB=1fa669&label=minzip
48+
[bundle-href]: https://bundlephobia.com/result?p=vite-plugin-mcp
49+
[license-src]: https://img.shields.io/github/license/antfu/vite-plugin-mcp.svg?style=flat&colorA=080f12&colorB=1fa669
50+
[license-href]: https://github.com/antfu/vite-plugin-mcp/blob/main/LICENSE
51+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
52+
[jsdocs-href]: https://www.jsdocs.io/package/vite-plugin-mcp

packages/vite-plugin-mcp/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"prepublishOnly": "nr build",
3737
"start": "nodemon --exec 'tsx src/server.ts'"
3838
},
39+
"peerDependencies": {
40+
"vite": ">=6.0.0"
41+
},
3942
"dependencies": {
4043
"@modelcontextprotocol/sdk": "catalog:prod",
4144
"debug": "catalog:",

packages/vite-plugin-mcp/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"private": true,
66
"scripts": {
7-
"dev": "vite",
7+
"dev": "DEBUG=vite:mcp:server vite",
88
"build": "vite build",
99
"preview": "vite preview"
1010
}

packages/vite-plugin-mcp/playground/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export default defineConfig({
55
plugins: [
66
ViteMcp(),
77
],
8+
server: {
9+
port: 5200,
10+
},
811
})

0 commit comments

Comments
 (0)