Skip to content

Conversation

@chriscasola
Copy link
Contributor

Make Server.Run return when the provided context is canceled.

Add tests for when the Run context is cancelled and also for when the server process receives a signal.

Fixes #107

mcp/cmd_test.go Outdated
session, err := client.Connect(ctx, mcp.NewCommandTransport(cmd))
if err != nil {
t.Fatal(err)
log.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something. Why switch to log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file was already using log -- I will replace it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I see the logs were there originally because this sometimes runs as a sub-process. You can leave them. Sorry for the noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem -- I think runServer is the only function called in the sub-process, and it is still using log, so should be set.

Make `Server.Run` return when the provided context
is canceled.

Add tests for when the `Run` context is cancelled and
also for when the server process receives a signal.

Fixes modelcontextprotocol#107
@chriscasola chriscasola force-pushed the server-context-cancel branch from b3f9138 to 5ba4d6e Compare July 9, 2025 18:01
@chriscasola chriscasola requested a review from jba July 9, 2025 18:13
@jba
Copy link
Contributor

jba commented Jul 10, 2025

Thanks!

@jba jba merged commit a1a3510 into modelcontextprotocol:main Jul 10, 2025
3 checks passed
@chriscasola chriscasola deleted the server-context-cancel branch July 10, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A server connection using stdio transport cannot be closed gracefully

2 participants