Interface McpResourceTemplateHandler
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA three-argument function from (uri,variables,ctx) to aMcpResourceOutcome, matchingMcpResourceTemplateHandler.ReadFunction.read(String, Map, BeanStore)'s signature. -
Method Summary
Modifier and TypeMethodDescriptiondefault McpCompleterReturns the completer for one of this template's declared variables.Returns the static descriptor for this resource template.static McpResourceTemplateHandlerof(McpResourceTemplateSpec descriptor, McpResourceTemplateHandler.ReadFunction read) Builds a handler from a fixed descriptor and areadlambda.Reads the resource body for a concrete URI matched against this template.
-
Method Details
-
of
static McpResourceTemplateHandler of(McpResourceTemplateSpec descriptor, McpResourceTemplateHandler.ReadFunction read) Builds a handler from a fixed descriptor and areadlambda.The sanctioned one-expression path for registering a resource template: wires both
descriptor()andread(String, Map, BeanStore)from a single call.- Parameters:
descriptor- The static descriptor returned from everydescriptor()call. Must not benull and must carry a non-blankuriTemplate(routing andcompletion/completeboth match on it, so a templateless registration would be silently unreachable). Must not benull .read- The read body, invoked with the concrete URI, its captured template variables, and the per-request bean store. Must not benull .- Returns:
- A new handler wiring both. Never
null .
-
descriptor
Returns the static descriptor for this resource template.The
uriTemplatevalue is used by the boundMcpRevisionto route incomingresources/readrequests and bycompletion/completeto identify this template, so each handler in anMcpServerConfigmust 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 theresources/readrequest.variables- An immutable, insertion-ordered map of this template's declared variables to their decoded values, captured fromuri.ctx- Per-request bean store. Nevernull.- Returns:
- The resource contents, or
nullif this template does not serveuri, which is reported as resource-not-found. Anullresult never falls through to a less-specific template.
-
completer
Returns the completer for one of this template's declared variables.- Parameters:
variableName- The variable name from acompletion/completerequest.- Returns:
- The completer for that variable, or
nullif none is registered. Callers must treat an undeclared variable name as having no completer regardless of what this method returns.
-