|
| 1 | +--- |
| 2 | +description: Learn how to create media items in Umbraco using the Developer MCP server |
| 3 | +--- |
| 4 | + |
| 5 | +# Creating Media |
| 6 | + |
| 7 | +The Developer MCP server provides powerful tools for creating media items programmatically. You can upload media from local files, remote URLs, or base64-encoded data, making it easy to automate media management tasks. |
| 8 | + |
| 9 | +## Available Media Creation Tools |
| 10 | + |
| 11 | +The MCP server provides two primary tools for creating media: |
| 12 | + |
| 13 | +- **`create-media`** - Create a single media item |
| 14 | +- **`create-media-multiple`** - Batch create up to 20 media items at once |
| 15 | + |
| 16 | +These tools are available when the `media` and `temporary-file` tool collections are enabled. |
| 17 | + |
| 18 | +## Supported Media Types |
| 19 | + |
| 20 | +The Developer MCP server supports all standard Umbraco media types, plus any custom media types you've defined: |
| 21 | + |
| 22 | +| Media Type | Description | Example File Types | |
| 23 | +|-------------------|--------------------------------------------------|---------------------------------| |
| 24 | +| Image | Standard images with focal point and cropping | .jpg, .png, .gif, .webp | |
| 25 | +| File | Generic file storage | Any file type | |
| 26 | +| Article | Document files | .pdf, .docx, .doc | |
| 27 | +| Audio | Audio files | .mp3, .wav, .ogg | |
| 28 | +| Video | Video files | .mp4, .webm, .avi | |
| 29 | +| SVG | Vector graphics (auto-detected from extension) | .svg | |
| 30 | + |
| 31 | +Custom media types created in your Umbraco installation are also supported and can be referenced by name. |
| 32 | + |
| 33 | +## Source Types |
| 34 | + |
| 35 | +You can create media from three different sources: |
| 36 | + |
| 37 | +### File Path |
| 38 | + |
| 39 | +Upload media from files on your local filesystem. This is the most efficient method for local files. |
| 40 | + |
| 41 | +**Requirements:** |
| 42 | +- The `UMBRACO_ALLOWED_MEDIA_PATHS` environment variable must be configured with allowed directories |
| 43 | +- File paths must be absolute paths |
| 44 | +- Files must exist within the allowed directories |
| 45 | + |
| 46 | +**Example prompt:** |
| 47 | +``` |
| 48 | +Upload the product image as "Product Photo" |
| 49 | +to the Products media folder |
| 50 | +``` |
| 51 | + |
| 52 | +**Security Note:** The MCP server validates all file paths to prevent directory traversal attacks and ensures files are only accessed from explicitly allowed directories. |
| 53 | + |
| 54 | +### URL |
| 55 | + |
| 56 | +Download and upload media from web URLs. The MCP server fetches the content and creates the media item. |
| 57 | + |
| 58 | +**Requirements:** |
| 59 | +- Valid HTTP/HTTPS URL |
| 60 | +- Accessible resource (30-second timeout) |
| 61 | +- Appropriate file extension or Content-Type header |
| 62 | + |
| 63 | +**Example prompt:** |
| 64 | +``` |
| 65 | +Download the image from https://example.com/images/hero.jpg and create |
| 66 | +a media item called "Homepage Hero" |
| 67 | +``` |
| 68 | + |
| 69 | +### Base64 |
| 70 | + |
| 71 | +Upload media from base64-encoded data. This method is suitable for small files (e.g svg) but should be used sparingly due to token usage. |
| 72 | + |
| 73 | +**Best Practices:** |
| 74 | +- Use only for small files (under 10KB recommended) |
| 75 | +- Prefer file path or URL methods when possible |
| 76 | +- Base64 encoding significantly increases the size of data sent |
| 77 | + |
| 78 | +**Example prompt:** |
| 79 | +``` |
| 80 | +Create an svg media item of a unicorn |
| 81 | +``` |
| 82 | + |
| 83 | +## Configuration |
| 84 | + |
| 85 | +### Environment Variables |
| 86 | + |
| 87 | +To use file path uploads, configure the allowed directories in your MCP server environment: |
| 88 | + |
| 89 | +```json |
| 90 | +{ |
| 91 | + "umbraco-mcp": { |
| 92 | + "command": "npx", |
| 93 | + "args": ["@umbraco-cms/mcp-dev@beta"], |
| 94 | + "env": { |
| 95 | + "UMBRACO_CLIENT_ID": "your-client-id", |
| 96 | + "UMBRACO_CLIENT_SECRET": "your-client-secret", |
| 97 | + "UMBRACO_BASE_URL": "https://localhost:12345", |
| 98 | + "UMBRACO_ALLOWED_MEDIA_PATHS": "/tmp/uploads,/Users/username/downloads", |
| 99 | + "UMBRACO_INCLUDE_TOOL_COLLECTIONS": "media,temporary-file" |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +Multiple paths can be specified by separating them with commas. |
| 106 | + |
| 107 | +## Usage Examples |
| 108 | + |
| 109 | +### Creating a Single Image |
| 110 | + |
| 111 | +Upload a local image file to a specific media folder: |
| 112 | + |
| 113 | +**Prompt:** |
| 114 | +``` |
| 115 | +Upload the file team-photo as "Team Photo 2024" |
| 116 | +to the Team Photos media folder |
| 117 | +``` |
| 118 | + |
| 119 | +The MCP server will: |
| 120 | +1. Validate the file path is allowed |
| 121 | +2. Determine the appropriate media type (Image) |
| 122 | +3. Upload the file to Umbraco's temporary storage |
| 123 | +4. Create the media item with correct properties |
| 124 | +5. Clean up temporary files |
| 125 | + |
| 126 | +### Batch Creating Media |
| 127 | + |
| 128 | +Upload multiple files at once (up to 20 files per batch): |
| 129 | + |
| 130 | +**Prompt:** |
| 131 | +``` |
| 132 | +Upload all images from the product-photos folder to the |
| 133 | +Products media folder |
| 134 | +``` |
| 135 | + |
| 136 | +The MCP server processes files sequentially and provides a summary of successes and failures. Individual file errors don't stop the batch processing. |
| 137 | + |
| 138 | +### Creating Media from URLs |
| 139 | + |
| 140 | +Download and upload media from remote sources: |
| 141 | + |
| 142 | +**Prompt:** |
| 143 | +``` |
| 144 | +Download these product images and upload them to the Products folder: |
| 145 | +- https://cdn.example.com/products/item1.jpg as "Product 1" |
| 146 | +- https://cdn.example.com/products/item2.jpg as "Product 2" |
| 147 | +- https://cdn.example.com/products/item3.jpg as "Product 3" |
| 148 | +``` |
| 149 | + |
| 150 | +### Creating Media with Specific Types |
| 151 | + |
| 152 | +Explicitly specify the media type: |
| 153 | + |
| 154 | +**Prompt:** |
| 155 | +``` |
| 156 | +Upload the PDF from manual.pdf as "User Manual" |
| 157 | +with media type "Article" to the Documentation folder |
| 158 | +``` |
| 159 | + |
| 160 | +### Creating Media Folders |
| 161 | + |
| 162 | +Organize your media library by creating folders: |
| 163 | + |
| 164 | +**Prompt:** |
| 165 | +``` |
| 166 | +Create a new media folder called "2024 Campaign" under the Marketing folder |
| 167 | +``` |
| 168 | + |
| 169 | +## Advanced Features |
| 170 | + |
| 171 | +### Automatic SVG Detection |
| 172 | + |
| 173 | +The MCP server automatically detects SVG files and corrects the media type from "Image" to "SVG" if needed: |
| 174 | + |
| 175 | +**Prompt:** |
| 176 | +``` |
| 177 | +Upload /Users/username/icons/logo.svg as "Company Logo" |
| 178 | +``` |
| 179 | + |
| 180 | +Even if you specify "Image" as the media type, the server will automatically use "SVG" for .svg files. |
| 181 | + |
| 182 | +### Focal Point for Images |
| 183 | + |
| 184 | +Image media items are automatically created with a center focal point (0.5, 0.5) for optimal cropping behavior in Umbraco. |
| 185 | + |
| 186 | +### Missing File Extensions from URLs |
| 187 | + |
| 188 | +When downloading from URLs without file extensions, the MCP server detects the file type from the Content-Type header: |
| 189 | + |
| 190 | +**Prompt:** |
| 191 | +``` |
| 192 | +Download the image from https://api.example.com/image/123 and create |
| 193 | +a media item |
| 194 | +``` |
| 195 | + |
| 196 | +The server adds the appropriate extension based on the response headers. |
| 197 | + |
| 198 | +### Error Handling |
| 199 | + |
| 200 | +The media creation tools include comprehensive error handling: |
| 201 | + |
| 202 | +- **File not found:** Clear error message with the attempted path |
| 203 | +- **Permission denied:** Indicates the path is not in allowed directories |
| 204 | +- **Invalid media type:** Lists all available media types for your Umbraco instance |
| 205 | +- **Upload failure:** Provides HTTP status codes and error details |
| 206 | +- **Batch errors:** Continue-on-error strategy with per-file status reporting |
| 207 | + |
| 208 | +## Common Scenarios |
| 209 | + |
| 210 | +### Migrating Media from External Sources |
| 211 | + |
| 212 | +Import media files from an external system: |
| 213 | + |
| 214 | +**Prompt:** |
| 215 | +``` |
| 216 | +Download all images listed in this CSV file and upload them to Umbraco with |
| 217 | +the specified names and folder structure |
| 218 | +``` |
| 219 | + |
| 220 | +### Organizing Existing Downloads |
| 221 | + |
| 222 | +Process files from your downloads folder: |
| 223 | + |
| 224 | +**Prompt:** |
| 225 | +``` |
| 226 | +Upload all PDF files from downloads to the Documents |
| 227 | +media folder, using their filenames as media names |
| 228 | +``` |
| 229 | + |
| 230 | +### Creating Product Media |
| 231 | + |
| 232 | +Set up a new product catalog with images: |
| 233 | + |
| 234 | +**Prompt:** |
| 235 | +``` |
| 236 | +Create a "Product Catalog 2024" folder and upload all images from |
| 237 | +/Users/username/products/ into it, organizing by subfolder names |
| 238 | +``` |
| 239 | + |
| 240 | +### Press Kit Distribution |
| 241 | + |
| 242 | +Download press materials from multiple sources: |
| 243 | + |
| 244 | +**Prompt:** |
| 245 | +``` |
| 246 | +Download these press images and create a "Press Kit Q1 2024" folder: |
| 247 | +- Logo: https://brand.example.com/logo-2024.png |
| 248 | +- Product shots from: https://products.example.com/images/... |
| 249 | +``` |
| 250 | + |
| 251 | +## Best Practices |
| 252 | + |
| 253 | +### Performance |
| 254 | + |
| 255 | +- Use **file path** source for local files (most efficient) |
| 256 | +- Use **URL** source for remote files |
| 257 | +- Avoid **base64** for files over 10KB |
| 258 | +- Batch upload multiple files using `create-media-multiple` when possible (up to 20 files) |
| 259 | + |
| 260 | +### Security |
| 261 | + |
| 262 | +- Only configure trusted directories in `UMBRACO_ALLOWED_MEDIA_PATHS` |
| 263 | + |
| 264 | +### Organization |
| 265 | + |
| 266 | +- Create folder structures before uploading files |
| 267 | + |
| 268 | +## Permissions |
| 269 | + |
| 270 | +Media creation requires the user configured in your MCP server to have appropriate permissions: |
| 271 | + |
| 272 | +- **Media Section Access** - Required to create any media |
| 273 | +- **Media Root/Folder Access** - Required to create media in specific folders |
| 274 | +- **Admin Rights** - Not required for basic media creation |
| 275 | + |
| 276 | +The MCP server automatically checks permissions and will report authorization errors if the user lacks access. |
| 277 | + |
| 278 | +## Troubleshooting |
| 279 | + |
| 280 | +### "Path not in allowed directories" Error |
| 281 | + |
| 282 | +**Problem:** You're trying to upload from a path that isn't configured in `UMBRACO_ALLOWED_MEDIA_PATHS`. |
| 283 | + |
| 284 | +**Solution:** Add the directory to your MCP server configuration and restart. |
| 285 | + |
| 286 | +### "Media type not found" Error |
| 287 | + |
| 288 | +**Problem:** The specified media type name doesn't exist in your Umbraco instance. |
| 289 | + |
| 290 | +**Solution:** Check the error message for available media types, or create the custom media type in Umbraco first. |
| 291 | + |
| 292 | +### Batch Upload Timeouts |
| 293 | + |
| 294 | +**Problem:** Large batch uploads are timing out. |
| 295 | + |
| 296 | +**Solution:** Reduce batch size (max 20 files), ensure stable network connection for URL downloads, or upload in multiple smaller batches. |
| 297 | + |
| 298 | +### File Not Found Errors |
| 299 | + |
| 300 | +**Problem:** The specified file path doesn't exist. |
| 301 | + |
| 302 | +**Solution:** Verify the absolute path is correct, check file permissions, and ensure the file exists at the specified location. |
| 303 | + |
0 commit comments