Package io.modelcontextprotocol.util
Class DefaultMcpUriTemplateManager
java.lang.Object
io.modelcontextprotocol.util.DefaultMcpUriTemplateManager
- All Implemented Interfaces:
McpUriTemplateManager
Default implementation of the UriTemplateUtils interface.
This class provides methods for extracting variables from URI templates and matching them against actual URIs.
- Author:
- Christian Tzolov
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMcpUriTemplateManager(String uriTemplate) Constructor for DefaultMcpUriTemplateManager. -
Method Summary
Modifier and TypeMethodDescriptionextractVariableValues(String requestUri) Extract URI variable values from the actual request URI.Extract URI variable names from a URI template.booleanisUriTemplate(String uri) Check if the given URI is a URI template.booleanCheck if a URI matches the uriTemplate with variables.
-
Constructor Details
-
DefaultMcpUriTemplateManager
Constructor for DefaultMcpUriTemplateManager.- Parameters:
uriTemplate- The URI template to be used for variable extraction
-
-
Method Details
-
getVariableNames
Extract URI variable names from a URI template.- Specified by:
getVariableNamesin interfaceMcpUriTemplateManager- Parameters:
uriTemplate- The URI template containing variables in the format {variableName}- Returns:
- A list of variable names extracted from the template
- Throws:
IllegalArgumentException- if duplicate variable names are found
-
extractVariableValues
Extract URI variable values from the actual request URI.This method converts the URI template into a regex pattern, then uses that pattern to extract variable values from the request URI.
- Specified by:
extractVariableValuesin interfaceMcpUriTemplateManager- Parameters:
requestUri- The actual URI from the request- Returns:
- A map of variable names to their values
- Throws:
IllegalArgumentException- if the URI template is invalid or the request URI doesn't match the template pattern
-
matches
Check if a URI matches the uriTemplate with variables.- Specified by:
matchesin interfaceMcpUriTemplateManager- Parameters:
uri- The URI to check- Returns:
- true if the URI matches the pattern, false otherwise
-
isUriTemplate
Description copied from interface:McpUriTemplateManagerCheck if the given URI is a URI template.- Specified by:
isUriTemplatein interfaceMcpUriTemplateManager- Returns:
- Returns true if the URI contains variables in the format {variableName}
-