ramu11 commented on code in PR #9509:
URL: https://github.com/apache/camel-quarkus/pull/9509#discussion_r4704337624
##########
extensions/mcp-server/runtime/src/main/java/org/apache/camel/quarkus/component/mcp/server/QuarkusMcpServerEngine.java:
##########
@@ -191,6 +353,321 @@ 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);
+ }
+
+ // Multiple matching templates make resource reads ambiguous in
quarkus-mcp-server.
+ // Definitions on other MCP servers are independent and must remain
untouched.
+ for (ResourceTemplateManager.ResourceTemplateInfo existing :
resourceTemplateManager) {
+ if (existing.serverNames().contains(McpServer.DEFAULT)
+ && templatesOverlap(matcher, existing.uriTemplate())) {
+ throw new McpServerRefusedException(
+ "Resource template '" + resourceTemplate.uriTemplate()
+ + "' overlaps resource template '"
+ + existing.uriTemplate() + "'");
+ }
+ }
+
+ ResourceTemplateManager.ResourceTemplateDefinition definition =
resourceTemplateManager
+ .newResourceTemplate(resourceTemplate.name())
+ .setUriTemplate(resourceTemplate.uriTemplate())
Review Comment:
Addressed in commit `ed222bd3d881889857afc2ce375d7e46f326bfa7`.
Updated resource-template registration and read handling in
`QuarkusMcpServerEngine`:
- Added validation to reject regex metacharacters in Camel template literal
URI text, since Quarkiverse interprets these as raw regular expressions.
- Rejects variable names that do not match the Quarkiverse `{\\w+}`
convention, such as `{customer.id}`.
- Added overlap protection against application-defined Quarkiverse templates
using regex syntax, including regex expressions in the URI authority.
- Added read-time matching against Camel's URI-template matcher. Requests
that Quarkiverse's regex matcher accepts but Camel's matcher rejects, such as a
query suffix on the final path segment, now return `RESOURCE_NOT_FOUND`.
Added regression coverage for regex literals, unsupported variable names,
path and authority overlap, and query-suffix reads. Updated both the extension
usage guide and reference documentation to explain the matcher restrictions.
The MCP integration-test build passes with these changes.
--
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]