Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mcp_plex/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import inspect
import json
from contextlib import asynccontextmanager
from typing import Annotated, Any, Callable

from fastapi import FastAPI
Expand Down Expand Up @@ -55,9 +56,12 @@ def __init__(
https=self.settings.qdrant_https,
)

@asynccontextmanager
async def _lifespan(app: FastMCP): # noqa: ARG001
yield
await self.close()
try:
yield
finally:
await self.close()
Comment on lines +61 to +64
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The try/finally block is redundant here. Since asynccontextmanager already handles exceptions and ensures cleanup code runs, the bare try/yield/finally pattern doesn't add value and can be simplified to just yield followed by await self.close().

Suggested change
try:
yield
finally:
await self.close()
yield
await self.close()

Copilot uses AI. Check for mistakes.

super().__init__(lifespan=_lifespan)
self._reranker: CrossEncoder | None = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mcp-plex"
version = "0.26.25"
version = "0.26.26"

description = "Plex-Oriented Model Context Protocol Server"
requires-python = ">=3.11,<3.13"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,12 @@ def test_rest_endpoints(monkeypatch):

resp = client.get("/rest")
assert resp.status_code == 200


def test_server_lifespan_context(monkeypatch):
with _load_server(monkeypatch) as module:
async def _lifespan() -> None:
async with module.server._mcp_server.lifespan(module.server):
pass

asyncio.run(_lifespan())
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.