Prompts
The Directus Content MCP Server supports stored prompts, allowing you to create reusable interactions for AI assistants. This feature is particularly useful for standardizing responses, creating guided workflows, and ensuring consistent content creation.
This guide covers how to set up and use prompts with the Directus Content MCP Server.
Setting Up a Prompts Collection
To use stored prompts, you need to create a dedicated collection in your Directus instance:
- Log in to your Directus instance as an administrator.
- Navigate to Settings > Data Model.
- Click the "Create Collection" button.
- Name your collection (e.g.,
ai_prompts
) and configure display settings. - Add the following fields to your collection:
Field Name | Field Type | Interface | Notes |
---|---|---|---|
name | String | Input | Name of the prompt |
description | Text | Input Multiline | Description of the prompt's purpose |
system_prompt | Text | Input Multiline | System prompt for the AI assistant |
messages | JSON | Input JSON | Array of predefined messages (optional) |
You can customize these field names if needed, but you'll need to update the configuration accordingly.
Configuring Permissions
Ensure that the Directus user associated with your MCP server token has appropriate permissions for the prompts collection:
- Navigate to Settings > Roles & Permissions.
- Select the role associated with your MCP server user.
- Find your prompts collection in the list.
- Enable at least the following permissions:
- Read (to access the prompts).
- Create (if you want the AI to create new prompts).
- Update (if you want the AI to modify prompts).
Without proper permissions, the MCP server won't be able to access your prompts.
Configuring the MCP Server
To enable the prompts feature, update your MCP server configuration with the following environment variables:
{
"mcpServers": {
"directus": {
"command": "npx",
"args": ["@directus/content-mcp@latest"],
"env": {
"DIRECTUS_URL": "https://your-directus-instance.com",
"DIRECTUS_TOKEN": "your_directus_token",
"DIRECTUS_PROMPTS_COLLECTION_ENABLED": "true",
"DIRECTUS_PROMPTS_COLLECTION": "ai_prompts",
"DIRECTUS_PROMPTS_NAME_FIELD": "name",
"DIRECTUS_PROMPTS_DESCRIPTION_FIELD": "description",
"DIRECTUS_PROMPTS_SYSTEM_PROMPT_FIELD": "system_prompt",
"DIRECTUS_PROMPTS_MESSAGES_FIELD": "messages"
}
}
}
}
If you used custom field names in your collection, adjust the corresponding environment variables accordingly.
Creating Effective Prompts
When creating prompts in your collection:
- Name: Use a clear, descriptive name that indicates the prompt's purpose.
- Description: Include details about when and how to use the prompt.
- System Prompt: Define the role and context for the AI assistant.
- Messages: (Optional) Add predefined messages to guide the conversation flow.
Example Prompt
Here's an example of a prompt for creating blog post content:
{
"name": "Create Blog Post",
"description": "Generate a blog post with specified topic and tone",
"system_prompt": "You are a professional content writer creating a blog post for a technology company. Maintain a helpful, authoritative tone while making complex topics accessible.",
"messages": [
{
"role": "user",
"content": "Please write a blog post about {{topic}} with a {{tone}} tone. The post should be around {{length}} words and target {{audience}}."
}
]
}
Dynamic Templating with Mustache
Prompts support dynamic templating using Mustache syntax with double curly braces: {{ variable_name }}
. This allows you to create flexible templates with placeholders that can be filled at runtime.
For example, in the blog post prompt above, variables like {{topic}}
, {{tone}}
, {{length}}
, and {{audience}}
can be replaced with actual values when the prompt is used.
How Templating Works
- Define variables in your prompts using double curly braces:
Hello, {{ name }}!
. - When calling the prompt, provide values for these variables in the
arguments
parameter. - The MCP server automatically replaces the variables with the provided values.
Use Cases for Stored Prompts
Stored prompts are particularly useful for:
- Standardizing Content Creation: Ensure consistent formatting and style across content.
- Guided Workflows: Create step-by-step processes for common tasks.
- Templates: Provide reusable templates for recurring content needs.
- Role-Based Interactions: Define different personas for the AI assistant based on tasks.
- Compliance: Ensure content follows specific guidelines or requirements.
Best Practices
When working with prompts:
- Start with a clear, specific system prompt that defines the role and context.
- Use variables for elements that will change between uses.
- Test prompts with different inputs to ensure they work as expected.
- Organize prompts by category or purpose for easier discovery.
- Update prompts regularly based on feedback and changing needs.