Advanced Topics
TypeScript
Type safety and TypeScript features in the Nuxt MCP module.
Type Safety
The Nuxt MCP module provides full TypeScript support with complete type inference and type safety.
Auto-Imports
All helper functions are automatically imported in your server files:
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server' // optional
// Imports are optional - auto-imported on server-side!
export default defineMcpTool({
name: 'example',
inputSchema: {
message: z.string(),
},
handler: async ({ message }) => {
// message is typed as string
},
})
Available auto-imports:
defineMcpTooldefineMcpResourcedefineMcpPromptdefineMcpHandler
Type Inference
Tool Input Types
Input types are automatically inferred from your inputSchema:
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server' // optional
export default defineMcpTool({
name: 'example',
inputSchema: {
name: z.string(),
age: z.number(),
email: z.string().email().optional(),
},
handler: async ({ name, age, email }) => {
// name: string
// age: number
// email: string | undefined
},
})
Tool Output Types
Output types are inferred from outputSchema:
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server' // optional
export default defineMcpTool({
name: 'example',
inputSchema: {
value: z.number(),
},
outputSchema: {
result: z.number(),
doubled: z.number(),
},
handler: async ({ value }) => {
const result = value * 2
return {
content: [{ type: 'text', text: String(result) }],
structuredContent: {
result, // TypeScript knows this is number
doubled: result * 2, // TypeScript knows this is number
},
}
},
})
Prompt Argument Types
Prompt argument types are inferred from inputSchema:
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server' // optional
export default defineMcpPrompt({
name: 'example',
inputSchema: {
text: z.string(),
maxLength: z.string().optional(),
},
handler: async ({ text, maxLength }) => {
// text: string
// maxLength: string | undefined
},
})
Runtime Config Types
Access typed runtime configuration:
server/api/config.ts
export default defineEventHandler((event) => {
const config = useRuntimeConfig(event).mcp
// config is typed with:
// - enabled: boolean
// - route: string
// - browserRedirect: string
// - name: string
// - version: string
// - dir: string
return config
})