Advanced Topics
Extend the module with hooks
Use Nuxt hooks to extend and customize the MCP module.
Available Hooks
The Nuxt MCP module provides hooks for extending and customizing behavior.
mcp:definitions:paths
This hook allows you to add additional directories to scan for MCP definitions.
Hook Signature
nuxt.hook('mcp:definitions:paths', (paths: {
tools: string[]
resources: string[]
prompts: string[]
handlers: string[]
}) => {
// Modify paths
})
Usage in nuxt.config.ts
nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/mcp-toolkit'],
hooks: {
'mcp:definitions:paths'(paths) {
// Add additional tool directories
paths.tools.push('shared/tools')
paths.tools.push('legacy/tools')
// Add additional resource directories
paths.resources.push('shared/resources')
// Add additional prompt directories
paths.prompts.push('shared/prompts')
// Add additional handler directories
paths.handlers.push('custom/handlers')
},
},
})
Usage in a Custom Module
my-module.ts
export default defineNuxtModule({
setup(options, nuxt) {
nuxt.hook('mcp:definitions:paths', (paths) => {
// Add paths from this module
paths.tools.push('my-module/tools')
paths.resources.push('my-module/resources')
paths.prompts.push('my-module/prompts')
})
},
})
Path Structure
The paths object contains arrays of directory paths:
{
tools: string[] // Directories to scan for tools
resources: string[] // Directories to scan for resources
prompts: string[] // Directories to scan for prompts
handlers: string[] // Directories to scan for handlers
}
All paths are relative to the server/ directory of each Nuxt layer.
Path Resolution
Paths are resolved in the following order:
- Relative to
server/: Paths like'tools'resolve toserver/tools/ - Absolute paths: Paths starting with
/resolve from project root - Layer-specific: Each Nuxt layer resolves paths relative to its own
server/directory
Next Steps
- Custom Paths - Learn more about customizing paths
- Handlers - Create multiple MCP endpoints
- Configuration - Configure the module