Tools
Create MCP tools with Zod validation and type safety.
What are Tools?
Tools are functions that AI assistants can call to perform actions or retrieve information. They accept validated input parameters and return structured results.
Scaffold a new MCP tool
Basic Tool Definition
Here's a simple tool that echoes back a message:
server/mcp/tools/echo.ts
import { z } from 'zod'
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpTool({
name: 'echo',
description: 'Echo back a message',
inputSchema: {
message: z.string().describe('The message to echo back'),
},
handler: async ({ message }) => `Echo: ${message}`,
})
Auto-Generated Name and Title
You can omit name and title - they will be automatically generated from the filename:
server/mcp/tools/list-documentation.ts
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpTool({
// name and title are auto-generated from filename:
// name: 'list-documentation'
// title: 'List Documentation'
description: 'List all documentation files',
handler: async () => {
// ...
},
})
The filename list-documentation.ts automatically becomes:
name:list-documentation(kebab-case)title:List Documentation(title case)
You can still provide name or title explicitly to override the auto-generated values.
Tool Structure
A tool definition consists of:
export default defineMcpTool({
name: 'tool-name', // Unique identifier (optional - auto-generated from filename)
inputSchema: { ... }, // Zod schema for input validation
handler: async (args) => {
return 'result' // string, number, boolean, object, or CallToolResult
},
})
export default defineMcpTool({
name: 'tool-name', // Optional - auto-generated from filename
title: 'Tool Title', // Optional - auto-generated from filename
description: 'Tool description', // What the tool does
inputSchema: { ... }, // Optional - Zod schema for input validation
outputSchema: { ... }, // Zod schema for structured output
annotations: { ... }, // Behavioral hints for clients
inputExamples: [{ ... }], // Concrete usage examples
handler: async (args) => { ... },
})
Going further
Once you've authored a few tools, branch out: