fix(#80): keep MCP server alive until client disconnects#81
Merged
Conversation
- Add service.waiting().await after serve_server() to block until the client disconnects, preventing RunningService from being dropped immediately after initialization - Add tokio to dev-dependencies for #[tokio::test] support - Add StoreWrapper::new() pub(crate) constructor for test access - Add test exercising ToolHandler ingest/search/list data path - Make StoreWrapper and methods pub(crate) for crate-internal access Fixes #80
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
rmcp::serve_server().awaitonly handles the MCP initialization handshake and returns aRunningServicehandle. The actual message serving (tools/list, store_memory, etc.) runs as a background tokio task. The previous code dropped the handle immediately, cancelling the background task before any tool calls could be served.Fix
Add
service.waiting().awaitto keepblock_onalive until the client disconnects:This matches the pattern used by reference MCP server implementations with rmcp v1.2.
Changes
src/mcp/server.rs: Addservice.waiting().await— core lifecycle fixsrc/mcp/tools.rs: MakeStoreWrapperand methodspub(crate)for test accesssrc/mcp/tests.rs: Add#[tokio::test]exercising ingest/search/list data pathCargo.toml: Addtokioto[dev-dependencies]for#[tokio::test]Quality Gates
cargo fmt --check✅cargo clippy -- -D warnings✅cargo test✅ (162 passed)cargo test --no-default-features✅ (154 passed)cargo clippy --no-default-features -- -D warnings✅Fixes #80
Part of #72