---
title: "Authoring & structure"
description: "Names, roles, arguments, and the shape of a prompt definition."
canonical_url: "https://mcp-toolkit.nuxt.dev/prompts/authoring"
---
# Authoring & structure

> Names, roles, arguments, and the shape of a prompt definition.

## Auto-Generated Name and Title

You can omit `name` and `title` - they will be automatically generated from the filename:

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

export default defineMcpPrompt({
  // name and title are auto-generated from filename:
  // name: 'greeting'
  // title: 'Greeting'
  description: 'Generate a personalized greeting message',
  handler: async () => {
    // ...
  },
})
```

The filename `greeting.ts` automatically becomes:

- `name`: `greeting` (kebab-case)
- `title`: `Greeting` (title case)

You can still provide `name` or `title` explicitly to override the auto-generated values.

## Simple Prompt (No Arguments)

Create a prompt without arguments. Handlers can return a simple string — it will be automatically wrapped into a single user message:

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

export default defineMcpPrompt({
  name: 'greeting',
  title: 'Greeting',
  description: 'Generate a personalized greeting message',
  handler: async () => {
    const hour = new Date().getHours()
    const timeOfDay = hour < 12 ? 'morning' : hour < 18 ? 'afternoon' : 'evening'

    return `Good ${timeOfDay}! How can I help you today?`
  },
})
```

### Default Role

When a handler returns a string, it is wrapped with the `user` role by default. Use the `role` option to change this:

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

export default defineMcpPrompt({
  role: 'assistant',
  description: 'Code review assistant persona',
  handler: async () => 'I am a code review assistant. Share your code and I will review it for best practices.',
})
```

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

The `role` option only affects string returns. When returning a full `GetPromptResult`, define roles directly in the `messages` array.

</callout>

## Prompt with Arguments

Create a prompt that accepts arguments:

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

export default defineMcpPrompt({
  name: 'summarize',
  title: 'Text Summarizer',
  description: 'Summarize any text content',
  inputSchema: {
    text: z.string().describe('The text to summarize'),
    maxLength: z.string().optional().describe('Maximum length of summary in words'),
  },
  handler: async ({ text, maxLength }) => {
    const words = text.split(/\s+/)
    const maxWords = maxLength ? Number.parseInt(maxLength) : Math.ceil(words.length * 0.3)
    const summary = words.slice(0, maxWords).join(' ')

    return `Summary (${maxWords} words): ${summary}${words.length > maxWords ? '...' : ''}`
  },
})
```

## Prompt Structure

A prompt definition consists of:

<code-group>

```typescript [Simple Prompt]
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  name: 'prompt-name',  // Unique identifier
  handler: async () => 'Your prompt text here',
})
```

```typescript [With Role]
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  name: 'prompt-name',
  role: 'assistant',             // Role for string returns (default: 'user')
  handler: async () => 'I am an assistant persona.',
})
```

```typescript [Prompt with Arguments]
import { defineMcpPrompt } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpPrompt({
  name: 'prompt-name',
  title: 'Prompt Title',        // Human-readable title
  description: 'Description',   // What the prompt does
  inputSchema: { ... },          // Zod schema for arguments
  handler: async (args) => {    // Handler with arguments
    return `Prompt text with ${args.param}`
  },
})
```

</code-group>


## Sitemap

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