Skip to content

Commit 730a5aa

Browse files
authored
feat(server): broaden query_media similarity identifiers (#150)
1 parent 604800d commit 730a5aa

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

docker/pyproject.deps.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-plex"
3-
version = "2.0.11"
3+
version = "2.0.12"
44
requires-python = ">=3.11,<3.13"
55
dependencies = [
66
"fastmcp>=2.11.2",

mcp_plex/server/tools/media_library.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,13 @@ async def query_media(
344344
Field(description="Match a TMDb identifier", examples=[568467]),
345345
] = None,
346346
similar_to: Annotated[
347-
str | Sequence[str] | None,
347+
str | int | Sequence[str | int] | None,
348348
Field(
349-
description="Recommend candidates similar to these identifiers",
350-
examples=[["49915"], "tt8367814"],
349+
description=(
350+
"Recommend candidates similar to Plex rating keys, "
351+
"IMDb/TMDb identifiers, or titles"
352+
),
353+
examples=[[49915], "tt8367814", 568467, "The Gentlemen"],
351354
),
352355
] = None,
353356
limit: Annotated[
@@ -372,12 +375,21 @@ async def query_media(
372375
) -> MediaSummaryResponse | list[AggregatedMediaItem]:
373376
"""Run a structured query against indexed payload fields and optional vector searches."""
374377

375-
def _listify(value: Sequence[str] | str | None) -> list[str]:
378+
def _listify(
379+
value: Sequence[str | int] | str | int | None,
380+
) -> list[str]:
376381
if value is None:
377382
return []
378-
if isinstance(value, str):
379-
return [value]
380-
return [v for v in value if isinstance(v, str) and v]
383+
if isinstance(value, (str, int)):
384+
text = str(value).strip()
385+
return [text] if text else []
386+
items: list[str] = []
387+
for entry in value:
388+
if isinstance(entry, (str, int)):
389+
text = str(entry).strip()
390+
if text:
391+
items.append(text)
392+
return items
381393

382394
def _finalize(
383395
items: list[AggregatedMediaItem],

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mcp-plex"
7-
version = "2.0.11"
7+
version = "2.0.12"
88

99
description = "Plex-Oriented Model Context Protocol Server"
1010
requires-python = ">=3.11,<3.13"

tests/test_server.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ def test_server_tools(monkeypatch):
181181
if isinstance(item.get("plex"), dict)
182182
} >= {"61960"}
183183

184+
similar_structured_int = asyncio.run(
185+
server.query_media.fn(
186+
similar_to=49915,
187+
type="episode",
188+
limit=3,
189+
summarize_for_llm=False,
190+
)
191+
)
192+
assert similar_structured_int
193+
assert {
194+
item["plex"]["rating_key"]
195+
for item in similar_structured_int
196+
if isinstance(item.get("plex"), dict)
197+
} >= {"61960"}
198+
184199
assert (
185200
asyncio.run(
186201
server.query_media.fn(

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)