From 56ec16a3c66061f16b5c921be7ebdb8f7cf5ca5c Mon Sep 17 00:00:00 2001 From: Teagan Glenn Date: Tue, 7 Oct 2025 15:42:13 -0600 Subject: [PATCH] feat(server): broaden query_media similarity identifiers --- docker/pyproject.deps.toml | 2 +- mcp_plex/server/tools/media_library.py | 26 +++++++++++++++++++------- pyproject.toml | 2 +- tests/test_server.py | 15 +++++++++++++++ uv.lock | 2 +- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/docker/pyproject.deps.toml b/docker/pyproject.deps.toml index 99b371c..6cdfa73 100644 --- a/docker/pyproject.deps.toml +++ b/docker/pyproject.deps.toml @@ -1,6 +1,6 @@ [project] name = "mcp-plex" -version = "2.0.11" +version = "2.0.12" requires-python = ">=3.11,<3.13" dependencies = [ "fastmcp>=2.11.2", diff --git a/mcp_plex/server/tools/media_library.py b/mcp_plex/server/tools/media_library.py index ce0b81b..a09653b 100644 --- a/mcp_plex/server/tools/media_library.py +++ b/mcp_plex/server/tools/media_library.py @@ -344,10 +344,13 @@ async def query_media( Field(description="Match a TMDb identifier", examples=[568467]), ] = None, similar_to: Annotated[ - str | Sequence[str] | None, + str | int | Sequence[str | int] | None, Field( - description="Recommend candidates similar to these identifiers", - examples=[["49915"], "tt8367814"], + description=( + "Recommend candidates similar to Plex rating keys, " + "IMDb/TMDb identifiers, or titles" + ), + examples=[[49915], "tt8367814", 568467, "The Gentlemen"], ), ] = None, limit: Annotated[ @@ -372,12 +375,21 @@ async def query_media( ) -> MediaSummaryResponse | list[AggregatedMediaItem]: """Run a structured query against indexed payload fields and optional vector searches.""" - def _listify(value: Sequence[str] | str | None) -> list[str]: + def _listify( + value: Sequence[str | int] | str | int | None, + ) -> list[str]: if value is None: return [] - if isinstance(value, str): - return [value] - return [v for v in value if isinstance(v, str) and v] + if isinstance(value, (str, int)): + text = str(value).strip() + return [text] if text else [] + items: list[str] = [] + for entry in value: + if isinstance(entry, (str, int)): + text = str(entry).strip() + if text: + items.append(text) + return items def _finalize( items: list[AggregatedMediaItem], diff --git a/pyproject.toml b/pyproject.toml index 75b2165..c78435e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mcp-plex" -version = "2.0.11" +version = "2.0.12" description = "Plex-Oriented Model Context Protocol Server" requires-python = ">=3.11,<3.13" diff --git a/tests/test_server.py b/tests/test_server.py index ac3c671..c948223 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -181,6 +181,21 @@ def test_server_tools(monkeypatch): if isinstance(item.get("plex"), dict) } >= {"61960"} + similar_structured_int = asyncio.run( + server.query_media.fn( + similar_to=49915, + type="episode", + limit=3, + summarize_for_llm=False, + ) + ) + assert similar_structured_int + assert { + item["plex"]["rating_key"] + for item in similar_structured_int + if isinstance(item.get("plex"), dict) + } >= {"61960"} + assert ( asyncio.run( server.query_media.fn( diff --git a/uv.lock b/uv.lock index 932f75c..671ae83 100644 --- a/uv.lock +++ b/uv.lock @@ -730,7 +730,7 @@ wheels = [ [[package]] name = "mcp-plex" -version = "2.0.11" +version = "2.0.12" source = { editable = "." } dependencies = [ { name = "fastapi" },