aldettinger commented on PR #9509:
URL: https://github.com/apache/camel-quarkus/pull/9509#issuecomment-7137317637

   **Prompts: cohabitation test scenarios**
   
   Same exercise as the resource-template note, for prompts.
   
   Four producers share one prompt name namespace on the default server: 
`@io.quarkiverse.mcp.server.Prompt`, `@org.mcpjava.server.prompts.Prompt`, 
programmatic `PromptManager#newPrompt`, and Camel `ai-prompt` routes. All land 
in the same `PromptManagerImpl.prompts` map keyed by `FeatureKey(name, 
serverName)` — `DotNames` carries both `PROMPT` and `MCPJAVA_PROMPT`, and 
`quarkus-mcp-server-core` has a non-optional dependency on 
`org.mcpjava:mcp-server-api`, so the portable annotations are on every 
application's classpath already.
   
   The guard in `promptAdded` handles all of them correctly. It just has no 
coverage: the itest registers no application prompts at all, so unlike tools, 
resources and resource templates, prompts have no clash test.
   
   Add a `QuarkusDefinedPrompts` bean, following `QuarkusDefinedTools`:
   
   ```java
   public class QuarkusDefinedPrompts {
   
       public static final String QUARKIVERSE_PROMPT_ANSWER = "Quarkus prompt 
(declared with @Prompt)";
       public static final String MCPJAVA_PROMPT_ANSWER = "Quarkus prompt 
(declared with the mcpjava @Prompt)";
   
       @Prompt(name = "clashing_prompt", description = "Name also asked for by 
an ai-prompt route")
       PromptMessage clashing() {
           return new PromptMessage(Role.USER, new 
TextContent(QUARKIVERSE_PROMPT_ANSWER));
       }
   
       // fully qualified to show the contrast with the quarkiverse annotation 
above
       @org.mcpjava.server.prompts.Prompt(name = "mcpjava_clashing_prompt",
               description = "Name also asked for by an ai-prompt route")
       org.mcpjava.server.prompts.PromptResponse mcpJavaClashing() {
           return org.mcpjava.server.prompts.PromptResponse.of(
                   org.mcpjava.server.Role.USER,
                   
org.mcpjava.server.content.TextContent.of(MCPJAVA_PROMPT_ANSWER));
       }
   
       void registerPrompts(@Observes StartupEvent event) {
           // looked up, not injected, as in QuarkusDefinedResources
           PromptManager promptManager = 
Arc.container().instance(PromptManager.class).get();
           promptManager.newPrompt("user_prompt")
                   .setDescription("Prompt registered by the application")
                   .setHandler(args -> new PromptResponse(null,
                           List.of(new PromptMessage(Role.USER, new 
TextContent("user")))))
                   .register();
           // same name as greeting-prompt-route, but on the other MCP server
           promptManager.newPrompt("greeting")
                   .setServerName("other")
                   .setDescription("Prompt registered by the application on 
another server")
                   .setHandler(args -> new PromptResponse(null,
                           List.of(new PromptMessage(Role.USER, new 
TextContent("other")))))
                   .register();
       }
   }
   ```
   
   and three refused routes in `McpServerRoutes`:
   
   ```java
   from("ai-prompt:clashing_prompt?tags=conformance&description=Name already 
taken by an annotated prompt")
           .routeId("clashing-prompt-route")
           .autoStartup(false)
           .setBody(constant("camel"));
   
   from("ai-prompt:mcpjava_clashing_prompt?tags=conformance&description=Name 
already taken by an mcpjava prompt")
           .routeId("mcpjava-clashing-prompt-route")
           .autoStartup(false)
           .setBody(constant("camel"));
   
   from("ai-prompt:user_prompt?tags=conformance&description=Name already taken 
by a programmatic prompt")
           .routeId("clashing-programmatic-prompt-route")
           .autoStartup(false)
           .setBody(constant("camel"));
   ```
   
   Scenarios 1-3 (quarkiverse annotation, mcpjava annotation, programmatic) 
mirror `testStoppingRefusedToolKeepsApplicationTool`:
   
   ```java
   @Test
   void testStoppingRefusedPromptKeepsApplicationPrompt() {
       controlRoute("clashing-prompt-route", "start");
       assertThat(routeStatus("clashing-prompt-route")).isEqualTo("Started");
       controlRoute("clashing-prompt-route", "stop");
       assertThat(routeStatus("clashing-prompt-route")).isEqualTo("Stopped");
   
       client().when()
               .promptsGet("clashing_prompt", Map.of(), response -> assertThat(
                       response.messages().get(0).content().asText().text())
                               
.isEqualTo(QuarkusDefinedPrompts.QUARKIVERSE_PROMPT_ANSWER))
               .thenAssertResults();
   }
   ```
   
   Scenario 4 needs no new route: stop `greeting-prompt-route` and assert via 
the existing `otherClient()` that `greeting` on server `other` still resolves — 
`removePrompt(name, McpServer.DEFAULT)` is scoped to the default server. Prompt 
analogue of `testStoppingToolRouteKeepsToolOfOtherServer`.
   
   API shapes checked against quarkus-mcp-server 2.0.4 and mcp-server-api 
1.0.0, but not compiled, since the module does not build on `camel-main` while 
#9362 is open.
   
   _Claude Code (Opus 5) on behalf of Alexandre Gallice_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to