Skip to main content
Prompts are reusable message templates that clients fetch with prompts/get. Register one with server.prompt(config, handler):
import { FastMCP } from '@prefecthq/fastmcp-ts/server'

const server = new FastMCP({ name: 'my-server' })

server.prompt(
  {
    name: 'review_code',
    description: 'Review code for quality and correctness',
    arguments: [
      { name: 'code', required: true },
      { name: 'language', required: false },
    ],
  },
  ({ code, language }) =>
    `Review this ${language ?? 'code'} for quality and correctness:\n\n${code}`
)
The handler receives a Record<string, string> of the supplied arguments. Required arguments are validated before the handler runs — a missing required argument returns McpError(InvalidParams) without invoking the handler.

Return values

Returned valueConversion
stringSingle user text message
PromptMessageWrapped in a one-element array
PromptMessage[]Used as-is (multi-turn sequence)
PromptResult(messages, description?)Passed through as-is
PromptMessage.content supports the content types text, image, audio, resource (embedded), and resource_link.
import { PromptResult } from '@prefecthq/fastmcp-ts/server'

server.prompt(
  { name: 'pair_review', arguments: [{ name: 'code', required: true }] },
  ({ code }) =>
    PromptResult(
      [
        { role: 'user', content: { type: 'text', text: `Review:\n${code}` } },
        { role: 'assistant', content: { type: 'text', text: 'Here is my review:' } },
      ],
      'A seeded multi-turn review exchange'
    )
)

Config fields

FieldBehavior
nameInferred from handler.name when omitted
titleHuman-readable label for UIs
descriptionInferred from the name (camelCase → words) when omitted
argumentsArray of { name, description?, required? }
timeoutPer-call timeout in milliseconds
disabledHides the prompt and rejects prompts/get
authPer-prompt authorization check

Dynamic registration

Prompts can be registered before or after run() — adding one to a running server sends notifications/prompts/list_changed automatically.