Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCP server terminates if not kept alive explicitly via onCloseCallback #51

Open
SebastianAigner opened this issue Mar 11, 2025 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@SebastianAigner
Copy link
Contributor

    runBlocking {
        server.connect(transport)
        val done = Job()
        server.onCloseCallback = {
            done.complete()
        }
        done.join()
    }

removing the done = Job() related logic from this causes the MCP server to terminate immediately, rather than wait for an process incoming requests.

@SebastianAigner SebastianAigner added the bug Something isn't working label Mar 11, 2025
@Mr3zee Mr3zee added the good first issue Good for newcomers label Mar 11, 2025
@JsFlo
Copy link
Contributor

JsFlo commented Mar 25, 2025

Is this an issue ? you want the server to "not terminate forever unless you get the event in "onCloseCallback" and this seems like the right/idiomatic way to do that (job.join()).

A different way to do the above would be


runBlocking {
    server.connect(transport)
    val done = CompletableDeferred<Unit>()
    server.onCloseCallback = {
        done.complete(Unit)
    }
    done.await()
}

and if you really didn't want to handle the onCloseCallback (like it seems in your case since you removed the job) then you could just wait forever

runBlocking {
    server.connect(transport)
    awaitCancellation()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants