The Model Context Protocol (MCP) lets AI assistants call functions, read data, and use prompt templates from your application. With the Nuxt MCP Toolkit (@nuxtjs/mcp-toolkit), you can add an MCP server directly to your Nuxt app and expose your application's features to tools like Cursor, VS Code, and Claude Desktop. The module handles protocol details, input validation, and auto-discovery so you can focus on building what your MCP server does.
This guide walks you through installing the module, creating tools, resources, and prompt templates, connecting your IDE, debugging with the built-in MCP Inspector, and adding authentication to protect your endpoints.
Before you begin, make sure you have:
- A Nuxt 3.x or 4.x project.
- Node.js 18 or higher.
- The
zodpackage installed in your project.
If you're working with an AI coding agent like Claude Code or Cursor, you can scaffold the starter project and hand off implementation with this prompt:
Add the agent skill to teach your AI coding agent about the toolkit:
Use the add-mcp CLI to add the documentation MCP to your agent:
The Nuxt MCP Toolkit adds an HTTP endpoint (by default at /mcp) to your Nuxt application. AI clients connect to this endpoint using the MCP protocol. The module scans your server/mcp/ directory for tool, resource, and prompt definitions, then registers them automatically. When an AI assistant sends a request, the module validates inputs with Zod, runs your handler, and returns the result.
Your project structure looks like this after setup:
Files placed in these directories are discovered and registered without any manual wiring.
Run the automatic installer, which adds the package and updates your Nuxt config:
If you prefer manual setup, install @nuxtjs/mcp-toolkit and its peer dependency zod:
Then add the module to your nuxt.config.ts:
The module works with defaults that cover most cases. To customize the server name, endpoint route, or file directory, pass options under the mcp key:
Here's what each option does:
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable the MCP server |
route | string | '/mcp' | HTTP route where the MCP server is accessible |
name | string | '' | Server name used in the MCP protocol handshake |
version | string | '1.0.0' | Server version (semantic versioning) |
dir | string | 'mcp' | Base directory for definitions, relative to server/ |
browserRedirect | string | '/' | URL to redirect browsers visiting the MCP endpoint |
autoImports | boolean | true | Auto-import defineMcpTool, defineMcpResource, and other helpers |
sessions | boolean | object | false | Enable stateful session management for SSE streaming and per-session state |
Tools are functions that AI assistants can call to perform actions or retrieve information. Each tool validates its input with Zod and returns a result.
Create a file in server/mcp/tools/:
The name and title fields are optional. If you omit them, the module generates both from the filename. A file named list-users.ts becomes name: 'list-users' and title: 'List Users'.
Your handler receives the validated input object and can return a string, number, boolean, object, or a full CallToolResult. For error cases, throw an error with createError from h3:
Resources expose read-only data that AI assistants can use as context. Unlike tools, resources are application-driven: the host application (or user) decides when to include resource content in a conversation, not the AI model.
The quickest way to expose a file is with the file property:
The module handles URI generation, MIME type detection, and file reading automatically.
For custom data sources, define a uri and handler manually:
Use resources for files, configs, database schemas, and logs. Use tools when the AI needs to perform an action or modify state.
Prompts are reusable message templates that appear in your IDE when you type / in the chat. They standardize how you interact with AI assistants for common tasks.
Handlers can return a plain string (auto-wrapped as a user message) or a full GetPromptResult with a messages array for multi-turn conversations. Prompt arguments must be strings since the MCP protocol requires it.
Start your Nuxt dev server, then connect your AI assistant to the MCP endpoint.
Use the add-mcp CLI to add your MCP to Claude Code, OpenCode, and more.
Add the server to ~/.cursor/mcp.json:
Add the server to .vscode/mcp.json in your project:
Replace my-nuxt-app with your project name and update the URL if you changed the route or port.
The module includes an integration with the MCP Inspector, a visual debugging tool built into Nuxt DevTools. To use it:
- Enable DevTools in your Nuxt config:
- Open Nuxt DevTools and navigate to the MCP Inspector tab under the Server section.
- Click Launch Inspector to browse your tools, resources, and prompts, test them with custom parameters, and view request/response history.
The inspector connects to your MCP server automatically with the correct configuration.
To secure your MCP endpoints, add Bearer token validation through the module's middleware system.
MCP middleware should not throw errors when authentication is missing or invalid. Throwing a 401 causes MCP clients to enter OAuth discovery mode, looking for .well-known/oauth-* endpoints that don't exist. Instead, set context when auth succeeds and let requests continue otherwise. Your tools can then check for user context:
To use useEvent() inside tool handlers, enable asyncContext in your Nuxt config:
Configure MCP clients to send the token in request headers (e.g., Cursor):
If you visit the MCP endpoint in a browser, you'll be redirected to the browserRedirect URL (by default /). MCP endpoints are designed for programmatic access by AI clients, not browsers. Use the MCP Inspector or your IDE to interact with the server.
Confirm that autoImports isn't set to false in your MCP config. If you've disabled auto-imports, import helpers explicitly:
Make sure your tool files are in the correct directory (server/mcp/tools/ by default) and that each file has a default export using defineMcpTool. Restart your dev server after adding new files.
Enable asyncContext in your Nitro configuration. Without it, useEvent() won't have access to the current request context inside async handlers.
Build knowledge agents without embeddings
Learn how you can build a Nuxt-based knowledge agent with Vercel Sandbox, Chat SDK, and AI SDK. No embeddings, no vector DB.