Skip to content

Commit 75afd5d

Browse files
authored
chore: add query filter to search history tool (#208)
1 parent ae5bd09 commit 75afd5d

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/deepset_mcp/api/search_history/protocols.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@
1313
class SearchHistoryResourceProtocol(Protocol):
1414
"""Protocol defining the interface for search history resources."""
1515

16-
async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResponse[SearchHistoryEntry]:
16+
async def list(
17+
self, limit: int = 10, after: str | None = None, query_filter: str | None = None
18+
) -> PaginatedResponse[SearchHistoryEntry]:
1719
"""List search history entries in the workspace.
1820
1921
:param limit: Maximum number of entries to return per page.
2022
:param after: Cursor to fetch the next page of results.
23+
:param query_filter: OData filter expression to narrow results.
2124
:returns: Paginated response of search history entries.
2225
"""
2326
...
2427

2528
async def list_pipeline(
26-
self, pipeline_name: str, limit: int = 10, after: str | None = None
29+
self, pipeline_name: str, limit: int = 10, after: str | None = None, query_filter: str | None = None
2730
) -> PaginatedResponse[SearchHistoryEntry]:
2831
"""List search history entries for a specific pipeline with pagination.
2932
3033
:param pipeline_name: Name of the pipeline.
3134
:param limit: Maximum number of entries to return per page.
3235
:param after: Cursor to fetch the next page of results.
36+
:param query_filter: OData filter expression to narrow results.
3337
:returns: Paginated response of search history entries (most recent first).
3438
"""
3539
...

src/deepset_mcp/api/search_history/resource.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ def _pipeline_path(self, pipeline_name: str) -> str:
3636
f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/search_history"
3737
)
3838

39-
async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResponse[SearchHistoryEntry]:
39+
async def list(
40+
self, limit: int = 10, after: str | None = None, query_filter: str | None = None
41+
) -> PaginatedResponse[SearchHistoryEntry]:
4042
"""List search history entries in the workspace.
4143
4244
:param limit: Maximum number of entries to return per page.
4345
:param after: Cursor to fetch the next page of results.
46+
:param query_filter: OData filter expression to narrow results.
4447
:returns: Paginated response of search history entries.
4548
"""
4649
params: dict[str, str | int] = {"limit": limit}
4750
if after is not None:
4851
params["after"] = after
52+
if query_filter is not None:
53+
params["filter"] = query_filter
4954

5055
resp = await self._client.request(
5156
endpoint=self._base_path(),
@@ -80,7 +85,7 @@ async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResp
8085
)
8186

8287
async def list_pipeline(
83-
self, pipeline_name: str, limit: int = 10, after: str | None = None
88+
self, pipeline_name: str, limit: int = 10, after: str | None = None, query_filter: str | None = None
8489
) -> PaginatedResponse[SearchHistoryEntry]:
8590
"""List search history entries for a specific pipeline with pagination.
8691
@@ -89,11 +94,14 @@ async def list_pipeline(
8994
:param pipeline_name: Name of the pipeline.
9095
:param limit: Maximum number of entries to return per page.
9196
:param after: Cursor to fetch the next page of results.
97+
:param query_filter: OData filter expression to narrow results.
9298
:returns: Paginated response of search history entries.
9399
"""
94100
params: dict[str, str | int] = {"limit": limit}
95101
if after is not None:
96102
params["after"] = after
103+
if query_filter is not None:
104+
params["filter"] = query_filter
97105

