|
| 1 | +# Guide to Creating Custom Prompts in Clojure MCP |
| 2 | + |
| 3 | +## Overview |
| 4 | +Custom prompts are saved in `.clojure-mcp/config.edn` under the `:prompts` key. Prompts use Mustache templating for dynamic content with parameters. |
| 5 | + |
| 6 | +## Prompt Structure |
| 7 | + |
| 8 | +Each prompt is defined as a map with the following keys: |
| 9 | + |
| 10 | +### Required Keys: |
| 11 | +- **`:description`** (string) - Clear description shown to the LLM when listing prompts |
| 12 | +- **`:content`** (string) OR **`:file-path`** (string) - Choose one: |
| 13 | + - `:content` - Inline Mustache template content |
| 14 | + - `:file-path` - Path to a template file (relative to project root) |
| 15 | + |
| 16 | +### Optional Keys: |
| 17 | +- **`:args`** (vector of maps) - Parameter definitions for the template |
| 18 | + - Each argument map has: |
| 19 | + - `:name` (required) - Parameter name used in Mustache template (e.g., `{{name}}`) |
| 20 | + - `:description` (required) - What this parameter is for |
| 21 | + - `:required?` (optional, defaults to false) - Whether parameter is required |
| 22 | + |
| 23 | +## Mustache Template Syntax |
| 24 | + |
| 25 | +- `{{variable}}` - Simple variable substitution |
| 26 | +- `{{#variable}}content{{/variable}}` - Conditional section (only shown if variable exists) |
| 27 | +- `{{^variable}}content{{/variable}}` - Inverted section (only shown if variable doesn't exist) |
| 28 | + |
| 29 | +## Examples |
| 30 | + |
| 31 | +### Simple Prompt (No Parameters) |
| 32 | +```edn |
| 33 | +"my-greeting" {:description "A simple greeting" |
| 34 | + :content "Hello! I'm ready to help you."} |
| 35 | +``` |
| 36 | + |
| 37 | +### Prompt with Required Parameters |
| 38 | +```edn |
| 39 | +"code-reviewer" {:description "Reviews code for best practices" |
| 40 | + :content "Please review this {{language}} code:\n\n```{{language}}\n{{code}}\n```\n\nProvide feedback on quality and improvements." |
| 41 | + :args [{:name "language" |
| 42 | + :description "Programming language" |
| 43 | + :required? true} |
| 44 | + {:name "code" |
| 45 | + :description "Code to review" |
| 46 | + :required? true}]} |
| 47 | +``` |
| 48 | + |
| 49 | +### Prompt with Optional Parameters |
| 50 | +```edn |
| 51 | +"explain-code" {:description "Explains code in detail" |
| 52 | + :content "Explain this {{language}} code:\n\n```\n{{code}}\n```\n\n{{#audience}}Target audience: {{audience}}{{/audience}}" |
| 53 | + :args [{:name "language" |
| 54 | + :description "Programming language" |
| 55 | + :required? true} |
| 56 | + {:name "code" |
| 57 | + :description "Code to explain" |
| 58 | + :required? true} |
| 59 | + {:name "audience" |
| 60 | + :description "Target audience level" |
| 61 | + :required? false}]} |
| 62 | +``` |
| 63 | + |
| 64 | +### Prompt Using File Template |
| 65 | +```edn |
| 66 | +"my-file-prompt" {:description "Loads content from a file" |
| 67 | + :file-path "prompts/my-template.md" |
| 68 | + :args [{:name "project_name" |
| 69 | + :description "Name of the project" |
| 70 | + :required? true}]} |
| 71 | +``` |
| 72 | + |
| 73 | +## Step-by-Step Guide |
| 74 | + |
| 75 | +1. **Locate config file**: Open `.clojure-mcp/config.edn` in your project root |
| 76 | + - If it doesn't exist, create it |
| 77 | + |
| 78 | +2. **Add `:prompts` key**: If not present, add `:prompts {}` to the config map |
| 79 | + |
| 80 | +3. **Define your prompt**: Add an entry under `:prompts` with: |
| 81 | + - String key (prompt name) - e.g., `"my-custom-prompt"` |
| 82 | + - Map value with `:description` and either `:content` or `:file-path` |
| 83 | + |
| 84 | +4. **Add parameters** (optional): If your prompt needs dynamic values: |
| 85 | + - Add `:args` vector with parameter definitions |
| 86 | + - Use parameter names in your template with Mustache syntax: `{{param_name}}` |
| 87 | + |
| 88 | +5. **Save and test**: Save the config file |
| 89 | + - The MCP server will reload the configuration |
| 90 | + - Your prompt will appear in the prompts list |
| 91 | + |
| 92 | +## Common Patterns |
| 93 | + |
| 94 | +### Code Review/Analysis |
| 95 | +```edn |
| 96 | +:content "Analyze this {{language}} code for {{focus}}:\n\n```{{language}}\n{{code}}\n```" |
| 97 | +``` |
| 98 | + |
| 99 | +### Documentation Generation |
| 100 | +```edn |
| 101 | +:content "Generate documentation for this {{language}} {{type}}:\n\n{{code}}\n\nInclude: {{#sections}}{{.}}, {{/sections}}" |
| 102 | +``` |
| 103 | + |
| 104 | +### Test Generation |
| 105 | +```edn |
| 106 | +:content "Generate {{framework}} tests for:\n\nFunction: {{function_name}}\n```{{language}}\n{{code}}\n```" |
| 107 | +``` |
| 108 | + |
| 109 | +## Important Notes |
| 110 | + |
| 111 | +- Prompt names MUST be strings (not keywords): `"my-prompt"` not `:my-prompt` |
| 112 | +- You cannot use both `:content` and `:file-path` - choose one |
| 113 | +- Parameter `:name` values must match the `{{variable}}` names in your template |
| 114 | +- Required parameters are enforced when the prompt is invoked |
| 115 | +- The config file must be valid EDN format |
| 116 | + |
| 117 | +## Configuration Location |
| 118 | + |
| 119 | +Full path: `<project-root>/.clojure-mcp/config.edn` |
| 120 | + |
| 121 | +Example complete config: |
| 122 | +```edn |
| 123 | +{:prompts {"my-prompt" {:description "My custom prompt" |
| 124 | + :content "Content here with {{param}}" |
| 125 | + :args [{:name "param" |
| 126 | + :description "A parameter" |
| 127 | + :required? true}]}} |
| 128 | + :allowed-directories ["." "src" "test"]} |
| 129 | +``` |
0 commit comments