Prompts

Prompts are user-controlled instruction templates that enable structured, consistent interactions through parameterized workflows.

xmcp detects files under the /src/prompts/ directory and registers them as prompts. This path can be configured in the xmcp.config.ts file.

The prompt file should export three elements:

  • Schema: The input parameters using Zod schemas.
  • Metadata: The prompt's identity and behavior hints.
  • Default: The prompt handler function.
src/prompts/review-code.ts

If you're returning a string or number only, you can shortcut the return value to be the string or number directly.

We encourage to use this shortcut for readability, and restrict the usage of the content object type only for complex responses, like images, audio or videos.

References

Schema (optional)

The schema object defines the prompt's parameters with:

  • Key: Parameter name.
  • Value: Zod schema with .describe() for documentation and prompt inspection. This will be visible through the inspector.
  • Purpose: Type validation and automatic parameter documentation.

This is the exact same as the schema object for tools.

Metadata (optional)

The metadata object provides:

  • Name: Unique identifier for the prompt
  • Title: Human-readable title for the prompt
  • Description: Brief explanation of what the prompt does
  • Role: The role of the prompt in the conversation. Can be either user or assistant.

Implementation (required)

The default export function that performs the actual work.

  • Parameters: Automatically typed from your schema using the built-in InferSchema.
  • Returns: MCP-compatible response with content type.
  • Async: Supports async operations for API calls, file I/O, etc.

On this page

One framework to rule them all

    Prompts | xmcp Documentation