Interface McpClientListener


public interface McpClientListener
Listener interface for monitoring MCP client operations.
  • Method Details

    • beforeInitialize

      default void beforeInitialize(McpCallContext context)
      Called before sending the initialize request to the MCP server. Legacy protocol only (up to 2025-11-25).
    • afterInitialize

      default void afterInitialize(McpCallContext context)
      Called after the initialize request completes successfully. Legacy protocol only (up to 2025-11-25).
    • onInitializeError

      default void onInitializeError(McpCallContext context, Throwable error)
      Called when the initialize request fails. Legacy protocol only (up to 2025-11-25).
    • beforeServerDiscover

      default void beforeServerDiscover(McpCallContext context)
      Called before sending the server/discover request to the MCP server. Only used with MCP protocol 2026-07-28 and later.
    • afterServerDiscover

      default void afterServerDiscover(McpCallContext context, McpDiscoverResult result)
      Called after a successful server/discover request. Only used with MCP protocol 2026-07-28 and later.
    • onServerDiscoverError

      default void onServerDiscoverError(McpCallContext context, Throwable error)
      Called when the server/discover request fails. Only used with MCP protocol 2026-07-28 and later.
    • beforeExecuteTool

      default void beforeExecuteTool(McpCallContext context)
      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

      default void onExecuteToolError(McpCallContext context, Throwable error)
      Called when a tool execution fails due to a protocol-level or communication error.
    • beforeToolsList

      default void beforeToolsList(McpCallContext context)
      Called before listing tools from the MCP server.
    • afterToolsList

      default void afterToolsList(McpCallContext context, List<ToolSpecification> tools)
      Called after listing tools from the MCP server completes successfully.
    • onToolsListError

      default void onToolsListError(McpCallContext context, Throwable error)
      Called when listing tools from the MCP server fails.
    • beforeResourceGet

      default void beforeResourceGet(McpCallContext context)
      Called before getting a resource.
    • afterResourceGet

      default void afterResourceGet(McpCallContext context, McpReadResourceResult result, Map<String,Object> rawResult)
      Called after getting a resource.
    • onResourceGetError

      default void onResourceGetError(McpCallContext context, Throwable error)
      Called when getting a resource fails.
    • beforeResourcesList

      default void beforeResourcesList(McpCallContext context)
      Called before listing resources from the MCP server.
    • afterResourcesList

      default void afterResourcesList(McpCallContext context, List<McpResource> resources)
      Called after listing resources from the MCP server completes successfully.
    • onResourcesListError

      default void onResourcesListError(McpCallContext context, Throwable error)
      Called when listing resources from the MCP server fails.
    • beforeResourceTemplatesList

      default void beforeResourceTemplatesList(McpCallContext context)
      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

      default void onResourceTemplatesListError(McpCallContext context, Throwable error)
      Called when listing resource templates from the MCP server fails.
    • beforeResourceSubscribe

      default void beforeResourceSubscribe(McpCallContext context)
      Called before subscribing to a resource. Legacy protocol only (up to 2025-11-25).
    • afterResourceSubscribe

      default void afterResourceSubscribe(McpCallContext context)
      Called after subscribing to a resource completes successfully. Legacy protocol only (up to 2025-11-25).
    • onResourceSubscribeError

      default void onResourceSubscribeError(McpCallContext context, Throwable error)
      Called when subscribing to a resource fails. Legacy protocol only (up to 2025-11-25).
    • beforeResourceUnsubscribe

      default void beforeResourceUnsubscribe(McpCallContext context)
      Called before unsubscribing from a resource. Legacy protocol only (up to 2025-11-25).
    • afterResourceUnsubscribe

      default void afterResourceUnsubscribe(McpCallContext context)
      Called after unsubscribing from a resource completes successfully. Legacy protocol only (up to 2025-11-25).
    • onResourceUnsubscribeError

      default void onResourceUnsubscribeError(McpCallContext context, Throwable error)
      Called when unsubscribing from a resource fails. Legacy protocol only (up to 2025-11-25).
    • beforeResourcesSubscribe

      default void beforeResourcesSubscribe(McpCallContext context, List<String> uris)
      Called before subscribing to resources via the modern subscriptions/listen mechanism. 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 the subscriptions/listen call)
    • onResourcesSubscribeError

      default void onResourcesSubscribeError(McpCallContext context, Throwable error)
      Called when subscribing to resources fails, either because the server rejected the subscriptions/listen request or because it never acknowledged it in time. Only used with MCP protocol 2026-07-28 and later.
    • beforeResourcesUnsubscribe

      default void beforeResourcesUnsubscribe(@Nullable McpCallContext context, long subscriptionId)
      Called before unsubscribing from resources via subscription ID. Only used with MCP protocol 2026-07-28 and later.
      Parameters:
      context - the call context wrapping the notifications/cancelled message, or null for transports that cancel by closing the SSE stream (e.g. Streamable HTTP)
    • afterResourcesUnsubscribe

      default void afterResourcesUnsubscribe(@Nullable McpCallContext context, long subscriptionId)
      Called after unsubscribing from resources completes. Only used with MCP protocol 2026-07-28 and later.
      Parameters:
      context - the call context wrapping the notifications/cancelled message, or null for transports that cancel by closing the SSE stream (e.g. Streamable HTTP)
    • beforePromptGet

      default void beforePromptGet(McpCallContext context)
      Called before getting a prompt.
    • afterPromptGet

      default void afterPromptGet(McpCallContext context, McpGetPromptResult result, Map<String,Object> rawResult)
      Called after getting a prompt.
    • onPromptGetError

      default void onPromptGetError(McpCallContext context, Throwable error)
      Called when getting a prompt fails.
    • beforePromptsList

      default void beforePromptsList(McpCallContext context)
      Called before listing prompts from the MCP server.
    • afterPromptsList

      default void afterPromptsList(McpCallContext context, List<McpPrompt> prompts)
      Called after listing prompts from the MCP server completes successfully.
    • onPromptsListError

      default void onPromptsListError(McpCallContext context, Throwable error)
      Called when listing prompts from the MCP server fails.
    • beforePing

      default void beforePing(McpCallContext context)
      Called before sending a ping request to the MCP server.
    • afterPing

      default void afterPing(McpCallContext context)
      Called after the ping request completes successfully (the server has responded with a pong).
    • onPingError

      default void onPingError(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).
    • onRootsListChanged

      default void onRootsListChanged(McpCallContext context)
      Called after the client sends a notifications/roots/list_changed notification to the server.
    • onNotificationToolsListChanged

      default void onNotificationToolsListChanged()
      Called when the server sends a notifications/tools/list_changed notification.
    • onNotificationResourcesListChanged

      default void onNotificationResourcesListChanged()
      Called when the server sends a notifications/resources/list_changed notification.
    • onNotificationPromptsListChanged

      default void onNotificationPromptsListChanged()
      Called when the server sends a notifications/prompts/list_changed notification.
    • onNotificationResourceUpdated

      default void onNotificationResourceUpdated(String uri)
      Called when the server sends a notifications/resources/updated notification.
    • onNotificationMessage

      default void onNotificationMessage(McpLogMessage message)
      Called when the server sends a notifications/message (log message) notification.
    • onNotificationProgress

      default void onNotificationProgress(McpProgressNotification notification)
      Called when the server sends a notifications/progress notification.
    • onNotificationCancelled

      default void onNotificationCancelled(long requestId, String reason)
      Called when the server sends a notifications/cancelled notification 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 server
      reason - an optional server-supplied reason for the cancellation; may be null
    • onServerMessage

      default void onServerMessage(McpServerMessageContext context)
      Called when the server sends a request or a notification to the client, before the client handles it. Called for every such message, in addition to the more specific callbacks for the known ones (for example onNotificationResourceUpdated(String)), and unlike them, it gives access to the whole message, including its JSON-RPC ID and _meta.
    • onServerPing

      default void onServerPing()
      Called when the server sends a ping request and the client responds.
    • onServerRootsList

      default void onServerRootsList()
      Called when the server sends a roots/list request and the client responds.