Class SyncModernMcpChangeSubscriber
- All Implemented Interfaces:
org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
listeners what the servers report.
A listen stream is a long-lived request, so it is not opened by the client of a chat
request. Each connection gets one client for its stream, taken from
SyncModernMcpConnection.applicationClient() when the subscriber starts. That
happens outside of any request, so the stream is opened for the application and not for
a caller: the server must accept it with the credentials of the application, or with
none.
The streams are opened when the subscriber is started, without waiting for the servers, and a server that cannot be reached does not fail the start. A subscriber without listeners opens no stream, so add the listeners before it is started.
A stream that ends, or that cannot be opened, is opened again for as long as the subscriber runs: after one second at first, and after twice the previous pause each time, up to the maximum reopen delay. The pauses start over with one second once a stream has stayed up for the maximum reopen delay. So a short interruption is over quickly, and neither a server that stays away nor one that accepts the stream only to end it is asked more often than the maximum delay allows.
The listeners are told that changes may have been missed when a stream is established and when an established stream ends, but not for a stream that could not be opened.
Register a SyncModernMcpToolCallbackProvider as a listener to have it drop a
kept tool listing as soon as the server reports that its tools changed. A stream always
listens for the changes of the tools, and for those of the prompts and of the list of
resources if the connection was added with them.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SyncModernMcpChangeListener listener) Adds a listener.builder()Creates a builder for aSyncModernMcpChangeSubscriber.The names of the connections a listen stream is kept open to.booleanvoidstart()Opens the listen streams, without waiting for the servers.voidstop()Closes the listen streams.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, isPauseable, pause, restart, stop
-
Method Details
-
builder
Creates a builder for aSyncModernMcpChangeSubscriber.- Returns:
- the builder
-
addListener
Adds a listener. The listeners are told in their order: one that isOrderedor annotated withOrderby that order, and the others last, in the order they were added. A subscriber that was started without listeners has opened no stream, and it opens the streams when the first listener is added.- Parameters:
listener- the listener
-
connectionNames
The names of the connections a listen stream is kept open to.- Returns:
- the connection names
-
start
public void start()Opens the listen streams, without waiting for the servers.- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()Closes the listen streams. They are not opened again until the next start.- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-