public class McpClientSession extends Object implements McpSession
The session manages:
| Modifier and Type | Class and Description |
|---|---|
static class |
McpClientSession.MethodNotFoundError |
static interface |
McpClientSession.NotificationHandler
Functional interface for handling incoming JSON-RPC notifications.
|
static interface |
McpClientSession.RequestHandler<T>
Functional interface for handling incoming JSON-RPC requests.
|
| Constructor and Description |
|---|
McpClientSession(Duration requestTimeout,
McpClientTransport transport,
Map<String,McpClientSession.RequestHandler<?>> requestHandlers,
Map<String,McpClientSession.NotificationHandler> notificationHandlers)
|
McpClientSession(Duration requestTimeout,
McpClientTransport transport,
Map<String,McpClientSession.RequestHandler<?>> requestHandlers,
Map<String,McpClientSession.NotificationHandler> notificationHandlers,
Function<? super reactor.core.publisher.Mono<Void>,? extends org.reactivestreams.Publisher<Void>> connectHook)
Creates a new McpClientSession with the specified configuration and handlers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the session immediately, potentially interrupting pending operations.
|
reactor.core.publisher.Mono<Void> |
closeGracefully()
Closes the session gracefully, allowing pending operations to complete.
|
reactor.core.publisher.Mono<Void> |
sendNotification(String method,
Object params)
Sends a JSON-RPC notification.
|
<T> reactor.core.publisher.Mono<T> |
sendRequest(String method,
Object requestParams,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Sends a JSON-RPC request and returns the response.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsendNotification@Deprecated public McpClientSession(Duration requestTimeout, McpClientTransport transport, Map<String,McpClientSession.RequestHandler<?>> requestHandlers, Map<String,McpClientSession.NotificationHandler> notificationHandlers)
requestTimeout - Duration to wait for responsestransport - Transport implementation for message exchangerequestHandlers - Map of method names to request handlersnotificationHandlers - Map of method names to notification handlerspublic McpClientSession(Duration requestTimeout, McpClientTransport transport, Map<String,McpClientSession.RequestHandler<?>> requestHandlers, Map<String,McpClientSession.NotificationHandler> notificationHandlers, Function<? super reactor.core.publisher.Mono<Void>,? extends org.reactivestreams.Publisher<Void>> connectHook)
requestTimeout - Duration to wait for responsestransport - Transport implementation for message exchangerequestHandlers - Map of method names to request handlersnotificationHandlers - Map of method names to notification handlersconnectHook - Hook that allows transforming the connection Publisher prior to
subscribingpublic <T> reactor.core.publisher.Mono<T> sendRequest(String method, Object requestParams, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
sendRequest in interface McpSessionT - The expected response typemethod - The method name to callrequestParams - The request parameterstypeRef - Type reference for response deserializationpublic reactor.core.publisher.Mono<Void> sendNotification(String method, Object params)
sendNotification in interface McpSessionmethod - The method name for the notificationparams - The notification parameterspublic reactor.core.publisher.Mono<Void> closeGracefully()
closeGracefully in interface McpSessionpublic void close()
close in interface McpSessionCopyright © 2025. All rights reserved.