Package io.modelcontextprotocol.server
Class McpAsyncServerExchange
java.lang.Object
io.modelcontextprotocol.server.McpAsyncServerExchange
Represents an asynchronous exchange with a Model Context Protocol (MCP) client. The
exchange provides methods to interact with the client and query its capabilities.
- Author:
- Dariusz Jędrzejczyk, Christian Tzolov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.fasterxml.jackson.core.type.TypeReference<Object> -
Constructor Summary
ConstructorsConstructorDescriptionMcpAsyncServerExchange(McpSession session, McpSchema.ClientCapabilities clientCapabilities, McpSchema.Implementation clientInfo) Deprecated.McpAsyncServerExchange(String sessionId, McpLoggableSession session, McpSchema.ClientCapabilities clientCapabilities, McpSchema.Implementation clientInfo, McpTransportContext transportContext) Create a new asynchronous exchange with the client. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<McpSchema.ElicitResult>createElicitation(McpSchema.ElicitRequest elicitRequest) Creates a new elicitation.reactor.core.publisher.Mono<McpSchema.CreateMessageResult>createMessage(McpSchema.CreateMessageRequest createMessageRequest) Create a new message using the sampling capabilities of the client.Get the client capabilities that define the supported features and functionality.Get the client implementation information.reactor.core.publisher.Mono<McpSchema.ListRootsResult>Retrieves the list of all roots provided by the client.reactor.core.publisher.Mono<McpSchema.ListRootsResult>Retrieves a paginated list of roots provided by the client.reactor.core.publisher.Mono<Void>loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to the client.reactor.core.publisher.Mono<Object>ping()Sends a ping request to the client.reactor.core.publisher.Mono<Void>progressNotification(McpSchema.ProgressNotification progressNotification) Sends a notification to the client that the current progress status has changed for long-running operations.Provides the Session ID.Provides theMcpTransportContextassociated with the transport layer.
-
Field Details
-
OBJECT_TYPE_REF
-
-
Constructor Details
-
McpAsyncServerExchange
@Deprecated public McpAsyncServerExchange(McpSession session, McpSchema.ClientCapabilities clientCapabilities, McpSchema.Implementation clientInfo) Deprecated.Create a new asynchronous exchange with the client.- Parameters:
session- The server session representing a 1-1 interaction.clientCapabilities- The client capabilities that define the supported features and functionality.clientInfo- The client implementation information.
-
McpAsyncServerExchange
public McpAsyncServerExchange(String sessionId, McpLoggableSession session, McpSchema.ClientCapabilities clientCapabilities, McpSchema.Implementation clientInfo, McpTransportContext transportContext) Create a new asynchronous exchange with the client.- Parameters:
session- The server session representing a 1-1 interaction.clientCapabilities- The client capabilities that define the supported features and functionality.clientInfo- The client implementation information.transportContext- context associated with the client as extracted from the transport
-
-
Method Details
-
getClientCapabilities
Get the client capabilities that define the supported features and functionality.- Returns:
- The client capabilities
-
getClientInfo
Get the client implementation information.- Returns:
- The client implementation details
-
transportContext
Provides theMcpTransportContextassociated with the transport layer. For HTTP transports it can contain the metadata associated with the HTTP request that triggered the processing.- Returns:
- the transport context object
-
sessionId
Provides the Session ID.- Returns:
- session ID string
-
createMessage
public reactor.core.publisher.Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest) Create a new message using the sampling capabilities of the client. The Model Context Protocol (MCP) provides a standardized way for servers to request LLM sampling (“completions” or “generations”) from language models via clients. This flow allows clients to maintain control over model access, selection, and permissions while enabling servers to leverage AI capabilities—with no server API keys necessary. Servers can request text or image-based interactions and optionally include context from MCP servers in their prompts.- Parameters:
createMessageRequest- The request to create a new message- Returns:
- A Mono that completes when the message has been created
- See Also:
-
createElicitation
public reactor.core.publisher.Mono<McpSchema.ElicitResult> createElicitation(McpSchema.ElicitRequest elicitRequest) Creates a new elicitation. MCP provides a standardized way for servers to request additional information from users through the client during interactions. This flow allows clients to maintain control over user interactions and data sharing while enabling servers to gather necessary information dynamically. Servers can request structured data from users with optional JSON schemas to validate responses.- Parameters:
elicitRequest- The request to create a new elicitation- Returns:
- A Mono that completes when the elicitation has been resolved.
- See Also:
-
listRoots
Retrieves the list of all roots provided by the client.- Returns:
- A Mono that emits the list of roots result.
-
listRoots
Retrieves a paginated list of roots provided by the client.- Parameters:
cursor- Optional pagination cursor from a previous list request- Returns:
- A Mono that emits the list of roots result containing
-
loggingNotification
public reactor.core.publisher.Mono<Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to the client. Messages below the current minimum logging level will be filtered out.- Parameters:
loggingMessageNotification- The logging message to send- Returns:
- A Mono that completes when the notification has been sent
-
progressNotification
public reactor.core.publisher.Mono<Void> progressNotification(McpSchema.ProgressNotification progressNotification) Sends a notification to the client that the current progress status has changed for long-running operations.- Parameters:
progressNotification- The progress notification to send- Returns:
- A Mono that completes when the notification has been sent
-
ping
Sends a ping request to the client.- Returns:
- A Mono that completes with clients's ping response
-
McpAsyncServerExchange(String, McpLoggableSession, McpSchema.ClientCapabilities, McpSchema.Implementation, McpTransportContext)