-
Notifications
You must be signed in to change notification settings - Fork 2
feat: [ECO-200] - Add Search history tool #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tholor
merged 9 commits into
main
from
feature/eco-200-mcp-search-history-add-new-search-history-tool
Feb 24, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d5bc5e
feat: [ECO-200] - Add Search history tool
YassineGabsi d320a96
fix: linting
YassineGabsi 0acda9a
fix: tests
YassineGabsi 017f5a4
fix: format
YassineGabsi fcc4f7f
feat: add readme how to run locally
YassineGabsi d86f091
fix: tests & unused comment
YassineGabsi 143ec72
fix: linting
YassineGabsi 019d21a
fix: format
YassineGabsi 8fe6d36
fix: add timeout to search history request
YassineGabsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Search history API module.""" | ||
|
|
||
| from .models import SearchHistoryEntry | ||
| from .resource import SearchHistoryResource | ||
|
|
||
| __all__ = ["SearchHistoryEntry", "SearchHistoryResource"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Models for search history API.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel, Field, field_validator | ||
|
|
||
|
|
||
| class SearchHistoryEntry(BaseModel): | ||
| """A single search history entry from the deepset platform. | ||
|
|
||
| Contains query, answers, prompts, feedback, and other metadata. | ||
| """ | ||
|
|
||
| model_config = {"extra": "allow"} | ||
|
|
||
| query: str | None = Field(default=None, description="The search query that was executed") | ||
| answer: str | None = Field(default=None, description="The answer returned by the pipeline") | ||
| created_at: str | None = Field(default=None, description="When the search was performed") | ||
| pipeline_name: str | None = Field(default=None, description="Name of the pipeline used") | ||
| feedback: list[dict[str, Any]] | None = Field(default=None, description="User feedback on the search") | ||
|
|
||
| @field_validator("feedback", mode="before") | ||
| @classmethod | ||
| def _feedback_to_list(cls, v: Any) -> list[dict[str, Any]] | None: | ||
| if v is None: | ||
| return None | ||
| if isinstance(v, list): | ||
| return v | ||
| if isinstance(v, dict): | ||
| return [v] | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Protocols for search history resources.""" | ||
|
|
||
| from typing import Protocol | ||
|
|
||
| from deepset_mcp.api.search_history.models import SearchHistoryEntry | ||
| from deepset_mcp.api.shared_models import PaginatedResponse | ||
|
|
||
|
|
||
| class SearchHistoryResourceProtocol(Protocol): | ||
| """Protocol defining the interface for search history resources.""" | ||
|
|
||
| async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResponse[SearchHistoryEntry]: | ||
| """List search history entries in the workspace. | ||
|
|
||
| :param limit: Maximum number of entries to return per page. | ||
| :param after: Cursor to fetch the next page of results. | ||
| :returns: Paginated response of search history entries. | ||
| """ | ||
| ... | ||
|
|
||
| async def list_pipeline( | ||
| self, pipeline_name: str, limit: int = 10, after: str | None = None | ||
| ) -> PaginatedResponse[SearchHistoryEntry]: | ||
| """List search history entries for a specific pipeline with pagination. | ||
|
|
||
| :param pipeline_name: Name of the pipeline. | ||
| :param limit: Maximum number of entries to return per page. | ||
| :param after: Cursor to fetch the next page of results. | ||
| :returns: Paginated response of search history entries (most recent first). | ||
| """ | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Resource implementation for search history API.""" | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from urllib.parse import quote | ||
|
|
||
| from deepset_mcp.api.search_history.models import SearchHistoryEntry | ||
| from deepset_mcp.api.search_history.protocols import SearchHistoryResourceProtocol | ||
| from deepset_mcp.api.shared_models import PaginatedResponse | ||
| from deepset_mcp.api.transport import raise_for_status | ||
|
|
||
| if TYPE_CHECKING: | ||
| from deepset_mcp.api.protocols import AsyncClientProtocol | ||
|
|
||
|
|
||
| class SearchHistoryResource(SearchHistoryResourceProtocol): | ||
| """Manages interactions with the deepset search history API.""" | ||
|
|
||
| def __init__(self, client: "AsyncClientProtocol", workspace: str) -> None: | ||
| """Initialize the search history resource. | ||
|
|
||
| :param client: The async REST client. | ||
| :param workspace: The workspace to use. | ||
| """ | ||
| self._client = client | ||
| self._workspace = workspace | ||
|
|
||
| def _base_path(self) -> str: | ||
| return f"v1/workspaces/{quote(self._workspace, safe='')}/search_history" | ||
|
|
||
| def _pipeline_path(self, pipeline_name: str) -> str: | ||
| return ( | ||
| f"v1/workspaces/{quote(self._workspace, safe='')}/pipelines/{quote(pipeline_name, safe='')}/search_history" | ||
| ) | ||
|
|
||
| async def list(self, limit: int = 10, after: str | None = None) -> PaginatedResponse[SearchHistoryEntry]: | ||
| """List search history entries in the workspace. | ||
|
|
||
| :param limit: Maximum number of entries to return per page. | ||
| :param after: Cursor to fetch the next page of results. | ||
| :returns: Paginated response of search history entries. | ||
| """ | ||
| params: dict[str, str | int] = {"limit": limit} | ||
| if after is not None: | ||
| params["after"] = after | ||
|
|
||
| resp = await self._client.request( | ||
| endpoint=self._base_path(), | ||
| method="GET", | ||
| params=params, | ||
| timeout=70.0, | ||
| ) | ||
|
|
||
| raise_for_status(resp) | ||
|
|
||
| if resp.json is None: | ||
| return PaginatedResponse( | ||
| data=[], | ||
| has_more=False, | ||
| total=0, | ||
| next_cursor=None, | ||
| ) | ||
|
|
||
| # API may return paginated shape: { "data": [...], "has_more": bool, "total": int } | ||
| data = resp.json if isinstance(resp.json, dict) else {"data": resp.json} | ||
| items = data.get("data", []) | ||
| if not isinstance(items, list): | ||
| items = [] | ||
|
|
||
| return PaginatedResponse[SearchHistoryEntry].create_with_cursor_field( | ||
| { | ||
| "data": items, | ||
| "has_more": data.get("has_more", False), | ||
| "total": data.get("total"), | ||
| }, | ||
| "created_at", | ||
| ) | ||
|
|
||
| async def list_pipeline( | ||
| self, pipeline_name: str, limit: int = 10, after: str | None = None | ||
| ) -> PaginatedResponse[SearchHistoryEntry]: | ||
| """List search history entries for a specific pipeline with pagination. | ||
|
|
||
| Uses the pipeline search history archive endpoint (full history, most recent first). | ||
|
|
||
| :param pipeline_name: Name of the pipeline. | ||
| :param limit: Maximum number of entries to return per page. | ||
| :param after: Cursor to fetch the next page of results. | ||
| :returns: Paginated response of search history entries. | ||
| """ | ||
| params: dict[str, str | int] = {"limit": limit} | ||
| if after is not None: | ||
| params["after"] = after | ||
|
|
||
| resp = await self._client.request( | ||
| endpoint=f"{self._pipeline_path(pipeline_name)}_archive", | ||
| method="GET", | ||
| params=params, | ||
| timeout=70.0, | ||
| ) | ||
|
|
||
| raise_for_status(resp) | ||
|
|
||
| if resp.json is None: | ||
| return PaginatedResponse( | ||
| data=[], | ||
| has_more=False, | ||
| total=0, | ||
| next_cursor=None, | ||
| ) | ||
|
|
||
| data = resp.json if isinstance(resp.json, dict) else {"data": resp.json} | ||
| items = data.get("data", []) | ||
| if not isinstance(items, list): | ||
| items = [] | ||
|
|
||
| return PaginatedResponse[SearchHistoryEntry].create_with_cursor_field( | ||
| { | ||
| "data": items, | ||
| "has_more": data.get("has_more", False), | ||
| "total": data.get("total"), | ||
| }, | ||
| "created_at", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.