Skip to content

Commit 6acc990

Browse files
committed
chore: Add AsyncCloseable interface.
Signed-off-by: He-Pin <[email protected]>
1 parent 79ec5b5 commit 6acc990

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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,
12+
* return the existing one.
13+
* @return A {@link Mono} that completes when the resource has been closed.
14+
*/
15+
Mono<Void> closeGracefully();
16+
17+
/**
18+
* Immediately closes the resource gracefully.
19+
*/
20+
default void close() {
21+
this.closeGracefully().subscribe();
22+
}
23+
24+
}

mcp/src/main/java/io/modelcontextprotocol/spec/McpServerTransportProvider.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
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
}

mcp/src/main/java/io/modelcontextprotocol/spec/McpSession.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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
}

mcp/src/main/java/io/modelcontextprotocol/spec/McpTransport.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
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
/**

0 commit comments

Comments
 (0)