aldettinger commented on PR #9509:
URL: https://github.com/apache/camel-quarkus/pull/9509#issuecomment-7133229215
**Resource templates: suggested test scenarios**
A few things I checked in quarkus-mcp-server 2.0.4 and
`camel-mcp-server-api` that suggest some missing coverage. All of these fit the
existing `McpServerRoutes` / `QuarkusDefinedResources` / `McpServerTest`
patterns.
What the code actually does:
- `ResourceTemplateManagerImpl` keeps declarative `@ResourceTemplate`
methods and programmatically registered templates in the **same** `templates`
map, and `FeatureManagerBase#iterator()` returns `infos().sorted()`. So the
overlap loop in `resourceTemplateAdded` does inspect `@ResourceTemplate`
methods — the itest only has the programmatic variant, so that path is untested.
- `ResourceTemplateDefinitionImpl#register()` rejects **name** collisions
only, never `uriTemplate` collisions. Overlap surfaces at read time as
`Multiple resource templates match uri` (`findMatching`).
- `removeResourceTemplate(name, server)` no-ops when `info().isMethod()`, so
stopping a Camel route can never evict a declarative template.
- "An exact static resource URI can coexist with a template" is not Camel
behaviour — `McpServerBridge#publishResourceTemplate` only checks
template-vs-template. It comes from `ResourceManagerImpl#getInvoker`, which
tries `uriToResource` before delegating to the template manager. Camel does
treat it as an engine contract, via
`McpServerResourceConformanceTestSupport#testFixedResourceTakesPrecedenceOverMatchingTemplate`.
### 1. Static resource wins over a matching template
The docs now assert this, and the PR removed the static-vs-template refusal
after review, so it is worth pinning. It is also order-sensitive:
`McpServerBridge#doStart` publishes resources before templates.
In `McpServerRoutes`, next to `customer-resource-template-route`:
```java
from("ai-resource:vip_customer?resourceUri=crm://customers/vip&tags=conformance"
+ "&description=VIP customer&mimeType=text/plain")
.routeId("vip-customer-resource-route")
.setBody(constant("vip customer"));
```
Assert `resourcesRead("crm://customers/vip")` returns `vip customer` and
`resourcesRead("crm://customers/42")` still returns `customer 42`.
### 2. Camel template vs declarative `@ResourceTemplate`, overlapping URI
Currently only the programmatic form is covered
(`application_resource_template`). Suggest a `QuarkusDefinedResourceTemplates`
class, mirroring `QuarkusDefinedTools`:
```java
@ResourceTemplate(name = "app_annotated_template", uriTemplate =
"crm://annotated/{id}",
description = "Template declared by the application")
TextResourceContents annotated(RequestUri uri, String id) {
return TextResourceContents.create(uri.value(), "annotated " + id);
}
```
plus a refused Camel route:
```java
from("ai-resource:clashing_annotated_template?uriTemplate=crm://annotated/{key}&tags=conformance"
+ "&description=Overlaps an annotated template")
.routeId("clashing-annotated-template-route")
.autoStartup(false)
.setBody(constant("camel"));
```
Then mirror `testStoppingRefusedResourceTemplateKeepsApplicationTemplate`:
start the route, stop it, assert `crm://annotated/42` still returns `annotated
42`. That covers both the refusal and the `isMethod()` removal guard in one
test.
### 3. Camel template vs declarative `@ResourceTemplate`, same name
Different path: `register()` throws `resourceTemplateWithNameAlreadyExists`
rather than the overlap pre-check firing. This is the resource-template
analogue of the existing `clashing_tool` test, and it currently has no
equivalent. Add an `@ResourceTemplate(name = "name_clash_template", uriTemplate
= "crm://annotated-name/{id}")` and a Camel route
`ai-resource:name_clash_template?uriTemplate=crm://unrelated/{id}`
(non-overlapping URI, same name); assert the route is refused and the annotated
template still serves.
### 4. An app template that Camel's parser cannot read must not refuse
Camel's own templates
`templatesOverlap` reasons in `AiResourceUriTemplate`'s dialect (strict
PCHAR, variables in path segments only) about templates quarkus-mcp-server
matches with its own much looser `\{(\w+)\}` to `([^/]+)` translation. When the
app template fails to parse and the schemes match, the Camel template is
refused.
So an application template such as `crm://search?q={term}` — which
quarkus-mcp-server accepts and compiles — makes `AiResourceUriTemplate` throw,
and then **every** Camel template on the `crm` scheme is refused at startup,
including `crm://customers/{id}`. That is fail-closed on a template that could
never have collided.
Suggest treating "cannot parse the other template" as "cannot overlap" (log
at DEBUG) instead of refusing, and adding that template to
`QuarkusDefinedResourceTemplates` as the regression test. Note the test only
passes once the engine change lands, so the two go together.
### 5. Conformance cases not yet mirrored
`McpServerTest` mirrors `McpServerResourceConformanceTestSupport`, and three
template cases from it are missing:
`testFixedResourceTakesPrecedenceOverMatchingTemplate` (see 1),
`testUnmatchedTemplateUriReturnsNotFoundWithoutCallingRoute`, and
`testResourceTemplateLifecycleSendsListChangedNotifications`. Tag selection for
templates is also untested — `McpServerRoutes` has no untagged or wrong-tag
template route, unlike the resource and prompt cases.
_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]