Skip to content

Commit 8f98c5c

Browse files
committed
Clear index state after MCP server shutdown
1 parent e9518d6 commit 8f98c5c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

redisvl/mcp/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ async def shutdown(self) -> None:
8787
self._vectorizer = None
8888
finally:
8989
if self._index is not None:
90-
await self._index.disconnect()
90+
index = self._index
91+
self._index = None
92+
await index.disconnect()
9193

9294
async def get_index(self) -> AsyncSearchIndex:
9395
"""Return the initialized async index or fail if startup has not run."""

tests/integration/test_mcp/test_server_startup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ async def test_server_shutdown_disconnects_owned_client(
199199
assert index.client is None
200200

201201

202+
@pytest.mark.asyncio
203+
async def test_server_get_index_fails_after_shutdown(
204+
monkeypatch, mcp_config_path, worker_id
205+
):
206+
monkeypatch.setattr(
207+
"redisvl.mcp.server.resolve_vectorizer_class",
208+
lambda class_name: FakeVectorizer,
209+
)
210+
settings = MCPSettings(
211+
config=mcp_config_path(index_name=f"mcp-get-index-after-shutdown-{worker_id}")
212+
)
213+
server = RedisVLMCPServer(settings)
214+
215+
await server.startup()
216+
await server.shutdown()
217+
218+
with pytest.raises(RuntimeError, match="has not been started"):
219+
await server.get_index()
220+
221+
202222
@pytest.mark.asyncio
203223
async def test_server_shutdown_disconnects_index_when_vectorizer_close_fails(
204224
monkeypatch, mcp_config_path, worker_id

0 commit comments

Comments
 (0)