Shutdown listener? #888
Replies: 1 comment
|
The SDK currently does not expose an EOF/shutdown callback from For a process-based STDIO server, the practical solution is to own cleanup at the application boundary and register an idempotent JVM shutdown hook: var closed = new AtomicBoolean();
Runnable cleanup = () -> {
if (closed.compareAndSet(false, true)) {
serviceA.close();
serviceB.close();
}
};
Runtime.getRuntime().addShutdownHook(new Thread(cleanup, "mcp-cleanup"));This covers the normal MCP client lifecycle where the parent closes stdin and then terminates the child process. Also call the same One caveat: closing stdin alone does not force an arbitrary Java process to exit. If your other services own non-daemon threads, your main/application lifecycle must exit after EOF (or those services must be stopped by the cleanup path). A public termination signal on the transport would make this cleaner; today the provider only exposes The EOF behavior is in |
Uh oh!
There was an error while loading. Please reload this page.
Pre-submission Checklist
Question Category
Your Question
Hello,
When we start our MCP server in STDIO mode, we start a bunch of other services. When the stdin is closed, we need to shutdown those services. Would there be a way to listen to the shutdown via the SDK? Is this something you would consider? Or do we need to wrap stdin on our side to detect termination? We are using
StdioServerTransportProviderwithMcpServer.sync().Thanks
All reactions