98106
resp = await self._client.request(
99107
endpoint=f"{self._pipeline_path(pipeline_name)}_archive",

src/deepset_mcp/tools/search_history.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212

1313
async def list_search_history(
14-
*, client: AsyncClientProtocol, workspace: str, limit: int = 10, after: str | None = None
14+
*,
15+
client: AsyncClientProtocol,
16+
workspace: str,
17+
limit: int = 10,
18+
after: str | None = None,
19+
query_filter: str | None = None,
1520
) -> PaginatedResponse[SearchHistoryEntry] | str:
1621
"""Retrieves search history for the configured deepset workspace.
1722
@@ -24,10 +29,18 @@ async def list_search_history(
2429
:param limit: Maximum number of entries to return per page.
2530
:param after: The cursor to fetch the next page of results.
2631
If there are more results to fetch, the cursor will appear as `next_cursor` on the response.
32+
:param query_filter: An OData filter expression to narrow down results.
33+
Supported fields: query, client_source_path, pipeline_version_id, answer, api_key,
34+
created_at, created_by, tags/tag_id, feedbacks, feedbacks/score, feedbacks/comment,
35+
feedbacks/bookmarked, session_id, search_session_id, feedbacks/result_id,
36+
request/filters, request/params, duration.
37+
Example: "created_at ge 2024-01-01T00:00:00Z" or "query eq 'my search'".
2738
:returns: Paginated list of search history entries or error message.
2839
"""
2940
try:
30-
return await client.search_history(workspace=workspace).list(limit=limit, after=after)
41+
return await client.search_history(workspace=workspace).list(
42+
limit=limit, after=after, query_filter=query_filter
43+
)
3144
except ResourceNotFoundError:
3245
return f"There is no workspace named '{workspace}'. Did you mean to configure it?"
3346
except (BadRequestError, UnexpectedAPIError) as e:
@@ -41,6 +54,7 @@ async def list_pipeline_search_history(
4154
pipeline_name: str,
4255
limit: int = 10,
4356
after: str | None = None,
57+
query_filter: str | None = None,
4458
) -> PaginatedResponse[SearchHistoryEntry] | str:
4559
"""Retrieves search history for a specific pipeline with pagination.
4660
@@ -54,11 +68,17 @@ async def list_pipeline_search_history(
5468
:param limit: Maximum number of entries to return per page.
5569
:param after: The cursor to fetch the next page of results.
5670
If there are more results to fetch, the cursor will appear as `next_cursor` on the response.
71+
:param query_filter: An OData filter expression to narrow down results.
72+
Supported fields: query, client_source_path, pipeline_version_id, answer, api_key,
73+
created_at, created_by, tags/tag_id, feedbacks, feedbacks/score, feedbacks/comment,
74+
feedbacks/bookmarked, session_id, search_session_id, feedbacks/result_id,
75+
request/filters, request/params, duration.
76+
Example: "created_at ge 2024-01-01T00:00:00Z" or "query eq 'my search'".
5777
:returns: Paginated list of search history entries or error message.
5878
"""
5979
try:
6080
return await client.search_history(workspace=workspace).list_pipeline(
61-
pipeline_name=pipeline_name, limit=limit, after=after
81+
pipeline_name=pipeline_name, limit=limit, after=after, query_filter=query_filter
6282
)
6383
except ResourceNotFoundError:
6484
return (

test/unit/tools/test_search_history.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ def __init__(
2727
self._list_exception = list_exception
2828
self._list_pipeline_exception = list_pipeline_exception
2929

30-
async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResponse[SearchHistoryEntry]:
30+
async def list(
31+
self, limit: int = 10, after: str | None = None, query_filter: str | None = None
32+
) -> PaginatedResponse[SearchHistoryEntry]:
3133
if self._list_exception:
3234
raise self._list_exception
3335
if self._list_response is not None:
3436
return self._list_response
3537
return PaginatedResponse(data=[], has_more=False, total=0)
3638

3739
async def list_pipeline(
38-
self, pipeline_name: str, limit: int = 10, after: str | None = None
40+
self, pipeline_name: str, limit: int = 10, after: str | None = None, query_filter: str | None = None
3941
) -> PaginatedResponse[SearchHistoryEntry]:
4042
if self._list_pipeline_exception:
4143
raise self._list_pipeline_exception

0 commit comments

Comments
 (0)