Skip to main content
Prompts are reusable prompt templates with typed arguments. They encapsulate system instructions, conversation starters, or any repeatable interaction pattern that clients can discover and invoke with parameters.
This feature implements the MCP Prompts specification. FrontMCP handles all protocol details automatically.
Nx users: Scaffold with nx g @frontmcp/nx:prompt my-prompt --project my-app. See Prompt Generator.

Why Prompts?

In the Model Context Protocol, prompts serve a distinct purpose from tools and resources: Prompts are ideal for:
  • System instructions — reusable persona definitions, behavior guidelines
  • Conversation starters — standardized ways to begin specific tasks
  • Workflow templates — multi-turn interaction patterns
  • Task scaffolding — structured prompts for code review, summarization, translation
  • Consistent messaging — ensure uniform tone and format across interactions

Creating Prompts

Class Style

Use class decorators for prompts that need dependency injection, lifecycle hooks, or complex logic:

Function Style

For simpler prompts, use the functional builder:

Registering Prompts

Add prompts to your app via the prompts array:
Prompts can also be generated dynamically by adapters or plugins.

Loading from npm or Remote Servers

Mix local prompts with those loaded from npm or proxied from remote servers:
Prompt.esm() and Prompt.remote() load individual prompts. For loading entire apps, use App.esm() or App.remote().

Return Values

Prompts return messages that clients can render or send to a model. The SDK supports multiple return formats.

Simple String Return

Message Array

Full MCP Format

For complete control, return the full GetPromptResult structure:

Object Return

Objects are automatically JSON-serialized:

Prompt Metadata

Field descriptions:

Prompt Context

Class-based prompts have access to a rich execution context via this:

Using Providers

Inject services via the get() method:

Real-World Examples

Code Review Prompt

Translation Prompt

Multi-Turn Conversation Starter

Dynamic Prompt with Provider


MCP Protocol Integration

Prompts integrate with the MCP protocol via two flows: When a client requests prompts/get with a name and arguments:
  1. The SDK locates the prompt by name
  2. Arguments are validated against the prompt’s definition
  3. The execute() method is called with the arguments
  4. The return value is converted to MCP GetPromptResult format

Capabilities

FrontMCP automatically advertises prompt capabilities during MCP initialization:
The SDK sets listChanged: true when you have any prompts registered, enabling clients to receive real-time notifications when prompts are dynamically added or removed.

Change Notifications

When prompts change dynamically (e.g., via adapters or plugins), FrontMCP automatically sends notifications/prompts/list_changed to connected clients. Clients that support this notification will refresh their prompt list.
For the full protocol specification, see MCP Prompts.
To learn how clients discover your prompts via MCP flows like prompts/list and prompts/get, see Discovery APIs.

Best Practices

Do:
  • Use descriptive name and description fields to help clients understand prompt purpose
  • Define clear arguments with descriptions to guide users
  • Keep prompts focused on a single task or interaction pattern
  • Use the title field for user-friendly display names
  • Return structured messages with appropriate roles
Don’t:
  • Create prompts that perform side effects (use tools instead)
  • Hardcode values that should be arguments
  • Create overly complex prompts—split into multiple prompts if needed
  • Ignore argument validation—mark required fields appropriately
  • Mix concerns—keep prompts focused on message generation