---
title: "Patterns & advanced"
description: "Real-world examples, organization, type safety, best practices, and conditional registration."
canonical_url: "https://mcp-toolkit.nuxt.dev/prompts/patterns-advanced"
---
# Patterns & advanced

> Real-world examples, organization, type safety, best practices, and conditional registration.

## Use Cases

Prompts are particularly useful for:

### 1. Setup and Onboarding

Help new developers or AI assistants understand how to work with your codebase:

```typescript [server/mcp/prompts/setup-guide.ts]
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  description: 'Provide complete setup instructions for this project',
  handler: async () => `You are setting up this Nuxt project. Here's what you need to know:

1. Install dependencies: \`pnpm install\`
2. Start dev server: \`pnpm dev\`
3. Project structure follows Nuxt conventions
4. MCP tools are available in server/mcp/

Ask me what you'd like to build!`,
})
```

### 2. Code Review Standards

Ensure consistent code review criteria:

```typescript [server/mcp/prompts/review-standards.ts]
import { z } from 'zod'
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  description: 'Apply team code review standards',
  inputSchema: {
    focus: z.enum(['security', 'performance', 'maintainability', 'all']).default('all'),
  },
  handler: async ({ focus }) => `You are a code reviewer following our team standards. Focus on: ${focus}.

Review the code I provide, checking for best practices and potential issues.`,
})
```

### 3. Documentation Generation

Standardize documentation format:

```typescript [server/mcp/prompts/generate-docs.ts]
import { z } from 'zod'
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  description: 'Generate documentation in team format',
  inputSchema: {
    type: z.enum(['api', 'component', 'function']).describe('What to document'),
  },
  handler: async ({ type }) => {
    const templates = {
      api: 'Document this API endpoint with: endpoint, method, parameters, response format, and examples.',
      component: 'Document this Vue component with: props, emits, slots, and usage examples.',
      function: 'Document this function with: parameters, return value, and usage examples.',
    }

    return templates[type]
  },
})
```

### 4. Troubleshooting Workflows

Guide debugging for common issues:

```typescript [server/mcp/prompts/debug-helper.ts]
import { z } from 'zod'
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  description: 'Help debug common issues',
  inputSchema: {
    area: z.enum(['api', 'auth', 'database', 'frontend']).describe('Area of the issue'),
  },
  handler: async ({ area }) => `You are debugging a ${area} issue. Ask clarifying questions and suggest diagnostic steps.`,
})
```

## Groups and Tags

Organize your prompts with `group` and `tags` for categorization. These fields work the same way as for [tools](https://mcp-toolkit.nuxt.dev/tools/groups-organization#groups-and-tags).

```typescript [server/mcp/prompts/onboarding/setup-guide.ts]
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  tags: ['getting-started'],
  description: 'Help new developers set up the project',
  handler: async () => 'You are setting up this project...',
})
```

Placing the file in `prompts/onboarding/` auto-infers `group: 'onboarding'`.

<callout color="info" icon="i-lucide-info">

Prompt `group` and `tags` are stored on the definition objects but are not yet included in `prompts/list` protocol responses. This will be supported when [SEP-1300](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1300) is adopted by the MCP SDK.

</callout>

## File Organization

Organize your prompts in the `server/mcp/prompts/` directory. Both flat and nested layouts are supported:

```text
server/
└── mcp/
    └── prompts/
        ├── greeting.ts
        ├── summarize.ts
        ├── onboarding/
        │   └── setup-guide.ts
        └── debugging/
            └── troubleshoot.ts
```

Each file should export a default prompt definition. Subdirectories automatically set the `group`.

## Type Safety

The module provides full TypeScript type inference:

```typescript
// Argument types are inferred from inputSchema
handler: async ({ text, maxLength }) => {
  // text is typed as string
  // maxLength is typed as string | undefined
}
```

## Best Practices

### 1. Design for AI Understanding

Write prompts that give the AI clear context and expectations:

```typescript
// Good: Clear context and instructions
handler: async ({ code }) =>
  `You are a senior developer reviewing code for a Nuxt application.

Review this code for Vue 3 best practices:\n\n${code}`

// Less effective: Vague instructions
handler: async ({ code }) => code
```

### 2. Use Descriptive Arguments

Always use `.describe()` on Zod fields to help both users and AI understand what's expected:

```typescript
inputSchema: {
  // Good: Clear descriptions
  language: z.enum(['typescript', 'javascript']).describe('Programming language of the code'),
  strict: z.boolean().default(true).describe('Whether to enforce strict TypeScript rules'),

  // Less helpful: No descriptions
  lang: z.string(),
  s: z.boolean(),
}
```

### 3. Use Conversation Flow

Use user and assistant messages to guide the AI:

```typescript
// Effective: User provides context, assistant acknowledges
messages: [
  { role: 'user', content: { type: 'text', text: 'You are an expert in accessibility. Review this HTML for a11y issues.' } },
  { role: 'assistant', content: { type: 'text', text: 'I\'ll analyze the HTML for accessibility issues.' } },
]
```

### 4. Keep Prompts Focused

Each prompt should have a single, clear purpose. Create multiple prompts instead of one complex one:

```typescript
// Good: Separate focused prompts
// server/mcp/prompts/review-security.ts
// server/mcp/prompts/review-performance.ts
// server/mcp/prompts/review-style.ts

// Less maintainable: One complex prompt trying to do everything
```

### 5. Provide Default Values

Use `.default()` for optional arguments to improve usability:

```typescript
inputSchema: {
  format: z.enum(['brief', 'detailed']).default('detailed').describe('Output format'),
  language: z.string().default('en').describe('Response language'),
}
```

### 6. Include Examples in Complex Prompts

For prompts that need specific output formats, include examples:

```typescript
handler: async () => `Generate a commit message following this format:

type(scope): description

Example:
feat(auth): add OAuth2 login support

Types: feat, fix, docs, style, refactor, test, chore`
```

## Conditional Registration

You can control whether a prompt is visible to clients using the `enabled` guard:

```typescript [server/mcp/prompts/admin-prompt.ts]
export default defineMcpPrompt({
  name: 'admin-prompt',
  description: 'Admin-only prompt',
  enabled: event => event.context.user?.role === 'admin',
  handler: async () => 'Admin instructions...',
})
```

<callout color="primary" icon="i-lucide-book-open">

See the [Dynamic Definitions](https://mcp-toolkit.nuxt.dev/advanced/dynamic-definitions) guide for detailed documentation on auth-based filtering.

</callout>

## Next Steps

- [Prompt Examples](https://mcp-toolkit.nuxt.dev/examples/prompt-examples) - See advanced prompt examples
- [Tools](https://mcp-toolkit.nuxt.dev/tools/overview) - Create tools to perform actions
- [Resources](https://mcp-toolkit.nuxt.dev/resources/overview) - Create resources to expose data
- [Handlers](https://mcp-toolkit.nuxt.dev/handlers/overview) - Create custom MCP endpoints
- [Dynamic Definitions](https://mcp-toolkit.nuxt.dev/advanced/dynamic-definitions) - Conditionally register definitions


## Sitemap

See the full [sitemap](https://mcp-toolkit.nuxt.dev/sitemap.md) for all pages.
