java.lang.Object
io.modelcontextprotocol.spec.DefaultMcpSession
- All Implemented Interfaces:
McpSession
Deprecated.
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Functional interface for handling incoming JSON-RPC notifications.static interfaceDeprecated.Functional interface for handling incoming JSON-RPC requests. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultMcpSession(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Deprecated.Closes the session immediately, potentially interrupting pending operations.reactor.core.publisher.Mono<Void>Deprecated.Closes the session gracefully, allowing pending operations to complete.static io.modelcontextprotocol.spec.DefaultMcpSession.MethodNotFoundErrorgetMethodNotFoundError(String method) Deprecated.reactor.core.publisher.Mono<Void>sendNotification(String method, Map<String, Object> params) Deprecated.Sends a JSON-RPC notification.<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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.spec.McpSession
sendNotification
-
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 responsestransport- Transport implementation for message exchangerequestHandlers- Map of method names to request handlersnotificationHandlers- 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:
sendRequestin interfaceMcpSession- Type Parameters:
T- The expected response type- Parameters:
method- The method name to callrequestParams- The request parameterstypeRef- Type reference for response deserialization- Returns:
- A Mono containing the response
-
sendNotification
Deprecated.Sends a JSON-RPC notification.- Specified by:
sendNotificationin interfaceMcpSession- Parameters:
method- The method name for the notificationparams- The notification parameters- Returns:
- A Mono that completes when the notification is sent
-
closeGracefully
Deprecated.Closes the session gracefully, allowing pending operations to complete.- Specified by:
closeGracefullyin interfaceMcpSession- 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:
closein interfaceMcpSession
-
McpClientSessioninstead