File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed
mcp/src/main/java/io/modelcontextprotocol/spec Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1+ package io .modelcontextprotocol .spec ;
2+
3+ import reactor .core .publisher .Mono ;
4+
5+ /**
6+ * Interface for close operations that are asynchronous.
7+ */
8+ public interface AsyncCloseable {
9+
10+ /**
11+ * Begins the process of closing the resource gracefully, if there is one in progress, return
12+ * the existing one.
13+ *
14+ * @return A {@link Mono} that completes when the resource has been closed.
15+ */
16+ Mono <Void > closeGracefully ();
17+
18+ /**
19+ * Immediately closes the resource gracefully.
20+ */
21+ default void close () {
22+ this .closeGracefully ().subscribe ();
23+ }
24+ }
Original file line number Diff line number Diff line change 2929 *
3030 * @author Dariusz Jędrzejczyk
3131 */
32- public interface McpServerTransportProvider {
32+ public interface McpServerTransportProvider extends AsyncCloseable {
3333
3434 /**
3535 * Sets the session factory that will be used to create sessions for new clients. An
@@ -52,6 +52,7 @@ public interface McpServerTransportProvider {
5252 * Immediately closes all the transports with connected clients and releases any
5353 * associated resources.
5454 */
55+ @ Override
5556 default void close () {
5657 this .closeGracefully ().subscribe ();
5758 }
@@ -61,6 +62,7 @@ default void close() {
6162 * associated resources asynchronously.
6263 * @return a {@link Mono<Void>} that completes when the connections have been closed.
6364 */
65+ @ Override
6466 Mono <Void > closeGracefully ();
6567
6668}
Original file line number Diff line number Diff line change 2323 * @author Christian Tzolov
2424 * @author Dariusz Jędrzejczyk
2525 */
26- public interface McpSession {
26+ public interface McpSession extends AsyncCloseable {
2727
2828 /**
2929 * Sends a request to the model counterparty and expects a response of type T.
@@ -72,11 +72,13 @@ default Mono<Void> sendNotification(String method) {
7272 * Closes the session and releases any associated resources asynchronously.
7373 * @return a {@link Mono<Void>} that completes when the session has been closed.
7474 */
75+ @ Override
7576 Mono <Void > closeGracefully ();
7677
7778 /**
7879 * Closes the session and releases any associated resources.
7980 */
81+ @ Override
8082 void close ();
8183
8284}
Original file line number Diff line number Diff line change 3535 * @author Christian Tzolov
3636 * @author Dariusz Jędrzejczyk
3737 */
38- public interface McpTransport {
38+ public interface McpTransport extends AsyncCloseable {
3939
4040 /**
4141 * Closes the transport connection and releases any associated resources.
@@ -45,6 +45,7 @@ public interface McpTransport {
4545 * needed. It should handle the graceful shutdown of any active connections.
4646 * </p>
4747 */
48+ @ Override
4849 default void close () {
4950 this .closeGracefully ().subscribe ();
5051 }
@@ -54,6 +55,7 @@ default void close() {
5455 * asynchronously.
5556 * @return a {@link Mono<Void>} that completes when the connection has been closed.
5657 */
58+ @ Override
5759 Mono <Void > closeGracefully ();
5860
5961 /**
You can’t perform that action at this time.
0 commit comments