You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this question would not be more appropriate as an issue in a specific repository
I have searched existing discussions and documentation for answers
Question Category
Protocol Specification
SDK Usage
Server Implementation
General Implementation
Documentation
Other
Your Question
Hi all,
I’m working with the Go SDK and the MCP protocol, and I’m trying to ensure my application state is properly cleaned up when the server disconnects or closes. Here’s a simplified version of my code:
Problem:
When I run this with go run and hit Ctrl+C, everything works as expected: stop3pApplication is called and cleanup happens.
However, when I run the same code via Claude Desktop or the MCP Inspector, stop3pApplication is never called. I suspect these tools are handling disconnects differently (not sending a signal?), so my cleanup code in defer isn’t triggered.
Question:
How can I reliably detect when the connection is closed or the server is disconnected, especially in these environments?
Is there a better way to ensure that stop3pApplication is always called, regardless of how the server is stopped/disconnected?
Are there any best practices or examples for handling cleanup in this kind of context/protocol setup?
Any advice or pointers would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Question Category
Your Question
Hi all,
I’m working with the Go SDK and the MCP protocol, and I’m trying to ensure my application state is properly cleaned up when the server disconnects or closes. Here’s a simplified version of my code:
Problem:
When I run this with go run and hit Ctrl+C, everything works as expected: stop3pApplication is called and cleanup happens.
However, when I run the same code via Claude Desktop or the MCP Inspector, stop3pApplication is never called. I suspect these tools are handling disconnects differently (not sending a signal?), so my cleanup code in defer isn’t triggered.
Question:
Any advice or pointers would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions