Interface McpClientListener
public interface McpClientListener
Listener interface for monitoring MCP client operations.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidafterExecuteTool(McpCallContext context, ToolExecutionResult result, Map<String, Object> rawResult) Called after executing a tool if the execution was successful, or if it resulted in an application-level error (but not a protocol-level or communication error).default voidafterInitialize(McpCallContext context) Called after the initialize request completes successfully.default voidafterPing(McpCallContext context) Called after the ping request completes successfully (the server has responded with a pong).default voidafterPromptGet(McpCallContext context, McpGetPromptResult result, Map<String, Object> rawResult) Called after getting a prompt.default voidafterPromptsList(McpCallContext context, List<McpPrompt> prompts) Called after listing prompts from the MCP server completes successfully.default voidafterResourceGet(McpCallContext context, McpReadResourceResult result, Map<String, Object> rawResult) Called after getting a resource.default voidafterResourcesList(McpCallContext context, List<McpResource> resources) Called after listing resources from the MCP server completes successfully.default voidafterResourcesSubscribe(McpCallContext context, long subscriptionId, List<String> uris) Called after subscribing to resources completes successfully.default voidafterResourceSubscribe(McpCallContext context) Called after subscribing to a resource completes successfully.default voidafterResourcesUnsubscribe(@Nullable McpCallContext context, long subscriptionId) Called after unsubscribing from resources completes.default voidafterResourceTemplatesList(McpCallContext context, List<McpResourceTemplate> templates) Called after listing resource templates from the MCP server completes successfully.default voidafterResourceUnsubscribe(McpCallContext context) Called after unsubscribing from a resource completes successfully.default voidafterServerDiscover(McpCallContext context, McpDiscoverResult result) Called after a successfulserver/discoverrequest.default voidafterToolsList(McpCallContext context, List<ToolSpecification> tools) Called after listing tools from the MCP server completes successfully.default voidbeforeExecuteTool(McpCallContext context) Called before executing a tool.default voidbeforeInitialize(McpCallContext context) Called before sending the initialize request to the MCP server.default voidbeforePing(McpCallContext context) Called before sending a ping request to the MCP server.default voidbeforePromptGet(McpCallContext context) Called before getting a prompt.default voidbeforePromptsList(McpCallContext context) Called before listing prompts from the MCP server.default voidbeforeResourceGet(McpCallContext context) Called before getting a resource.default voidbeforeResourcesList(McpCallContext context) Called before listing resources from the MCP server.default voidbeforeResourcesSubscribe(McpCallContext context, List<String> uris) Called before subscribing to resources via the modernsubscriptions/listenmechanism.default voidbeforeResourceSubscribe(McpCallContext context) Called before subscribing to a resource.default voidbeforeResourcesUnsubscribe(@Nullable McpCallContext context, long subscriptionId) Called before unsubscribing from resources via subscription ID.default voidCalled before listing resource templates from the MCP server.default voidbeforeResourceUnsubscribe(McpCallContext context) Called before unsubscribing from a resource.default voidbeforeServerDiscover(McpCallContext context) Called before sending theserver/discoverrequest to the MCP server.default voidbeforeToolsList(McpCallContext context) Called before listing tools from the MCP server.default voidonExecuteToolError(McpCallContext context, Throwable error) Called when a tool execution fails due to a protocol-level or communication error.default voidonInitializeError(McpCallContext context, Throwable error) Called when the initialize request fails.default voidonNotificationCancelled(long requestId, String reason) Called when the server sends anotifications/cancellednotification to abort a previously accepted request.default voidonNotificationMessage(McpLogMessage message) Called when the server sends anotifications/message(log message) notification.default voidonNotificationProgress(McpProgressNotification notification) Called when the server sends anotifications/progressnotification.default voidCalled when the server sends anotifications/prompts/list_changednotification.default voidCalled when the server sends anotifications/resources/list_changednotification.default voidCalled when the server sends anotifications/resources/updatednotification.default voidCalled when the server sends anotifications/tools/list_changednotification.default voidonPingError(McpCallContext context, Throwable error) Called when the ping request fails (the server didn't send a pong in time or some transport-level issue occurred).default voidonPromptGetError(McpCallContext context, Throwable error) Called when getting a prompt fails.default voidonPromptsListError(McpCallContext context, Throwable error) Called when listing prompts from the MCP server fails.default voidonResourceGetError(McpCallContext context, Throwable error) Called when getting a resource fails.default voidonResourcesListError(McpCallContext context, Throwable error) Called when listing resources from the MCP server fails.default voidonResourcesSubscribeError(McpCallContext context, Throwable error) Called when subscribing to resources fails, either because the server rejected thesubscriptions/listenrequest or because it never acknowledged it in time.default voidonResourceSubscribeError(McpCallContext context, Throwable error) Called when subscribing to a resource fails.default voidonResourceTemplatesListError(McpCallContext context, Throwable error) Called when listing resource templates from the MCP server fails.default voidonResourceUnsubscribeError(McpCallContext context, Throwable error) Called when unsubscribing from a resource fails.default voidonRootsListChanged(McpCallContext context) Called after the client sends anotifications/roots/list_changednotification to the server.default voidonServerDiscoverError(McpCallContext context, Throwable error) Called when theserver/discoverrequest fails.default voidCalled when the server sends apingrequest and the client responds.default voidCalled when the server sends aroots/listrequest and the client responds.default voidonToolsListError(McpCallContext context, Throwable error) Called when listing tools from the MCP server fails.
-
Method Details
-
beforeInitialize
Called before sending the initialize request to the MCP server. Legacy protocol only (up to 2025-11-25). -
afterInitialize
Called after the initialize request completes successfully. Legacy protocol only (up to 2025-11-25). -
onInitializeError
Called when the initialize request fails. Legacy protocol only (up to 2025-11-25). -
beforeServerDiscover
Called before sending theserver/discoverrequest to the MCP server. Only used with MCP protocol 2026-07-28 and later. -
afterServerDiscover
Called after a successfulserver/discoverrequest. Only used with MCP protocol 2026-07-28 and later. -
onServerDiscoverError
Called when theserver/discoverrequest fails. Only used with MCP protocol 2026-07-28 and later. -
beforeExecuteTool
Called before executing a tool. -
afterExecuteTool
default void afterExecuteTool(McpCallContext context, ToolExecutionResult result, Map<String, Object> rawResult) Called after executing a tool if the execution was successful, or if it resulted in an application-level error (but not a protocol-level or communication error). -
onExecuteToolError
Called when a tool execution fails due to a protocol-level or communication error. -
beforeToolsList
Called before listing tools from the MCP server. -
afterToolsList
Called after listing tools from the MCP server completes successfully. -
onToolsListError
Called when listing tools from the MCP server fails. -
beforeResourceGet
Called before getting a resource. -
afterResourceGet
default void afterResourceGet(McpCallContext context, McpReadResourceResult result, Map<String, Object> rawResult) Called after getting a resource. -
onResourceGetError
Called when getting a resource fails. -
beforeResourcesList
Called before listing resources from the MCP server. -
afterResourcesList
Called after listing resources from the MCP server completes successfully. -
onResourcesListError
Called when listing resources from the MCP server fails. -
beforeResourceTemplatesList
Called before listing resource templates from the MCP server. -
afterResourceTemplatesList
default void afterResourceTemplatesList(McpCallContext context, List<McpResourceTemplate> templates) Called after listing resource templates from the MCP server completes successfully. -
onResourceTemplatesListError
Called when listing resource templates from the MCP server fails. -
beforeResourceSubscribe
Called before subscribing to a resource. Legacy protocol only (up to 2025-11-25). -
afterResourceSubscribe
Called after subscribing to a resource completes successfully. Legacy protocol only (up to 2025-11-25). -
onResourceSubscribeError
Called when subscribing to a resource fails. Legacy protocol only (up to 2025-11-25). -
beforeResourceUnsubscribe
Called before unsubscribing from a resource. Legacy protocol only (up to 2025-11-25). -
afterResourceUnsubscribe
Called after unsubscribing from a resource completes successfully. Legacy protocol only (up to 2025-11-25). -
onResourceUnsubscribeError
Called when unsubscribing from a resource fails. Legacy protocol only (up to 2025-11-25). -
beforeResourcesSubscribe
Called before subscribing to resources via the modernsubscriptions/listenmechanism. Only used with MCP protocol 2026-07-28 and later. -
afterResourcesSubscribe
default void afterResourcesSubscribe(McpCallContext context, long subscriptionId, List<String> uris) Called after subscribing to resources completes successfully. Only used with MCP protocol 2026-07-28 and later.- Parameters:
subscriptionId- the subscription ID (the JSON-RPC request ID of thesubscriptions/listencall)
-
onResourcesSubscribeError
Called when subscribing to resources fails, either because the server rejected thesubscriptions/listenrequest or because it never acknowledged it in time. Only used with MCP protocol 2026-07-28 and later. -
beforeResourcesUnsubscribe
Called before unsubscribing from resources via subscription ID. Only used with MCP protocol 2026-07-28 and later.- Parameters:
context- the call context wrapping thenotifications/cancelledmessage, ornullfor transports that cancel by closing the SSE stream (e.g. Streamable HTTP)
-
afterResourcesUnsubscribe
Called after unsubscribing from resources completes. Only used with MCP protocol 2026-07-28 and later.- Parameters:
context- the call context wrapping thenotifications/cancelledmessage, ornullfor transports that cancel by closing the SSE stream (e.g. Streamable HTTP)
-
beforePromptGet
Called before getting a prompt. -
afterPromptGet
default void afterPromptGet(McpCallContext context, McpGetPromptResult result, Map<String, Object> rawResult) Called after getting a prompt. -
onPromptGetError
Called when getting a prompt fails. -
beforePromptsList
Called before listing prompts from the MCP server. -
afterPromptsList
Called after listing prompts from the MCP server completes successfully. -
onPromptsListError
Called when listing prompts from the MCP server fails. -
beforePing
Called before sending a ping request to the MCP server. -
afterPing
Called after the ping request completes successfully (the server has responded with a pong). -
onPingError
Called when the ping request fails (the server didn't send a pong in time or some transport-level issue occurred). -
onRootsListChanged
Called after the client sends anotifications/roots/list_changednotification to the server. -
onNotificationToolsListChanged
default void onNotificationToolsListChanged()Called when the server sends anotifications/tools/list_changednotification. -
onNotificationResourcesListChanged
default void onNotificationResourcesListChanged()Called when the server sends anotifications/resources/list_changednotification. -
onNotificationPromptsListChanged
default void onNotificationPromptsListChanged()Called when the server sends anotifications/prompts/list_changednotification. -
onNotificationResourceUpdated
Called when the server sends anotifications/resources/updatednotification. -
onNotificationMessage
Called when the server sends anotifications/message(log message) notification. -
onNotificationProgress
Called when the server sends anotifications/progressnotification. -
onNotificationCancelled
Called when the server sends anotifications/cancellednotification to abort a previously accepted request. The corresponding pending operation, if any, is completed exceptionally before this listener is invoked.- Parameters:
requestId- the id of the cancelled request, as supplied by the serverreason- an optional server-supplied reason for the cancellation; may benull
-
onServerPing
default void onServerPing()Called when the server sends apingrequest and the client responds. -
onServerRootsList
default void onServerRootsList()Called when the server sends aroots/listrequest and the client responds.
-