Skip to content

Commit 01f9e8b

Browse files
committed
add new tool for search with filters
1 parent 0d45984 commit 01f9e8b

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/deepset_mcp/mcp/tool_registry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
get_pipeline_logs as get_pipeline_logs_tool,
3838
list_pipelines as list_pipelines_tool,
3939
search_pipeline as search_pipeline_tool,
40+
search_pipeline_with_filters as search_pipeline_with_filters_tool,
4041
update_pipeline as update_pipeline_tool,
4142
validate_pipeline as validate_pipeline_tool,
4243
)
@@ -128,6 +129,10 @@ async def search_docs(query: str) -> str:
128129
search_pipeline_tool,
129130
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),
130131
),
132+
"search_pipeline_with_filters": (
133+
search_pipeline_with_filters_tool,
134+
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),
135+
),
131136
"list_indexes": (
132137
list_indexes_tool,
133138
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),

src/deepset_mcp/tools/pipeline.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import asyncio
6+
from typing import Any
67

78
import yaml
89
from pydantic import BaseModel
@@ -367,3 +368,44 @@ async def search_pipeline(
367368
return f"Failed to search using pipeline '{pipeline_name}': {e}"
368369
except Exception as e:
369370
return f"An unexpected error occurred while searching with pipeline '{pipeline_name}': {str(e)}"
371+
372+
async def search_pipeline_with_filters(
373+
*, client: AsyncClientProtocol, workspace: str, pipeline_name: str, query: str, filters: dict[str, Any] | None = None
374+
) -> DeepsetSearchResponse | str:
375+
"""Searches using a pipeline with filters.
376+
377+
Uses the specified pipeline to perform a search with the given query.
378+
Before executing the search, checks if the pipeline is deployed (status = DEPLOYED).
379+
Returns search results.
380+
381+
:param client: The async client for API communication.
382+
:param workspace: The workspace name.
383+
:param pipeline_name: Name of the pipeline to use for search.
384+
:param query: The search query to execute.
385+
:param filters: The filters to apply to the search.
386+
387+
:returns: Search results or error message.
388+
"""
389+
try:
390+
# First, check if the pipeline exists and get its status
391+
pipeline = await client.pipelines(workspace=workspace).get(pipeline_name=pipeline_name)
392+
393+
# Check if pipeline is deployed
394+
if pipeline.status != "DEPLOYED":
395+
return (
396+
f"Pipeline '{pipeline_name}' is not deployed (current status: {pipeline.status}). "
397+
f"Please deploy the pipeline first using the deploy_pipeline tool before attempting to search."
398+
)
399+
400+
# Execute the search
401+
return await client.pipelines(workspace=workspace).search(pipeline_name=pipeline_name, query=query, filters=filters)
402+
403+
except ResourceNotFoundError:
404+
return f"There is no pipeline named '{pipeline_name}' in workspace '{workspace}'."
405+
except BadRequestError as e:
406+
return f"Failed to search using pipeline '{pipeline_name}': {e}"
407+
except UnexpectedAPIError as e:
408+
return f"Failed to search using pipeline '{pipeline_name}': {e}"
409+
except Exception as e:
410+
return f"An unexpected error occurred while searching with pipeline '{pipeline_name}': {str(e)}"
411+

0 commit comments

Comments
 (0)