Package io.modelcontextprotocol.server
Class McpSyncServerExchange
java.lang.Object
io.modelcontextprotocol.server.McpSyncServerExchange
Represents a synchronous 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
-
Constructor Summary
ConstructorsConstructorDescriptionMcpSyncServerExchange(McpAsyncServerExchange exchange) Create a new synchronous exchange with the client using the provided asynchronous implementation as a delegate. -
Method Summary
Modifier and TypeMethodDescriptioncreateElicitation(McpSchema.ElicitRequest elicitRequest) Creates a new elicitation.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.Retrieves the list of all roots provided by the client.Retrieves a paginated list of roots provided by the client.voidloggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to the client.ping()Sends a synchronous ping request to the client.voidprogressNotification(McpSchema.ProgressNotification progressNotification) Sends a notification to the client that the current progress status has changed for long-running operations.Provides the Session IDProvides theMcpTransportContextassociated with the transport layer.
-
Constructor Details
-
McpSyncServerExchange
Create a new synchronous exchange with the client using the provided asynchronous implementation as a delegate.- Parameters:
exchange- The asynchronous exchange to delegate to.
-
-
Method Details
-
sessionId
Provides the Session ID- Returns:
- session ID
-
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
-
createMessage
public 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 result containing the details of the sampling response
- See Also:
-
createElicitation
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 result containing the elicitation response.
- See Also:
-
listRoots
Retrieves the list of all roots provided by the client.- Returns:
- 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:
- The list of roots result
-
loggingNotification
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
-
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
-
ping
Sends a synchronous ping request to the client.- Returns:
-