Skip to content

Commit c686290

Browse files
committed
feat: support module hooks
1 parent 223c708 commit c686290

File tree

7 files changed

+1027
-1717
lines changed

7 files changed

+1027
-1717
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This monorepo contains two packages:
1414
- [`vite-plugin-mcp`](./packages/vite-plugin-mcp) - A Vite plugin for adding MCP support to your Vite app.
1515

1616
> [!IMPORTANT]
17-
> Experimental. Not ready for production.
17+
> Experimental. Use with caution.
1818
1919
## Sponsors
2020

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "module",
33
"version": "0.0.3",
44
"private": true,
5-
"packageManager": "pnpm@10.6.5",
5+
"packageManager": "pnpm@10.8.0",
66
"scripts": {
77
"build": "pnpm -r run build",
88
"dev": "pnpm -r run dev",

packages/nuxt-mcp/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
MCP server helping models to understand your Nuxt app better.
1010

1111
> [!IMPORTANT]
12-
> Experimental. Not ready for production.
12+
> Experimental. Use with caution.
1313
1414
```ts
1515
// nuxt.config.ts
@@ -23,6 +23,34 @@ Then the MCP server will be available at `http://localhost:3000/__mcp/sse`.
2323

2424
If you are using Cursor, create a `.cursor/mcp.json` file in your project root, this plugin will automatically update it for you.
2525

26+
## Module Hooks
27+
28+
For other modules to provide information to MCP, you can use the `mcp:setup` hook.
29+
30+
```ts
31+
// src/module.ts
32+
33+
export default defineNuxtModule({
34+
meta: {
35+
name: 'my-module',
36+
},
37+
async setup(options, nuxt) {
38+
nuxt.hook('mcp:setup', ({ mcp }) => {
39+
// Setup your MCP tools here
40+
// For example
41+
mcp.tool('get-nuxt-root', 'Get the Nuxt root path', {}, async () => {
42+
return {
43+
content: [{
44+
type: 'text',
45+
text: nuxt.options.rootDir,
46+
}],
47+
}
48+
})
49+
})
50+
},
51+
})
52+
```
53+
2654
## Sponsors
2755

2856
<p align="center">

packages/nuxt-mcp/src/module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export interface ModuleOptions {
1717
updateCursorMcpJson?: boolean
1818
}
1919

20+
export interface ModuleHooks {
21+
'mcp:setup': (context: McpToolContext) => void
22+
}
23+
2024
export default defineNuxtModule<ModuleOptions>({
2125
meta: {
2226
name: 'nuxt-mcp',
@@ -46,7 +50,7 @@ export default defineNuxtModule<ModuleOptions>({
4650
name: 'nuxt',
4751
version,
4852
},
49-
mcpServerSetup(mcp, vite) {
53+
async mcpServerSetup(mcp, vite) {
5054
const context: McpToolContext = {
5155
unimport: unimport.promise,
5256
nitro: nitro.promise,
@@ -58,6 +62,8 @@ export default defineNuxtModule<ModuleOptions>({
5862
toolsNuxtRuntime(context)
5963
toolsNuxtDotComInfo(context)
6064
toolsScaffold(context)
65+
66+
await nuxt.callHook('mcp:setup', context)
6167
},
6268
}), { client: true })
6369
},

packages/vite-plugin-mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vite-plugin-mcp",
33
"type": "module",
44
"version": "0.0.3",
5-
"packageManager": "pnpm@10.6.5",
5+
"packageManager": "pnpm@10.8.0",
66
"description": "MCP server helping models to understand your Vite app better.",
77
"author": "Anthony Fu <[email protected]>",
88
"license": "MIT",

0 commit comments

Comments
 (0)