Skip to content

fix/mcp_session_auto_close_when_Mcpworkbench_deleted #6497

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

Conversation

SongChiYoung
Copy link
Contributor

Why are these changes needed?

As-is: Deleting McpWorkbench does not close the McpSession.
To-be: Deleting McpWorkbench now properly closes the McpSession.

Related issue number

Checks

@SongChiYoung SongChiYoung changed the title Fix/mcp workbench del with closed session fix/mcp_session_auto_close_when_Mcpworkbench_deleted May 9, 2025
@jackgerrits
Copy link
Member

Do you think this might fix #6467?

Copy link

codecov bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.75%. Comparing base (6427c07) to head (ec8358b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6497      +/-   ##
==========================================
- Coverage   78.75%   78.75%   -0.01%     
==========================================
  Files         225      225              
  Lines       16581    16589       +8     
==========================================
+ Hits        13058    13064       +6     
- Misses       3523     3525       +2     
Flag Coverage Δ
unittests 78.75% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SongChiYoung
Copy link
Contributor Author

While attempting to improve code coverage, I discovered that the previous fallback logic in del (used to stop the actor if McpWorkbench is GC’ed) did not behave correctly under certain loop conditions.

As a result, the shutdown logic has been rewritten.

This change simplifies the behavior, avoids misleading fallback attempts, and ensures the shutdown path is verifiable via testing (e.g., pytest.warns()).

@SongChiYoung
Copy link
Contributor Author

@jackgerrits
Regarding #6467
This change might help in some scenarios, especially when McpWorkbench is deleted unintentionally (e.g., via GC or teardown).

That said, I’m not entirely confident about the lifecycle behavior on Windows — I’m not a specialist in how del interacts with the asyncio loop on that platform.

Ideally, McpWorkbench should be used via async with, in which case aexit guarantees proper shutdown of the MCP session.

The fact that it doesn’t close cleanly in #6467 is quite weird and deserves separate investigation.

Copy link
Member

@jackgerrits jackgerrits left a comment

Choose a reason for hiding this comment

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

Sounds good, thanks!

@jackgerrits jackgerrits enabled auto-merge (squash) May 12, 2025 13:24
@jackgerrits jackgerrits merged commit c26d894 into microsoft:main May 12, 2025
62 checks passed
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.

2 participants