Skip to main content
Prompts in WebMCP are reusable message templates that AI agents can retrieve and use to guide interactions. They provide a standardized way to create consistent AI conversations.
Prompts are part of the Model Context Protocol (MCP) specification. WebMCP implements prompts for browser environments, enabling web applications to expose conversational templates to AI agents.

Overview

When to Use Prompts

Standardized Interactions

Create consistent conversation starters across your application

Template Messages

Generate parameterized messages with validated arguments

Workflow Guidance

Guide AI agents through specific interaction patterns

Context Injection

Inject application-specific context into AI conversations

Basic Registration

Register a simple prompt without arguments:

Prompts with Arguments

Use argsSchema to accept validated parameters:

Multi-Message Prompts

Return multiple messages to establish conversation context:

How AI Agents Use Prompts

When an AI agent wants to use a prompt, it calls getPrompt() through the MCP protocol. This invokes your registered get() handler:
The getPrompt() method is called by AI agents through the MCP protocol, not directly from your application code. Your get() handler is invoked automatically when an agent requests the prompt.

Listing Available Prompts

Dynamic vs Static Registration

Use registerPrompt() for prompts that may be added/removed at runtime:
Use for:
  • Context-dependent prompts
  • Feature-specific interactions
  • Prompts tied to component lifecycle

Schema Validation

Prompts support both JSON Schema and Zod for argument validation:

Best Practices

Choose prompt names that clearly indicate purpose. Use kebab-case for multi-word names:
  • code-review instead of codeReview
  • bug-report instead of report
Descriptions help AI agents decide when to use a prompt:
Always use argsSchema for prompts with parameters. Include descriptions for each property to help AI agents provide correct values.
Each prompt should serve a single purpose. Create multiple prompts instead of one complex multi-purpose prompt.
Verify prompts work correctly with actual AI integrations. Check that:
  • Arguments are passed correctly
  • Messages are formatted as expected
  • AI responses are appropriate

Common Patterns

Contextual Prompts

Inject application state into prompts:

Role-Based Templates

Different prompts for different user interactions:

Live Prompt Examples

Interactive prompt demonstrations

Resources

Exposing data to AI agents

Tool Registration

Executing actions for AI agents

Schemas

Schema validation patterns