Package io.modelcontextprotocol.spec
Interface McpSession
- All Known Implementing Classes:
DefaultMcpSession
public interface McpSession
Represents a Model Control Protocol (MCP) session that handles communication between
clients and the server. This interface provides methods for sending requests and
notifications, as well as managing the session lifecycle.
The session operates asynchronously using Project Reactor's Mono type for
non-blocking operations. It supports both request-response patterns and one-way
notifications.
- Author:
- Christian Tzolov, Dariusz Jędrzejczyk
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the session and releases any associated resources.reactor.core.publisher.Mono<Void>Closes the session and releases any associated resources asynchronously.default reactor.core.publisher.Mono<Void>sendNotification(String method) Sends a notification to the model server without parameters.reactor.core.publisher.Mono<Void>sendNotification(String method, Map<String, Object> params) Sends a notification to the model server with parameters.<T> reactor.core.publisher.Mono<T>sendRequest(String method, Object requestParams, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Sends a request to the model server and expects a response of type T.
-
Method Details
-
sendRequest
<T> reactor.core.publisher.Mono<T> sendRequest(String method, Object requestParams, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Sends a request to the model server and expects a response of type T.This method handles the request-response pattern where a response is expected from the server. The response type is determined by the provided TypeReference.
- Type Parameters:
T- the type of the expected response- Parameters:
method- the name of the method to be called on the serverrequestParams- the parameters to be sent with the requesttypeRef- the TypeReference describing the expected response type- Returns:
- a Mono that will emit the response when received
-
sendNotification
Sends a notification to the model server without parameters.This method implements the notification pattern where no response is expected from the server. It's useful for fire-and-forget scenarios.
- Parameters:
method- the name of the notification method to be called on the server- Returns:
- a Mono that completes when the notification has been sent
-
sendNotification
Sends a notification to the model server with parameters.Similar to
sendNotification(String)but allows sending additional parameters with the notification.- Parameters:
method- the name of the notification method to be called on the serverparams- a map of parameters to be sent with the notification- Returns:
- a Mono that completes when the notification has been sent
-
closeGracefully
reactor.core.publisher.Mono<Void> closeGracefully()Closes the session and releases any associated resources asynchronously.- Returns:
- a
reactor.core.publisher.Mono<Void>that completes when the session has been closed.
-
close
void close()Closes the session and releases any associated resources.
-