Croway commented on code in PR #9509:
URL: https://github.com/apache/camel-quarkus/pull/9509#discussion_r4585972744
##########
extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngineFactory.java:
##########
@@ -35,7 +39,17 @@ public class QuarkusMcpServerEngineFactory {
@Inject
ResourceManager resourceManager;
+ @Inject
+ ResourceTemplateManager resourceTemplateManager;
+
+ @Inject
+ PromptManager promptManager;
+
+ @Inject
+ CurrentIdentityAssociation currentIdentityAssociation;
Review Comment:
**Applications without a security extension fail to build.** Only the
`quarkus-security` extension registers a `CurrentIdentityAssociation` bean
(`SecurityProcessor#registerCurrentIdentityAssociationBean`).
`quarkus-vertx-http` and quarkus-mcp-server core depend only on the
`io.quarkus.security:quarkus-security` library, which registers no bean. That's
why quarkus-mcp-server itself injects `Instance<CurrentIdentityAssociation>`
and checks `isResolvable()`. The dependency layout is the same in Quarkus
4.0.0.CR1.
I reproduced it on Quarkus 3.40.1 with `quarkus-mcp-server-http` 2.0.4 and
an `@Unremovable @Singleton` bean that has the same `@Inject
CurrentIdentityAssociation` field:
```
Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an
exception: jakarta.enterprise.inject.spi.DeploymentException:
jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied
dependency for type io.quarkus.security.identity.CurrentIdentityAssociation and
qualifiers [@Default]
```
It still fails with `quarkus-resteasy` added, and it builds once
`quarkus-security` is added. The extension depends only on
`quarkus-mcp-server-http`, so after this PR a Camel Quarkus app that serves MCP
without authentication no longer builds. The integration test doesn't show it,
because this PR adds `quarkus-oidc` to it.
Suggestion: inject `Instance<CurrentIdentityAssociation>` and hand the
engine `null` when it isn't resolvable, so that `currentToolCallContext()`
returns `McpToolCallContext.EMPTY`. A test module with no security extension
would catch a regression.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
##########
integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerTest.java:
##########
@@ -538,6 +662,21 @@ void testResourcesListReflectsRouteStopAndStart() {
.thenAssertResults());
}
+ @Test
+ @TestSecurity(user = "alice", roles = { "admin", "operator" })
Review Comment:
**This test fails in `McpServerIT`.** `McpServerIT` extends this class, but
`@TestSecurity` "is only available for `@QuarkusTest` and will **not** work on
a `@QuarkusIntegrationTest`" (Quarkus security testing guide). In the packaged
or native run the call is anonymous, so the tool returns
`no-principal|no-name|` instead of `alice|alice|admin,operator`.
Suggestion: annotate it with `@DisabledOnIntegrationTest`. Once the Keycloak
test has its own IT class, it covers the integration-test path.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
##########
integration-tests/mcp-server/pom.xml:
##########
@@ -57,11 +55,16 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-oidc</artifactId>
Review Comment:
**Adding `quarkus-oidc` here affects the whole module:**
- `McpServerTest` and `McpServerIT` don't set `quarkus.oidc.auth-server-url`
(only `McpServerKeycloakTestResource` does), so Dev Services for Keycloak
starts a Keycloak container for them as well.
- It hides the `CurrentIdentityAssociation` build failure (see the comment
on `QuarkusMcpServerEngineFactory`), because the module now always has a
security extension.
- `McpServerOAuthTest` has no `@QuarkusIntegrationTest` counterpart, so the
OIDC path never runs in native mode.
Suggestion: move the OIDC tests (`McpServerOAuthTest`, the Keycloak test
resource and the realm file) into their own module, for example
`integration-tests/mcp-server-oidc`, with an `McpServerOAuthIT`. This module
then stays without a security extension and covers the anonymous case. If the
tests stay here, turn Dev Services off
(`quarkus.keycloak.devservices.enabled=false`) and disable the default OIDC
tenant in `application.properties`, and let the test resource turn the tenant
back on.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
##########
integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerKeycloakTestResource.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.mcp.server.it;
+
+import java.time.Duration;
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import io.quarkus.test.keycloak.server.KeycloakContainer;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.utility.MountableFile;
+
+/** Starts a real Keycloak container for MCP/OIDC integration tests. */
+public class McpServerKeycloakTestResource implements
QuarkusTestResourceLifecycleManager {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(McpServerKeycloakTestResource.class);
+ private static final String REALM_NAME = "mcp";
+
+ private KeycloakContainer keycloak;
+
+ @Override
+ public Map<String, String> start() {
+ System.setProperty("keycloak.docker.image",
+
ConfigProvider.getConfig().getValue("keycloak.container.image", String.class));
+
+ keycloak = new KeycloakContainer()
+ .withStartupTimeout(Duration.ofMinutes(5))
+ .withLogConsumer(new Slf4jLogConsumer(LOG))
+ .withCopyFileToContainer(
+ MountableFile.forClasspathResource("/mcp-realm.json"),
+ "/opt/keycloak/data/import/mcp-realm.json")
+ .withCommand("start", "--import-realm", "--verbose");
+ keycloak.start();
+
+ String issuer = keycloak.getServerUrl() + "/realms/" + REALM_NAME;
+ return Map.ofEntries(
+ Map.entry("quarkus.oidc.auth-server-url", issuer),
+ Map.entry("quarkus.oidc.client-id", "mcp-test-client"),
+ Map.entry("quarkus.oidc.credentials.secret",
"mcp-test-secret"),
+ Map.entry("quarkus.oidc.application-type", "service"),
+ Map.entry("quarkus.oidc.token.principal-claim",
"preferred_username"),
+ Map.entry("quarkus.oidc.roles.role-claim-path",
"realm_access/roles"),
+ Map.entry("quarkus.oidc.tenant-paths", "/mcp,/mcp/*"),
+ Map.entry("quarkus.oidc.resource-metadata.enabled", "true"),
+ Map.entry("quarkus.oidc.resource-metadata.force-https-scheme",
"false"),
+ Map.entry("quarkus.http.host", "localhost"),
Review Comment:
**`untrustedOriginIsRejectedEvenWithValidBearerToken` tests
quarkus-mcp-server's DNS-rebinding check, which a default production setup
doesn't run.** The 403 comes from quarkus-mcp-server's `HttpMcpServerRecorder`,
which checks the `Origin` header only when `quarkus.http.host` is a loopback
name. That's why this resource sets `quarkus.http.host=localhost`. In prod mode
Quarkus binds to `0.0.0.0` by default, so `/mcp` then accepts any `Origin`.
Camel Main (`McpServerOrigins`, with loopback defaults and
`camel.server.mcp-allowed-origins`) and Spring Boot
(`camel.mcp-server.allowed-origins`) check it whatever the bind address.
Suggestion: state in the usage guide that Origin validation on Quarkus is
this localhost-only check from quarkus-mcp-server, and open a follow-up issue
for an allow-list, either in Camel Quarkus or upstream in quarkus-mcp-server.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
##########
extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java:
##########
@@ -191,6 +265,357 @@ public boolean supportsResources() {
return true;
}
+ @Override
+ public void resourceTemplateAdded(McpServerResourceTemplate
resourceTemplate) {
+ AiResourceUriTemplate matcher;
+ try {
+ matcher = new
AiResourceUriTemplate(resourceTemplate.uriTemplate());
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException(
+ "Unsupported MCP resource template '" +
resourceTemplate.uriTemplate() + "'", e);
+ }
+
+ // Retry cleanup if a previous route stop failed to remove this
template.
+ try {
+ removeRegisteredResourceTemplate(resourceTemplate.uriTemplate());
+ } catch (Exception e) {
+ throw new McpServerRefusedException(
+ "Previously registered MCP resource template '" +
resourceTemplate.uriTemplate()
+ + "' could not be removed before re-registration",
+ e);
+ }
+
+ // A template must not shadow an application-defined resource or
another application-defined template on the
+ // default MCP server. Definitions on other MCP servers are
independent and must remain untouched.
+ for (ResourceManager.ResourceInfo existing : resourceManager) {
Review Comment:
**A template is refused when any static resource on the default server
matches it, including Camel's own `ai-resource` routes.** Neither
`VertxMcpServerEngine` nor the Spring Boot `SpringAiMcpServerEngine` does this.
quarkus-mcp-server also tries an exact static URI before any template
(`ResourceManagerImpl#getInvoker`), so the template can't shadow the resource.
Example: two tagged routes,
`ai-resource:readme?resourceUri=docs://files/readme` and
`ai-resource:file?uriTemplate=docs://files/{name}`. `McpServerBridge#doStart`
publishes resources before templates, so on Quarkus the template is always
refused at startup, while Camel Main and Spring Boot serve both. If the
resource route starts later (for example with `autoStartup=false`, started by
hand), both are served, so the outcome also depends on the start order.
Suggestion: drop this loop and keep the template-vs-template check below it.
That one is needed, since quarkus-mcp-server fails the read with "Multiple
resource templates match uri" when two templates match.
This comes from reading the code: it can't run on `camel-main` until a
Quarkus 4 compatible quarkus-mcp-server is released.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
##########
extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java:
##########
@@ -86,6 +124,39 @@ public void initialize(McpServerInfo info) {
LOG.debug("quarkus-mcp-server engine initialized; serving
configuration is owned by quarkus.mcp.server.*");
}
+ /**
+ * Converts the current Quarkus request identity to the transport-neutral
Camel MCP context.
+ *
+ * The CurrentIdentityAssociation is request scoped. It is deliberately
read inside the
+ * tool callback so concurrent MCP requests cannot share or overwrite each
other's identity.
+ */
+ private McpToolCallContext currentToolCallContext() {
+ SecurityIdentity identity = currentIdentityAssociation.getIdentity();
+ if (identity == null || identity.isAnonymous()) {
+ return McpToolCallContext.EMPTY;
+ }
+
+ Principal principal = identity.getPrincipal();
+ String principalName = principal != null ? principal.getName() : null;
+ if (principalName != null && principalName.isBlank()) {
+ principalName = null;
+ }
+
+ List<String> roles = identity.getRoles().stream()
+ .filter(role -> role != null && !role.isBlank())
+ .sorted()
+ .toList();
+
+ if (principal == null && principalName == null && roles.isEmpty()) {
+ return McpToolCallContext.EMPTY;
+ }
+
+ return new McpToolCallContext(
Review Comment:
**The OAuth subject, scopes and claims are never set.** Camel Main fills
`CamelMcpOAuthSubject`, `CamelMcpOAuthScopes` and `CamelMcpOAuthClaims` from
the validated token, and since apache/camel-spring-boot#2094 Spring Boot fills
them as well. The three-argument constructor used here leaves them `null`.
Example: a tool route whose `AuthorizationPolicy` requires a scope in
`CamelMcpOAuthScopes` works on Main and Spring Boot. On Quarkus it denies every
caller, including callers whose token has that scope.
The PR description lists this as remaining work. With `quarkus-oidc` and a
JWT bearer token, `identity.getPrincipal()` is a `JsonWebToken`, so the subject
(`getSubject()`), the claims (`getClaimNames()` / `getClaim()`) and the scopes
(the `scope` claim split on whitespace) are all available. The check needs a
guard for when the MicroProfile JWT API isn't on the classpath. If this stays
out of scope, please say in the Caller identity section of the docs that these
properties are not set on Quarkus, and open a follow-up issue.
_Claude Code (Opus 5.5) on behalf of Federico Mariani_
--
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]