-
Notifications
You must be signed in to change notification settings - Fork 675
Open
Description
Bug description
Resource Template does not handle query(?) in URI correctly
Environment
Version: 0.14.0
Steps to reproduce
- Create an MCP resource with the URI: "file://name/search?={search}"
- Try and read that resource with uri: "file://name/search?=abc"
- Notice how it does not match the resource
Expected behavior
Using query(?) in template URI should work.
Cause
The cause for this is that "?" in the URI template is not escaped when it is used to create the Regex for matching a URI.
DefaultMcpUriTemplateManager.java:
@Override
public boolean matches(String uri) {
// If the uriTemplate doesn't contain variables, do a direct comparison
if (!this.isUriTemplate(this.uriTemplate)) {
return uri.equals(this.uriTemplate);
}
// Convert the pattern to a regex
String regex = this.uriTemplate.replaceAll("\\{[^/]+?\\}", "([^/]+?)");
regex = regex.replace("/", "\\/");
//Should also handle ? here.
// Check if the URI matches the regex
return Pattern.compile(regex).matcher(uri).matches();
}

There may be another issue where capturing of the query string is not done correctly either as only the first character of the query string is captured:
DeafaultMcpUriTemplateManagerFactory is also misspelled.
Metadata
Metadata
Assignees
Labels
No labels