Interface McpToolHandler
Implementations declare a descriptor (returned from tools/list) and
a call body invoked when a matching tools/call arrives. Both
use the revision-neutral model, so a handler compiles against exactly one protocol revision's
worth of assumptions: none.
The BeanStore argument is the per-request bean store, letting handlers look up additional
services (or the underlying RestRequest) without this interface depending on REST runtime types.
This is a genuine two-method contract, not a single-method one: both descriptor() and
call(Map, 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 tools/list and tools/call, 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(McpToolSpec, BiFunction) for
the common case of wiring both in a single expression.
-
Method Summary
Modifier and TypeMethodDescriptionInvokes the tool.Returns the static descriptor for this tool.static McpToolHandlerof(McpToolSpec descriptor, BiFunction<Map<String, Object>, BeanStore, McpToolOutcome> call) Builds a handler from a fixed descriptor and acalllambda.
-
Method Details
-
of
static McpToolHandler of(McpToolSpec descriptor, BiFunction<Map<String, Object>, BeanStore, McpToolOutcome> call) Builds a handler from a fixed descriptor and acalllambda.The sanctioned one-expression path for registering a tool: unlike a bare lambda (which cannot satisfy this two-method interface at all), this factory wires both
descriptor()andcall(Map, BeanStore)from a single call.- Parameters:
descriptor- The static descriptor returned from everydescriptor()call. Must not benull and must carry a non-blankname(routing matches incomingtools/callrequests on name, so a nameless tool would be silently unreachable).call- The call body, invoked with the incoming arguments and the per-request bean store. Must not benull .- Returns:
- A new handler wiring both. Never
null .
-
descriptor
Returns the static descriptor for this tool.The
namevalue is used by the boundMcpRevisionto route incomingtools/callrequests, so each handler in anMcpServerConfigmust use a unique name.- Returns:
- The tool descriptor. Never
null.
-
call
Invokes the tool.- Parameters:
arguments- The arguments object passed in the JSON-RPC params (nevernull; empty map when omitted).ctx- Per-request bean store. Nevernull.- Returns:
- The call result. Never
null.
-