public class McpClientSession extends java.lang.Object implements McpSession
The session manages:
限定符和类型 | 类和说明 |
---|---|
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.
|
构造器和说明 |
---|
McpClientSession(java.time.Duration requestTimeout,
McpClientTransport transport,
java.util.Map<java.lang.String,McpClientSession.RequestHandler<?>> requestHandlers,
java.util.Map<java.lang.String,McpClientSession.NotificationHandler> notificationHandlers)
Creates a new McpClientSession with the specified configuration and handlers.
|
限定符和类型 | 方法和说明 |
---|---|
void |
close()
Closes the session immediately, potentially interrupting pending operations.
|
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Closes the session gracefully, allowing pending operations to complete.
|
java.lang.String |
getId()
Retrieve the session id.
|
static McpClientSession.MethodNotFoundError |
getMethodNotFoundError(java.lang.String method) |
reactor.core.publisher.Mono<java.lang.Void> |
handle(McpSchema.JSONRPCMessage message)
Called by the
McpServerTransportProvider once the session is determined. |
void |
openSSE()
The client may issue an HTTP GET to the MCP endpoint.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendNotification(java.lang.String method)
Sends a notification to the model client or server without parameters.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendNotification(java.lang.String method,
java.util.Map<java.lang.String,java.lang.Object> params)
Sends a JSON-RPC notification.
|
<T> reactor.core.publisher.Mono<T> |
sendRequest(java.lang.String method,
java.lang.Object requestParams,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Sends a JSON-RPC request and returns the response.
|
public McpClientSession(java.time.Duration requestTimeout, McpClientTransport transport, java.util.Map<java.lang.String,McpClientSession.RequestHandler<?>> requestHandlers, java.util.Map<java.lang.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 void openSSE()
public static McpClientSession.MethodNotFoundError getMethodNotFoundError(java.lang.String method)
public java.lang.String getId()
McpSession
getId
在接口中 McpSession
public reactor.core.publisher.Mono<java.lang.Void> handle(McpSchema.JSONRPCMessage message)
McpSession
McpServerTransportProvider
once the session is determined.
The purpose of this method is to dispatch the message to an appropriate handler as
specified by the MCP server implementation
(McpAsyncServer
or
McpSyncServer
) via
McpServerSession.Factory
that the server creates.handle
在接口中 McpSession
message
- the incoming JSON-RPC messagepublic <T> reactor.core.publisher.Mono<T> sendRequest(java.lang.String method, java.lang.Object requestParams, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
sendRequest
在接口中 McpSession
T
- The expected response typemethod
- The method name to callrequestParams
- The request parameterstypeRef
- Type reference for response deserializationpublic reactor.core.publisher.Mono<java.lang.Void> sendNotification(java.lang.String method)
McpSession
This method implements the notification pattern where no response is expected from the counterparty. It's useful for fire-and-forget scenarios.
sendNotification
在接口中 McpSession
method
- the name of the notification method to be called on the serverpublic reactor.core.publisher.Mono<java.lang.Void> sendNotification(java.lang.String method, java.util.Map<java.lang.String,java.lang.Object> params)
sendNotification
在接口中 McpSession
method
- The method name for the notificationparams
- The notification parameterspublic reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
closeGracefully
在接口中 McpSession
public void close()
close
在接口中 McpSession