This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 9126a1c57a3 mcp-server: cover ai-resource routes clashing with
@Resource resources (#9535)
9126a1c57a3 is described below
commit 9126a1c57a3bf049f3b978699cca7a75f54baf9c
Author: Alexandre Gallice <[email protected]>
AuthorDate: Thu Dec 3 13:01:13 2026 +0100
mcp-server: cover ai-resource routes clashing with @Resource resources
(#9535)
Resources the application declares with @io.quarkiverse.mcp.server.Resource
were neither tested nor documented; only the ResourceManager ones were.
They are registered at build time, before any route starts, so an
auto-started ai-resource route clashing with one is the only way to reach a
refusal during startup. The existing clashing-resource-route cannot: it is
autoStartup(false), its owner registering on StartupEvent with no ordering
guarantee against route startup.
Three annotated resources, one per outcome, each returning its own content
so that a read tells which resource served it:
- annotated_no_clash, listed and read next to the Camel resources;
- annotated_uri_clash, owning the uri of the camel_uri_clash route, whose
name is free, so the uri is the only cause of the refusal;
- annotated_name_clash, owning the name of the route of the same name,
whose uri is free, so the name is the only cause.
Both branches of the quarkus-mcp-server uniqueness check are reachable this
way; only the uri one was before.
The ERROR logged on a refusal printed the uri in the identifier slot for
both branches, so a name clash named a uri that was free. Log both.
Documented in a new "Mixing with quarkus-mcp-server annotated resources"
section, the counterpart of the one tools already have.
Co-authored-by: Claude Opus 5 <[email protected]>
---
.../pages/reference/extensions/mcp-server.adoc | 43 ++++++++++++++--
.../mcp-server/runtime/src/main/doc/usage.adoc | 42 ++++++++++++++--
.../mcp/server/QuarkusMcpServerEngine.java | 5 +-
.../component/mcp/server/it/McpServerRoutes.java | 11 ++++-
.../mcp/server/it/QuarkusDefinedResources.java | 34 +++++++++++--
.../component/mcp/server/it/McpServerTest.java | 57 ++++++++++++++++++++++
6 files changed, 175 insertions(+), 17 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/mcp-server.adoc
b/docs/modules/ROOT/pages/reference/extensions/mcp-server.adoc
index 98cd48cece1..7e71197b5c5 100644
--- a/docs/modules/ROOT/pages/reference/extensions/mcp-server.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/mcp-server.adoc
@@ -118,11 +118,11 @@ the tagged ones are served as MCP resources, selected by
the same
and clients are notified via `notifications/resources/list_changed`. A failed
read returns a JSON-RPC error with the generic message `Resource read failed`;
a read exceeding `quarkus.camel.mcp-server.resource-timeout` returns
-`Resource read timed out`. Resource names must be unique, as
-quarkus-mcp-server requires: a resource whose name is already taken, or
-whose uri is already used by a resource the application registers with
-quarkus-mcp-server, is refused with an ERROR log, while its route keeps
-running.
+`Resource read timed out`. Resource names and uris must be unique, as
+quarkus-mcp-server requires: a resource whose name or uri is already taken
+is refused with an ERROR log, while its route keeps running. See
+<<extensions-mcp-server-usage-mixing-with-quarkus-mcp-server-annotated-resources,Mixing
with quarkus-mcp-server annotated resources>>
+for resources the application defines itself.
[id="extensions-mcp-server-usage-combining-the-camel-and-quarkus-mcp-server-configuration"]
=== Combining the Camel and quarkus-mcp-server configuration
@@ -241,6 +241,39 @@ application tool is kept and the `ai-tool` route is
therefore not exposed via
MCP. The route still starts and an `ERROR` is logged mentioning the name of the
ignored `ai-tool`.
+[id="extensions-mcp-server-usage-mixing-with-quarkus-mcp-server-annotated-resources"]
+=== Mixing with quarkus-mcp-server annotated resources
+
+Resources work the same way: `ai-resource` routes coexist with resources the
+application defines with quarkus-mcp-server, and both appear in the same
+`resources/list`. For example, a `@Resource`-annotated method:
+
+[source,java]
+----
+public class DocumentationResources {
+
+ @Resource(name = "readme", uri = "app:///readme", description = "Project
README", mimeType = "text/plain")
+ ResourceResponse readme(RequestUri uri) {
+ return new
ResourceResponse(List.of(TextResourceContents.create(uri.value(), "...")));
+ }
+}
+----
+
+is served alongside the `ai-resource` routes. Resources annotated with
+`@Resource` are registered at build time, resources registered via
+`ResourceManager` at runtime, and Camel resources are added and removed
+dynamically with the route lifecycle.
+`quarkus.camel.mcp-server.tags` only selects `ai-resource` routes: the
+resources registered by the application are always exposed.
+
+Choose distinct resource names *and* uris — quarkus-mcp-server requires both
+to be unique. When an `ai-resource` route asks for a name or a uri that a
+resource of the application already has, the application resource is kept and
+the `ai-resource` route is therefore not exposed via MCP. The route still
+starts and an `ERROR` is logged mentioning the name and the uri of the ignored
+`ai-resource`. Stopping such a refused route leaves the application resource
+in place.
+
[id="extensions-mcp-server-usage-dynamic-tools"]
=== Dynamic tools
diff --git a/extensions/mcp-server/runtime/src/main/doc/usage.adoc
b/extensions/mcp-server/runtime/src/main/doc/usage.adoc
index 33abc070c28..1aa4847b919 100644
--- a/extensions/mcp-server/runtime/src/main/doc/usage.adoc
+++ b/extensions/mcp-server/runtime/src/main/doc/usage.adoc
@@ -54,11 +54,11 @@ the tagged ones are served as MCP resources, selected by
the same
and clients are notified via `notifications/resources/list_changed`. A failed
read returns a JSON-RPC error with the generic message `Resource read failed`;
a read exceeding `quarkus.camel.mcp-server.resource-timeout` returns
-`Resource read timed out`. Resource names must be unique, as
-quarkus-mcp-server requires: a resource whose name is already taken, or
-whose uri is already used by a resource the application registers with
-quarkus-mcp-server, is refused with an ERROR log, while its route keeps
-running.
+`Resource read timed out`. Resource names and uris must be unique, as
+quarkus-mcp-server requires: a resource whose name or uri is already taken
+is refused with an ERROR log, while its route keeps running. See
+<<extensions-mcp-server-usage-mixing-with-quarkus-mcp-server-annotated-resources,Mixing
with quarkus-mcp-server annotated resources>>
+for resources the application defines itself.
=== Combining the Camel and quarkus-mcp-server configuration
@@ -173,6 +173,38 @@ application tool is kept and the `ai-tool` route is
therefore not exposed via
MCP. The route still starts and an `ERROR` is logged mentioning the name of the
ignored `ai-tool`.
+=== Mixing with quarkus-mcp-server annotated resources
+
+Resources work the same way: `ai-resource` routes coexist with resources the
+application defines with quarkus-mcp-server, and both appear in the same
+`resources/list`. For example, a `@Resource`-annotated method:
+
+[source,java]
+----
+public class DocumentationResources {
+
+ @Resource(name = "readme", uri = "app:///readme", description = "Project
README", mimeType = "text/plain")
+ ResourceResponse readme(RequestUri uri) {
+ return new
ResourceResponse(List.of(TextResourceContents.create(uri.value(), "...")));
+ }
+}
+----
+
+is served alongside the `ai-resource` routes. Resources annotated with
+`@Resource` are registered at build time, resources registered via
+`ResourceManager` at runtime, and Camel resources are added and removed
+dynamically with the route lifecycle.
+`quarkus.camel.mcp-server.tags` only selects `ai-resource` routes: the
+resources registered by the application are always exposed.
+
+Choose distinct resource names *and* uris — quarkus-mcp-server requires both
+to be unique. When an `ai-resource` route asks for a name or a uri that a
+resource of the application already has, the application resource is kept and
+the `ai-resource` route is therefore not exposed via MCP. The route still
+starts and an `ERROR` is logged mentioning the name and the uri of the ignored
+`ai-resource`. Stopping such a refused route leaves the application resource
+in place.
+
=== Dynamic tools
The exposed tool list follows the route lifecycle: stopping or suspending an
diff --git
a/extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java
b/extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java
index e6d02a540c1..c41bd70a9f8 100644
---
a/extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java
+++
b/extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java
@@ -162,9 +162,8 @@ public class QuarkusMcpServerEngine extends ServiceSupport
implements McpServerE
try {
definition.register();
} catch (IllegalArgumentException e) {
- // quarkus-mcp-server also requires unique names: refuse the
resource, like the bridge does on a uri clash
- LOG.error("Refusing to expose MCP resource '{}': {}. Resource
names and uris must be unique.",
- resource.uri(), e.getMessage());
+ LOG.error("Refusing to expose MCP resource '{}' at uri '{}': {}.
Resource names and uris must be unique.",
+ resource.name(), resource.uri(), e.getMessage());
return;
}
registeredResourceUris.add(resource.uri());
diff --git
a/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerRoutes.java
b/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerRoutes.java
index 3d10441768d..d390351feeb 100644
---
a/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerRoutes.java
+++
b/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerRoutes.java
@@ -154,11 +154,20 @@ public class McpServerRoutes extends RouteBuilder {
+ "&description=Name already taken, must be refused")
.setBody(constant("second"));
- // the uri is taken by the resource registered in
QuarkusDefinedResources, so it is refused once started
from("ai-resource:clashing_resource?resourceUri=camel:///user/clash&tags=conformance"
+ "&description=Uri already taken by an application resource,
must be refused")
.routeId("clashing-resource-route")
.autoStartup(false)
.setBody(constant("camel"));
+
+
from("ai-resource:camel_uri_clash?resourceUri=camel:///annotated/uri-clash&tags=conformance"
+ + "&description=Uri already taken by an annotated resource,
must be refused")
+ .routeId("annotated-uri-clash-route")
+ .setBody(constant("camel uri clash route"));
+
+
from("ai-resource:annotated_name_clash?resourceUri=camel:///camel/name-clash&tags=conformance"
+ + "&description=Name already taken by an annotated resource,
must be refused")
+ .routeId("annotated-name-clash-route")
+ .setBody(constant("camel name clash route"));
}
}
diff --git
a/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/QuarkusDefinedResources.java
b/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/QuarkusDefinedResources.java
index 6353dc7c167..3aac48e918b 100644
---
a/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/QuarkusDefinedResources.java
+++
b/integration-tests/mcp-server/src/main/java/org/apache/camel/quarkus/component/mcp/server/it/QuarkusDefinedResources.java
@@ -18,6 +18,8 @@ package org.apache.camel.quarkus.component.mcp.server.it;
import java.util.List;
+import io.quarkiverse.mcp.server.RequestUri;
+import io.quarkiverse.mcp.server.Resource;
import io.quarkiverse.mcp.server.ResourceManager;
import io.quarkiverse.mcp.server.ResourceResponse;
import io.quarkiverse.mcp.server.TextResourceContents;
@@ -27,13 +29,39 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
/**
- * Resources registered by the application itself through the
quarkus-mcp-server {@link ResourceManager}: one at the
- * same uri as the clashing-resource-route ai-resource route, and one at the
uri of the app-config-route ai-resource
- * route, on another MCP server.
+ * Resources defined by the application itself.
+ * <p>
+ * With {@link Resource}, registered at build time before any route starts:
one per outcome an ai-resource route can
+ * meet, named after it. Each returns its own content, so a read tells which
resource served it.
+ * <p>
+ * With {@link ResourceManager}, registered on startup: one at the uri of the
clashing-resource-route ai-resource
+ * route, and one at the uri of the app-config-route ai-resource route, on
another MCP server.
*/
@ApplicationScoped
public class QuarkusDefinedResources {
+ public static final String NO_CLASH_CONTENT = "read from @Resource
annotated_no_clash";
+ public static final String URI_CLASH_CONTENT = "read from @Resource
annotated_uri_clash";
+ public static final String NAME_CLASH_CONTENT = "read from @Resource
annotated_name_clash";
+
+ /** Clashes with nothing: exposed next to the Camel resources. */
+ @Resource(name = "annotated_no_clash", uri =
"camel:///annotated/no-clash", description = "Resource declared with @Resource,
clashing with nothing", mimeType = "text/plain")
+ ResourceResponse annotatedNoClash(RequestUri uri) {
+ return new
ResourceResponse(List.of(TextResourceContents.create(uri.value(),
NO_CLASH_CONTENT)));
+ }
+
+ /** Owns the uri of the camel_uri_clash route, whose name is free: that
route is refused on the uri. */
+ @Resource(name = "annotated_uri_clash", uri =
"camel:///annotated/uri-clash", description = "Uri also asked for by an
ai-resource route")
+ ResourceResponse annotatedUriClash(RequestUri uri) {
+ return new
ResourceResponse(List.of(TextResourceContents.create(uri.value(),
URI_CLASH_CONTENT)));
+ }
+
+ /** Owns the name of the annotated_name_clash route, whose uri is free:
that route is refused on the name. */
+ @Resource(name = "annotated_name_clash", uri =
"camel:///annotated/name-clash", description = "Name also asked for by an
ai-resource route")
+ ResourceResponse annotatedNameClash(RequestUri uri) {
+ return new
ResourceResponse(List.of(TextResourceContents.create(uri.value(),
NAME_CLASH_CONTENT)));
+ }
+
void registerResources(@Observes StartupEvent event) {
// looked up, not injected: any ResourceManager injection point makes
quarkus-mcp-server advertise
// resources listChanged, which would hide a missing injection in
QuarkusMcpServerEngineFactory
diff --git
a/integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerTest.java
b/integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerTest.java
index f262514f0f5..f89a93af1e5 100644
---
a/integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerTest.java
+++
b/integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerTest.java
@@ -503,6 +503,63 @@ class McpServerTest {
.thenAssertResults();
}
+ @Test
+ void testAnnotatedResourceWithoutClashCoexistsWithCamelResources() {
+ client().when()
+ .resourcesList(page -> assertThat(resourceUris(page))
+ .contains("camel:///annotated/no-clash",
"camel:///config/app.json"))
+ .resourcesRead("camel:///annotated/no-clash",
+ response ->
assertThat(response.contents().get(0).asText().text())
+
.isEqualTo(QuarkusDefinedResources.NO_CLASH_CONTENT))
+ .thenAssertResults();
+ }
+
+ @Test
+ void testCamelResourceCollidingWithAnnotatedResourceUriIsRefused() {
+
assertThat(routeStatus("annotated-uri-clash-route")).isEqualTo("Started");
+ client().when()
+ .resourcesRead("camel:///annotated/uri-clash",
+ response ->
assertThat(response.contents().get(0).asText().text())
+
.isEqualTo(QuarkusDefinedResources.URI_CLASH_CONTENT))
+ .thenAssertResults();
+
+ // stopping the refused route must leave the annotated resource in
place
+ controlRoute("annotated-uri-clash-route", "stop");
+
assertThat(routeStatus("annotated-uri-clash-route")).isEqualTo("Stopped");
+ try {
+ client().when()
+ .resourcesRead("camel:///annotated/uri-clash",
+ response ->
assertThat(response.contents().get(0).asText().text())
+
.isEqualTo(QuarkusDefinedResources.URI_CLASH_CONTENT))
+ .thenAssertResults();
+ } finally {
+ controlRoute("annotated-uri-clash-route", "start");
+ }
+ }
+
+ @Test
+ void testCamelResourceCollidingWithAnnotatedResourceNameIsRefused() {
+
assertThat(routeStatus("annotated-name-clash-route")).isEqualTo("Started");
+ client().when()
+ .resourcesList(page ->
assertThat(resourceUris(page)).doesNotContain("camel:///camel/name-clash"))
+ .resourcesRead("camel:///annotated/name-clash",
+ response ->
assertThat(response.contents().get(0).asText().text())
+
.isEqualTo(QuarkusDefinedResources.NAME_CLASH_CONTENT))
+ .thenAssertResults();
+
+ controlRoute("annotated-name-clash-route", "stop");
+
assertThat(routeStatus("annotated-name-clash-route")).isEqualTo("Stopped");
+ try {
+ client().when()
+ .resourcesRead("camel:///annotated/name-clash",
+ response ->
assertThat(response.contents().get(0).asText().text())
+
.isEqualTo(QuarkusDefinedResources.NAME_CLASH_CONTENT))
+ .thenAssertResults();
+ } finally {
+ controlRoute("annotated-name-clash-route", "start");
+ }
+ }
+
@Test
void testStoppingResourceRouteKeepsResourceOfOtherServer() {
// the application registered a resource at the same uri on another
MCP server