Class DefaultMcpUriTemplateManager

java.lang.Object
io.modelcontextprotocol.util.DefaultMcpUriTemplateManager
All Implemented Interfaces:
McpUriTemplateManager

public class DefaultMcpUriTemplateManager extends Object implements 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 Details

    • DefaultMcpUriTemplateManager

      public DefaultMcpUriTemplateManager(String uriTemplate)
      Constructor for DefaultMcpUriTemplateManager.
      Parameters:
      uriTemplate - The URI template to be used for variable extraction
  • Method Details

    • getVariableNames

      public List<String> getVariableNames()
      Extract URI variable names from a URI template.
      Specified by:
      getVariableNames in interface McpUriTemplateManager
      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

      public Map<String,String> extractVariableValues(String requestUri)
      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:
      extractVariableValues in interface McpUriTemplateManager
      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

      public boolean matches(String uri)
      Check if a URI matches the uriTemplate with variables.
      Specified by:
      matches in interface McpUriTemplateManager
      Parameters:
      uri - The URI to check
      Returns:
      true if the URI matches the pattern, false otherwise
    • isUriTemplate

      public boolean isUriTemplate(String uri)
      Description copied from interface: McpUriTemplateManager
      Check if the given URI is a URI template.
      Specified by:
      isUriTemplate in interface McpUriTemplateManager
      Returns:
      Returns true if the URI contains variables in the format {variableName}