Interface McpResourceHandler
Implementations declare a descriptor (the McpResourceSpec returned by
resources/list) and a read body invoked when the matching
resources/read method runs.
This is a genuine two-method contract, not a single-method one: both descriptor() and
read(String, BeanStore) are abstract, so it is deliberately not annotated
@FunctionalInterface and a bare lambda cannot implement it. Routing calls descriptor()
on every registered handler for both resources/list and resources/read, so a handler
with no usable descriptor is not a valid handler; making descriptor() abstract catches that at
compile time instead of the first request to reach it at runtime. Use of(McpResourceSpec, BiFunction)
for the common case of wiring both in a single expression.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the static descriptor for this resource.static McpResourceHandlerof(McpResourceSpec descriptor, BiFunction<String, BeanStore, McpResourceOutcome> read) Builds a handler from a fixed descriptor and areadlambda.Reads the resource body.
-
Method Details
-
of
static McpResourceHandler of(McpResourceSpec descriptor, BiFunction<String, BeanStore, McpResourceOutcome> read) Builds a handler from a fixed descriptor and areadlambda.The sanctioned one-expression path for registering a resource: unlike a bare lambda (which cannot satisfy this two-method interface at all), this factory wires both
descriptor()andread(String, BeanStore)from a single call.- Parameters:
descriptor- The static descriptor returned from everydescriptor()call. Must not benull and must carry a non-blankuri(routing matches incomingresources/readrequests on uri, not name, so a uri-less resource would be silently unreachable).read- The read body, invoked with the incoming uri 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.The
urivalue is used by the boundMcpRevisionto route incomingresources/readrequests, so each handler in anMcpServerConfigmust use a unique URI.- Returns:
- The resource descriptor. Never
null.
-
read
Reads the resource body.- Parameters:
uri- The URI from theresources/readrequest (matchesdescriptor().uri).ctx- Per-request bean store. Nevernull.- Returns:
- The resource contents. Never
null.
-