The rule
A custom method’s name must start with_. ExtensionMethods.requireExtension throws
IllegalArgumentException for a name that doesn’t, specifically so a custom handler can never
collide with or replace a protocol method.
Annotated agents: the recommended way in
AcpSyncAgent/AcpAsyncAgent and NegotiatedCapabilities, like any other
annotated handler (see Clients and Agents in Java).
The builder form
For a client (no annotation model exists for clients), or an agent built with the lower-level builder API, register handlers directly:extRequestHandler and extNotificationHandler also have
agent-aware overloads: a two-argument lambda receives the params and the agent build() is about to
return, for a handler that needs to call the client back or send a session update:
self above), since a lambda parameter can’t shadow a local variable in scope.
Sending, on either side
From a client or agent directly:context.client(), to send an extension
request or notification to the client mid-prompt, without needing a reference to the agent:
AcpAsyncAgent/AcpSyncAgent directly, for calling the client’s extension
methods from outside a prompt handler.
Behavior when nothing handles a method
- An unhandled extension request fails with
-32601(method not found), same as any unhandled protocol method. - An unhandled extension notification is silently ignored, since notifications have no response
to fail; it’s logged at DEBUG, not WARN, since a peer can send many of these (
_auth/status_updatefrom some agents) and none of them is an error. An unhandled protocol notification still logs a warning. - A result of
"result": nullcompletes as an emptyMono(async) ornull(sync). - A handler that produces genuinely nothing should still answer with an empty map; returning nothing
at all from a request handler answers
-32603(internal error), since a request always needs some result.
Related
Forward Compatibility
How unknown methods, variants, and enum values are handled elsewhere in the protocol
Concepts
Client and agent roles, and the rest of the vocabulary this page assumes