A Model Control Protocol (MCP) server for managing and serving dynamic prompt templates using Go's text/template engine.
It allows you to create reusable prompt templates with variable placeholders, partials, conditionals, and loops that can be filled in at runtime.
- Rich CLI Interface: Modern command-line interface with subcommands, colored output, and comprehensive help
- Template Management: List, validate, and render templates directly from the command line
- Go Template Engine: Full
text/templatesyntax with variables, partials, conditionals, and loops - Automatic JSON Parsing: Intelligent argument parsing with JSON support and string fallback
- Environment Variables: Automatic injection of environment variables into templates
- Hot-Reload: Efficient file watching with automatic template reloading using fsnotify
- MCP Compatible: Works seamlessly with Claude Desktop, Claude Code, and other MCP clients
go install github.com/vasayxtx/mcp-prompt-engine@latestmake buildRun the MCP server in a Docker container:
# Build the Docker image
make docker-build
# Run the server with mounted volumes
make docker-runThe Docker container runs as a non-root user and mounts the prompts and logs directories from the host system.
Create a directory to store your prompt templates. Each template should be a .tmpl file using Go's text/template syntax with the following format:
{{/* Brief description of the prompt */}}
Your prompt text here with {{.template_variable}} placeholders.The first line comment ({{/* description */}}) is used as the prompt description, and the rest of the file is the prompt template.
The server uses Go's text/template engine, which provides powerful templating capabilities:
- Variables:
{{.variable_name}}- Access template variables - Built-in variables:
{{.date}}- Current date and time
- Conditionals:
{{if .condition}}...{{end}},{{if .condition}}...{{else}}...{{end}} - Logical operators:
{{if and .condition1 .condition2}}...{{end}},{{if or .condition1 .condition2}}...{{end}} - Loops:
{{range .items}}...{{end}} - Template inclusion:
{{template "partial_name" .}}or{{template "partial_name" dict "key" "value"}}
The server automatically parses argument values as JSON when possible, enabling rich data types in templates:
- Booleans:
true,false→ Go boolean values - Numbers:
42,3.14→ Go numeric values - Arrays:
["item1", "item2"]→ Go slices for use with{{range}} - Objects:
{"key": "value"}→ Go maps for structured data - Strings: Invalid JSON falls back to string values
This allows for advanced template operations like:
{{range .items}}Item: {{.}}{{end}}
{{if .enabled}}Feature is enabled{{end}}
{{.config.timeout}} secondsTo disable JSON parsing and treat all arguments as strings, use the --disable-json-args flag.
Create reusable template components by prefixing filenames with _. These partials can be included in other templates using the {{template "partial_name" .}} syntax. The system automatically detects which partials are used by each template:
Example partial (_header.tmpl):
{{/* Common header partial */}}
You are an experienced {{.role}} tasked with {{.task}}.
Current date: {{.date}}
{{if .context}}Context: {{.context}}{{end}}Using partials in main templates:
{{/* Main prompt using header partial */}}
{{template "_header" dict "role" "software developer" "task" "code review" "context" .context}}
Please review the following code:
{{.code}}The server provides these built-in template functions:
dict- Create a map from key-value pairs:{{template "partial" dict "key1" "value1" "key2" "value2"}}
Here's a complete example of a code review prompt template (code_review.tmpl):
{{/* Perform a code review. Optionally include urgency. Args: language, project_root, src_path, [urgency_level], [context] */}}
{{template "_header" dict "role" "software developer" "task" "performing a thorough code review" "date" .date "context" .context}}
Here are the details of the code you need to review:
Programming Language:
<programming_language>
{{.language}}
</programming_language>
Project Root Directory:
<project_root>
{{.project_root}}
</project_root>
File or Directory for Review:
<review_path>
{{.src_path}}
</review_path>
{{if .urgency_level}}
Urgency: Please address this review with {{.urgency_level}} urgency.
{{end}}
Please conduct a comprehensive code review focusing on the following aspects:
1. Code quality
2. Adherence to best practices
3. Potential bugs or logical errors
4. Performance optimization opportunities
5. Security vulnerabilities or concerns
{{template "_analysis_footer" dict "analysis_type" "review"}}
Remember to be specific in your recommendations, providing clear guidance on how to improve the code.The MCP Prompt Engine provides a modern command-line interface with multiple subcommands for different operations.
# Show help and available commands
mcp-prompt-engine --help
# Show version information
mcp-prompt-engine --version# Start the server with default settings
mcp-prompt-engine serve
# Start with custom prompts directory and options
mcp-prompt-engine --prompts /path/to/prompts serve --log-file /path/to/log/file --quiet
# Start with JSON argument parsing disabled
mcp-prompt-engine serve --disable-json-argsList available templates:
# Simple list
mcp-prompt-engine list
# Detailed list with descriptions and variables
mcp-prompt-engine --prompts /path/to/prompts list --verboseRender a template to stdout:
# Render a specific template
mcp-prompt-engine render template_name
# Render with custom prompts directory
mcp-prompt-engine --prompts /path/to/prompts render code_reviewValidate template syntax:
# Validate all templates
mcp-prompt-engine validate
# Validate a specific template
mcp-prompt-engine validate template_name--prompts, -p: Directory containing prompt template files (default: "./prompts")- Can also be set via
MCP_PROMPTS_DIRenvironment variable
- Can also be set via
--help, -h: Show help information--version, -v: Show version information
--log-file: Path to log file (if not specified, logs to stdout)--disable-json-args: Disable JSON argument parsing, treat all arguments as strings--quiet: Suppress non-essential output for cleaner logs
--verbose: Show detailed information including template descriptions and variables
The CLI provides colored output and helpful error messages to improve the user experience.
To use this MCP server with Claude Desktop, add the following configuration to your Claude Desktop settings:
{
"my-prompts": {
"command": "/path/to/mcp-prompt-engine",
"args": [
"--prompts",
"/path/to/prompts/dir",
"serve",
"--log-file",
"/path/to/log/file",
"--quiet"
]
}
}If you want to run the server within a Docker container, you can use the following configuration:
{
"mcp-prompt-engine": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "/path/to/prompts/dir:/app/prompts:ro",
"-v", "/path/to/logs/dir:/app/logs",
"mcp-prompt-engine"
]
}
}The server supports environment variable configuration and injection:
Configuration via Environment Variables:
MCP_PROMPTS_DIR: Set the default prompts directory (equivalent to--promptsflag)
Template Variable Injection: The server automatically injects environment variables into your prompts. If an environment variable with the same name as a template variable (in uppercase) is found, it will be used to fill the template.
For example, if your prompt contains {{.username}} and you set the environment variable USERNAME=john, the server will automatically replace {{.username}} with john in the prompt.
In the Claude Desktop configuration above, the "env" section allows you to define environment variables that will be injected into your prompts.
-
CLI Interface: The application uses a modern CLI framework:
- Built with urfave/cli/v3 for robust command-line interface
- Colored output using fatih/color for better user experience
- Hierarchical command structure with global and command-specific options
- Comprehensive help system and error handling
-
Server startup: The server parses all
.tmplfiles on startup:- Loads partials (files starting with
_) for reuse - Loads main prompt templates (files not starting with
_) - Extracts template variables by analyzing the template content and its used partials
- Only partials that are actually referenced by the template are included
- Template arguments are extracted from patterns like
{{.fieldname}}anddict "key" .value - Sets up efficient file watching using fsnotify for hot-reload capabilities
- Provides startup feedback with template count and status indicators
- Loads partials (files starting with
-
File watching and hot-reload: The server automatically detects changes:
- Monitors the prompts directory for file modifications, additions, and removals
- Automatically reloads templates when changes are detected
- No server restart required when adding new templates or modifying existing ones
-
Prompt request processing: When a prompt is requested:
- Uses the latest version of templates (automatically reloaded if changed)
- Prepares template data with built-in variables (like
date) - Merges environment variables and request parameters
- Executes the template with all data
- Returns the processed prompt to the client
MIT License - see LICENSE file for details.