MCP Prompts
mcpfy provides a declarative API for defining and registering MCP prompts. Prompts allow an MCP server to expose reusable prompt templates that MCP clients can discover and request with structured arguments. mcpfy simplifies prompt registration while keeping the underlying MCP prompt model intact.1. Overview
A prompt in mcpfy consists of:- A unique name
- An optional title
- An optional description
- An optional Zod schema for prompt arguments
- A callback that generates the prompt result
2. Importing Prompt APIs
The prompt types are available from:3. Registering a Prompt
Prompts are registered using:4. Prompt Definition
The prompt definition has the following structure:Properties
A callback must be supplied either through the second argument of
.prompt() or through the cb property.
5. Prompt Callback
A prompt callback receives:paramscontains the validated prompt arguments.ctxis the mcpfyToolContext.
GetPromptResult or the same simplified content-helper results supported by tools.
6. Using a Zod Schema
A Zod object can be used to describe prompt arguments.7. Example: Simple Prompt
8. Standard GetPromptResult
The most direct way to return a prompt is to return a standard MCP GetPromptResult.
messages array contains the messages that make up the generated prompt.
9. Prompt Messages
A prompt result uses MCPPromptMessage objects.
For example:
10. Using text()
mcpfy also allows prompt callbacks to return the same content helpers used by tools.
For example:
11. Using markdown()
Markdown content can also be returned:
12. Using object()
Structured content can also be produced using the object() helper when appropriate.
13. Callback Defined Inside the Definition
Instead of passing the callback as the second argument, it can be specified usingcb.
14. Callback as the Second Argument
The callback can instead be separated from the definition:15. Using ToolContext
The prompt callback receives a ToolContext as its second parameter.
16. Prompt Without Arguments
A prompt does not require a schema.17. Prompt With Multiple Arguments
18. How Prompt Registration Works
Internally,server.prompt() delegates registration to the prompt registration layer.
The process is:
19. Automatic Result Conversion
Prompt callbacks can return either:- A standard
GetPromptResult - A typed tool-style result
- A
ToolContentResult
GetPromptResult, mcpfy uses it directly.
For content-helper results, mcpfy converts the returned content into prompt messages.
Conceptually:
user prompt message.
20. Missing Callback Error
Every registered prompt must have a callback. This is valid:21. Discovering Prompts from a Client
Once registered, prompts can be discovered using the mcpfy client:22. Requesting a Prompt from a Client
After discovering a prompt:23. Complete Example
Server
Client
24. Best Practices
Use descriptive prompt names
Prefer:Provide descriptions
Descriptions help MCP clients understand when a prompt should be used.Use schemas for arguments
If a prompt requires input, define it explicitly:Keep callbacks focused
A prompt callback should primarily construct the prompt rather than contain unnecessary application logic.Use content helpers when appropriate
For simple prompts, helpers such as:25. API Summary
server.prompt()
Registers an MCP prompt.
PromptDefinition
PromptCallback
Client prompt methods
26. Summary
mcpfy makes MCP prompt development straightforward by providing a declarative.prompt() API with:
- Prompt metadata
- Zod-based argument schemas
- Typed callback parameters
ToolContextaccess- Standard MCP
GetPromptResultsupport text(),markdown(), andobject()content-helper support- Automatic conversion of content results into MCP prompt messages

