|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.camel.dsl.jbang.core.commands.mcp; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import jakarta.enterprise.context.ApplicationScoped; |
| 22 | + |
| 23 | +import io.quarkiverse.mcp.server.Prompt; |
| 24 | +import io.quarkiverse.mcp.server.PromptArg; |
| 25 | +import io.quarkiverse.mcp.server.PromptMessage; |
| 26 | + |
| 27 | +/** |
| 28 | + * MCP Prompt definitions that provide structured multi-step workflows for LLMs. |
| 29 | + * <p> |
| 30 | + * Prompts guide the LLM through orchestrating multiple existing tools in the correct sequence, rather than requiring it |
| 31 | + * to discover the workflow on its own. |
| 32 | + */ |
| 33 | +@ApplicationScoped |
| 34 | +public class PromptDefinitions { |
| 35 | + |
| 36 | + /** |
| 37 | + * Guided workflow for building a Camel integration from requirements. |
| 38 | + */ |
| 39 | + @Prompt(name = "camel_build_integration", |
| 40 | + description = "Guided workflow to build a Camel integration: " |
| 41 | + + "analyze requirements, discover components and EIPs, " |
| 42 | + + "generate a YAML route, validate it, and run a security check.") |
| 43 | + public List<PromptMessage> buildIntegration( |
| 44 | + @PromptArg(name = "requirements", |
| 45 | + description = "Natural-language description of what the integration should do") String requirements, |
| 46 | + @PromptArg(name = "runtime", description = "Target runtime: main, spring-boot, or quarkus (default: main)", |
| 47 | + required = false) String runtime) { |
| 48 | + |
| 49 | + String resolvedRuntime = runtime != null && !runtime.isBlank() ? runtime : "main"; |
| 50 | + |
| 51 | + String instructions = """ |
| 52 | + You are building a Camel integration for the "%s" runtime. |
| 53 | +
|
| 54 | + ## Requirements |
| 55 | + %s |
| 56 | +
|
| 57 | + ## Workflow |
| 58 | +
|
| 59 | + Follow these steps in order: |
| 60 | +
|
| 61 | + ### Step 1: Identify components |
| 62 | + Analyze the requirements above and identify the Camel components needed. |
| 63 | + Call `camel_catalog_components` with a relevant filter and runtime="%s" to find matching components. |
| 64 | +
|
| 65 | + ### Step 2: Identify EIPs |
| 66 | + Determine which Enterprise Integration Patterns are needed (e.g., split, aggregate, filter, choice). |
| 67 | + Call `camel_catalog_eips` with a relevant filter to find matching patterns. |
| 68 | +
|
| 69 | + ### Step 3: Get component details |
| 70 | + For each component you selected, call `camel_catalog_component_doc` with the component name \ |
| 71 | + and runtime="%s" to get its endpoint options, required parameters, and URI syntax. |
| 72 | +
|
| 73 | + ### Step 4: Build the route |
| 74 | + Using the gathered information, write a complete YAML route definition. \ |
| 75 | + Use correct component URI syntax and required options from the documentation. |
| 76 | +
|
| 77 | + ### Step 5: Validate |
| 78 | + Call `camel_validate_yaml_dsl` with the generated YAML route to check for syntax errors. |
| 79 | + If validation fails, fix the issues and re-validate. |
| 80 | +
|
| 81 | + ### Step 6: Security review |
| 82 | + Call `camel_route_harden_context` with the generated route and format="yaml" \ |
| 83 | + to identify security concerns. Address any critical or high-severity findings. |
| 84 | +
|
| 85 | + ### Step 7: Present result |
| 86 | + Present the final YAML route along with: |
| 87 | + - A brief explanation of each component and EIP used |
| 88 | + - Any security recommendations from Step 6 |
| 89 | + - Instructions for running the route (e.g., with camel-jbang) |
| 90 | + """.formatted(resolvedRuntime, requirements, resolvedRuntime, resolvedRuntime); |
| 91 | + |
| 92 | + return List.of(PromptMessage.withUserRole(instructions)); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Guided workflow for migrating a Camel project to a new version. |
| 97 | + */ |
| 98 | + @Prompt(name = "camel_migrate_project", |
| 99 | + description = "Guided workflow to migrate a Camel project: " |
| 100 | + + "analyze the pom.xml, check compatibility, " |
| 101 | + + "get OpenRewrite recipes, search migration guides, " |
| 102 | + + "and produce a migration summary.") |
| 103 | + public List<PromptMessage> migrateProject( |
| 104 | + @PromptArg(name = "pomContent", description = "The project's pom.xml file content") String pomContent, |
| 105 | + @PromptArg(name = "targetVersion", description = "Target Camel version to migrate to (e.g., 4.18.0)", |
| 106 | + required = false) String targetVersion) { |
| 107 | + |
| 108 | + String versionNote = targetVersion != null && !targetVersion.isBlank() |
| 109 | + ? "Target version: " + targetVersion |
| 110 | + : "Target version: latest stable (determine from camel_version_list)"; |
| 111 | + |
| 112 | + String instructions = """ |
| 113 | + You are migrating a Camel project to a newer version. |
| 114 | +
|
| 115 | + ## %s |
| 116 | +
|
| 117 | + ## Project pom.xml |
| 118 | + ```xml |
| 119 | + %s |
| 120 | + ``` |
| 121 | +
|
| 122 | + ## Workflow |
| 123 | +
|
| 124 | + Follow these steps in order: |
| 125 | +
|
| 126 | + ### Step 1: Analyze the project |
| 127 | + Call `camel_migration_analyze` with the pom.xml content above. |
| 128 | + This detects the current runtime, Camel version, Java version, and component dependencies. |
| 129 | +
|
| 130 | + ### Step 2: Determine target version |
| 131 | + If no target version was specified, call `camel_version_list` with the detected runtime \ |
| 132 | + to find the latest stable version. For LTS releases, filter with lts=true. |
| 133 | +
|
| 134 | + ### Step 3: Check compatibility |
| 135 | + Based on the detected runtime from Step 1: |
| 136 | + - For **wildfly** or **karaf** runtimes: call `camel_migration_wildfly_karaf` with the pom.xml \ |
| 137 | + content, target runtime, and target version. |
| 138 | + - For **main**, **spring-boot**, or **quarkus** runtimes: call `camel_migration_compatibility` \ |
| 139 | + with the detected components, current version, target version, runtime, and Java version. |
| 140 | +
|
| 141 | + Review any blockers (e.g., Java version too old) and warnings. |
| 142 | +
|
| 143 | + ### Step 4: Get migration recipes |
| 144 | + Call `camel_migration_recipes` with the runtime, current version, target version, \ |
| 145 | + Java version, and dryRun=true to get the OpenRewrite Maven commands. |
| 146 | +
|
| 147 | + ### Step 5: Search for breaking changes |
| 148 | + For each component detected in Step 1, call `camel_migration_guide_search` \ |
| 149 | + with the component name to find relevant breaking changes and rename mappings. |
| 150 | +
|
| 151 | + ### Step 6: Produce migration summary |
| 152 | + Present a structured summary: |
| 153 | + - **Current state**: runtime, Camel version, Java version, component count |
| 154 | + - **Target state**: target version, required Java version |
| 155 | + - **Blockers**: issues that must be resolved before migration |
| 156 | + - **Breaking changes**: component renames, API changes found in guides |
| 157 | + - **Migration commands**: the OpenRewrite commands from Step 4 |
| 158 | + - **Manual steps**: any changes that OpenRewrite cannot automate |
| 159 | + """.formatted(versionNote, pomContent); |
| 160 | + |
| 161 | + return List.of(PromptMessage.withUserRole(instructions)); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Guided workflow for a security review of a Camel route. |
| 166 | + */ |
| 167 | + @Prompt(name = "camel_security_review", |
| 168 | + description = "Guided workflow to perform a security audit of a Camel route: " |
| 169 | + + "analyze security-sensitive components, check for vulnerabilities, " |
| 170 | + + "and produce an actionable audit checklist.") |
| 171 | + public List<PromptMessage> securityReview( |
| 172 | + @PromptArg(name = "route", description = "The Camel route content to review") String route, |
| 173 | + @PromptArg(name = "format", description = "Route format: yaml, xml, or java (default: yaml)", |
| 174 | + required = false) String format) { |
| 175 | + |
| 176 | + String resolvedFormat = format != null && !format.isBlank() ? format : "yaml"; |
| 177 | + |
| 178 | + String instructions = """ |
| 179 | + You are performing a security audit of a Camel route. |
| 180 | +
|
| 181 | + ## Route (format: %s) |
| 182 | + ``` |
| 183 | + %s |
| 184 | + ``` |
| 185 | +
|
| 186 | + ## Workflow |
| 187 | +
|
| 188 | + Follow these steps in order: |
| 189 | +
|
| 190 | + ### Step 1: Analyze security |
| 191 | + Call `camel_route_harden_context` with the route above and format="%s". |
| 192 | + This returns security-sensitive components, vulnerabilities, and risk levels. |
| 193 | +
|
| 194 | + ### Step 2: Understand route structure |
| 195 | + Call `camel_route_context` with the route and format="%s". |
| 196 | + This returns the components and EIPs used, helping you understand the full data flow. |
| 197 | +
|
| 198 | + ### Step 3: Produce audit checklist |
| 199 | + Using the results from Steps 1 and 2, produce a structured security audit report: |
| 200 | +
|
| 201 | + **Critical Issues** (must fix before production): |
| 202 | + - List all critical-severity concerns from the security analysis |
| 203 | + - For each: describe the issue, the affected component, and the specific fix |
| 204 | +
|
| 205 | + **Warnings** (should fix): |
| 206 | + - List all high and medium-severity concerns |
| 207 | + - For each: describe the risk and the recommended mitigation |
| 208 | +
|
| 209 | + **Positive Findings** (already secured): |
| 210 | + - List all positive security findings (TLS enabled, property placeholders used, etc.) |
| 211 | +
|
| 212 | + **Recommendations**: |
| 213 | + - Provide actionable, prioritized recommendations based on the specific components used |
| 214 | + - Reference the relevant security best practices for each component |
| 215 | + - Include specific configuration examples where applicable |
| 216 | +
|
| 217 | + **Compliance Notes**: |
| 218 | + - Note any components that handle PII or sensitive data |
| 219 | + - Flag any components that communicate over the network without encryption |
| 220 | + """.formatted(resolvedFormat, route, resolvedFormat, resolvedFormat); |
| 221 | + |
| 222 | + return List.of(PromptMessage.withUserRole(instructions)); |
| 223 | + } |
| 224 | +} |
0 commit comments