Interface McpResourceTemplateHandler


Handler for a single MCP resource template.

Implementations declare a descriptor (the McpResourceTemplateSpec returned by resources/templates/list), a read body invoked when this template is selected for a matching resources/read request, and an optional completer for one of the template's declared variables.

A registration whose descriptor.uriTemplate is not one of McpUriTemplateMatcher's reverse-matchable forms remains listable and completable but is never selected for a template-backed read. Use McpServerConfig.addResourceTemplate(McpResourceTemplateSpec...) to register a listing-only template without implementing this interface.

Use of(McpResourceTemplateSpec, ReadFunction) for the common case of wiring both descriptor() and read(String, Map, BeanStore) in a single expression.

  • Method Details

    • of

      Builds a handler from a fixed descriptor and a read lambda.

      The sanctioned one-expression path for registering a resource template: wires both descriptor() and read(String, Map, BeanStore) from a single call.

      Parameters:
      descriptor - The static descriptor returned from every descriptor() call. Must not be null and must carry a non-blank uriTemplate (routing and completion/complete both match on it, so a templateless registration would be silently unreachable). Must not be null.
      read - The read body, invoked with the concrete URI, its captured template variables, and the per-request bean store. Must not be null.
      Returns:
      A new handler wiring both. Never null.
    • descriptor

      Returns the static descriptor for this resource template.

      The uriTemplate value is used by the bound McpRevision to route incoming resources/read requests and by completion/complete to identify this template, so each handler in an McpServerConfig must use a unique template string.

      Returns:
      The resource-template descriptor. Never null.
    • read

      Reads the resource body for a concrete URI matched against this template.
      Parameters:
      uri - The original concrete URI from the resources/read request.
      variables - An immutable, insertion-ordered map of this template's declared variables to their decoded values, captured from uri.
      ctx - Per-request bean store. Never null.
      Returns:
      The resource contents, or null if this template does not serve uri, which is reported as resource-not-found. A null result never falls through to a less-specific template.
    • completer

      default McpCompleter completer(String variableName)
      Returns the completer for one of this template's declared variables.
      Parameters:
      variableName - The variable name from a completion/complete request.
      Returns:
      The completer for that variable, or null if none is registered. Callers must treat an undeclared variable name as having no completer regardless of what this method returns.