Class DefaultMcpSession

java.lang.Object
io.modelcontextprotocol.spec.DefaultMcpSession
All Implemented Interfaces:
McpSession

@Deprecated public class DefaultMcpSession extends Object implements McpSession
Deprecated.
This method will be removed in 0.9.0. Use McpClientSession instead
Default implementation of the MCP (Model Context Protocol) session that manages bidirectional JSON-RPC communication between clients and servers. This implementation follows the MCP specification for message exchange and transport handling.

The session manages:

  • Request/response handling with unique message IDs
  • Notification processing
  • Message timeout management
  • Transport layer abstraction
Author:
Christian Tzolov, Dariusz Jędrzejczyk
  • Constructor Details

    • DefaultMcpSession

      public DefaultMcpSession(Duration requestTimeout, McpTransport transport, Map<String,DefaultMcpSession.RequestHandler<?>> requestHandlers, Map<String,DefaultMcpSession.NotificationHandler> notificationHandlers)
      Deprecated.
      Creates a new DefaultMcpSession with the specified configuration and handlers.
      Parameters:
      requestTimeout - Duration to wait for responses
      transport - Transport implementation for message exchange
      requestHandlers - Map of method names to request handlers
      notificationHandlers - Map of method names to notification handlers
  • Method Details

    • getMethodNotFoundError

      public static io.modelcontextprotocol.spec.DefaultMcpSession.MethodNotFoundError getMethodNotFoundError(String method)
      Deprecated.
    • sendRequest

      public <T> reactor.core.publisher.Mono<T> sendRequest(String method, Object requestParams, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Deprecated.
      Sends a JSON-RPC request and returns the response.
      Specified by:
      sendRequest in interface McpSession
      Type Parameters:
      T - The expected response type
      Parameters:
      method - The method name to call
      requestParams - The request parameters
      typeRef - Type reference for response deserialization
      Returns:
      A Mono containing the response
    • sendNotification

      public reactor.core.publisher.Mono<Void> sendNotification(String method, Map<String,Object> params)
      Deprecated.
      Sends a JSON-RPC notification.
      Specified by:
      sendNotification in interface McpSession
      Parameters:
      method - The method name for the notification
      params - The notification parameters
      Returns:
      A Mono that completes when the notification is sent
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Deprecated.
      Closes the session gracefully, allowing pending operations to complete.
      Specified by:
      closeGracefully in interface McpSession
      Returns:
      A Mono that completes when the session is closed
    • close

      public void close()
      Deprecated.
      Closes the session immediately, potentially interrupting pending operations.
      Specified by:
      close in interface McpSession