public class McpServerSession extends java.lang.Object implements McpLoggableSession
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
McpServerSession.Factory
Factory for creating server sessions which delegate to a provided 1:1 transport
with a connected client.
|
static interface |
McpServerSession.InitNotificationHandler
Notification handler for the initialization notification from the client.
|
static interface |
McpServerSession.InitRequestHandler
已过时。
|
static class |
McpServerSession.MethodNotFoundError |
static interface |
McpServerSession.NotificationHandler
已过时。
|
static interface |
McpServerSession.RequestHandler<T>
已过时。
|
| 构造器和说明 |
|---|
McpServerSession(java.lang.String id,
java.time.Duration requestTimeout,
McpServerTransport transport,
McpInitRequestHandler initHandler,
java.util.Map<java.lang.String,McpRequestHandler<?>> requestHandlers,
java.util.Map<java.lang.String,McpNotificationHandler> notificationHandlers)
Creates a new server session with the given parameters and the transport to use.
|
McpServerSession(java.lang.String id,
java.time.Duration requestTimeout,
McpServerTransport transport,
McpInitRequestHandler initHandler,
McpServerSession.InitNotificationHandler initNotificationHandler,
java.util.Map<java.lang.String,McpRequestHandler<?>> requestHandlers,
java.util.Map<java.lang.String,McpNotificationHandler> notificationHandlers)
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
Closes the session and releases any associated resources.
|
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Closes the session and releases any associated resources asynchronously.
|
java.lang.String |
getId()
Retrieve the session id.
|
reactor.core.publisher.Mono<java.lang.Void> |
handle(McpSchema.JSONRPCMessage message)
Called by the
McpServerTransportProvider once the session is determined. |
void |
init(McpSchema.ClientCapabilities clientCapabilities,
McpSchema.Implementation clientInfo)
Called upon successful initialization sequence between the client and the server
with the client capabilities and information.
|
boolean |
isNotificationForLevelAllowed(McpSchema.LoggingLevel loggingLevel)
Allows checking whether a particular logging level is allowed.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendNotification(java.lang.String method,
java.lang.Object params)
Sends a notification to the model client or server with parameters.
|
<T> reactor.core.publisher.Mono<T> |
sendRequest(java.lang.String method,
java.lang.Object requestParams,
TypeRef<T> typeRef)
Sends a request to the model counterparty and expects a response of type T.
|
void |
setMinLoggingLevel(McpSchema.LoggingLevel minLoggingLevel)
Set the minimum logging level for the client.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsendNotificationpublic McpServerSession(java.lang.String id,
java.time.Duration requestTimeout,
McpServerTransport transport,
McpInitRequestHandler initHandler,
java.util.Map<java.lang.String,McpRequestHandler<?>> requestHandlers,
java.util.Map<java.lang.String,McpNotificationHandler> notificationHandlers)
id - session idtransport - the transport to useinitHandler - called when a
McpSchema.InitializeRequest is received by the
serverrequestHandlers - map of request handlers to usenotificationHandlers - map of notification handlers to use@Deprecated
public McpServerSession(java.lang.String id,
java.time.Duration requestTimeout,
McpServerTransport transport,
McpInitRequestHandler initHandler,
McpServerSession.InitNotificationHandler initNotificationHandler,
java.util.Map<java.lang.String,McpRequestHandler<?>> requestHandlers,
java.util.Map<java.lang.String,McpNotificationHandler> notificationHandlers)
id - session idtransport - the transport to useinitHandler - called when a
McpSchema.InitializeRequest is received by the
serverinitNotificationHandler - called when a
McpSchema.METHOD_NOTIFICATION_INITIALIZED is
received.requestHandlers - map of request handlers to usenotificationHandlers - map of notification handlers to usepublic java.lang.String getId()
public void init(McpSchema.ClientCapabilities clientCapabilities, McpSchema.Implementation clientInfo)
clientCapabilities - the capabilities the connected client providesclientInfo - the information about the connected clientpublic void setMinLoggingLevel(McpSchema.LoggingLevel minLoggingLevel)
McpLoggableSessionsetMinLoggingLevel 在接口中 McpLoggableSessionminLoggingLevel - The minimum logging levelpublic boolean isNotificationForLevelAllowed(McpSchema.LoggingLevel loggingLevel)
McpLoggableSessionisNotificationForLevelAllowed 在接口中 McpLoggableSessionloggingLevel - the level to checkpublic <T> reactor.core.publisher.Mono<T> sendRequest(java.lang.String method,
java.lang.Object requestParams,
TypeRef<T> typeRef)
McpSessionThis method handles the request-response pattern where a response is expected from the client or server. The response type is determined by the provided TypeReference.
sendRequest 在接口中 McpSessionT - the type of the expected responsemethod - the name of the method to be called on the counterpartyrequestParams - the parameters to be sent with the requesttypeRef - the TypeReference describing the expected response typepublic reactor.core.publisher.Mono<java.lang.Void> sendNotification(java.lang.String method,
java.lang.Object params)
McpSession
Similar to McpSession.sendNotification(String) but allows sending additional
parameters with the notification.
sendNotification 在接口中 McpSessionmethod - the name of the notification method to be sent to the counterpartyparams - parameters to be sent with the notificationpublic reactor.core.publisher.Mono<java.lang.Void> handle(McpSchema.JSONRPCMessage message)
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.message - the incoming JSON-RPC messagepublic reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
McpSessioncloseGracefully 在接口中 McpSessionMono that completes when the session has been closed.public void close()
McpSessionclose 在接口中 McpSession