Skip to content

Commit f089d6b

Browse files
authored
feat: add search_pipeline_with_params tool (#203)
1 parent 337345b commit f089d6b

3 files changed

Lines changed: 58 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
@@ -38,6 +38,7 @@
3838
list_pipelines as list_pipelines_tool,
3939
search_pipeline as search_pipeline_tool,
4040
search_pipeline_with_filters as search_pipeline_with_filters_tool,
41+
search_pipeline_with_params as search_pipeline_with_params_tool,
4142
update_pipeline as update_pipeline_tool,
4243
validate_pipeline as validate_pipeline_tool,
4344
)
@@ -133,6 +134,10 @@ async def search_docs(query: str) -> str:
133134
search_pipeline_with_filters_tool,
134135
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),
135136
),
137+
"search_pipeline_with_params": (
138+
search_pipeline_with_params_tool,
139+
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),
140+
),
136141
"list_indexes": (
137142
list_indexes_tool,
138143
ToolConfig(needs_client=True, needs_workspace=True, memory_type=MemoryType.EXPLORABLE),

src/deepset_mcp/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
list_pipelines,
2222
search_pipeline,
2323
search_pipeline_with_filters,
24+
search_pipeline_with_params,
2425
update_pipeline,
2526
validate_pipeline,
2627
)
@@ -51,6 +52,7 @@
5152
"deploy_pipeline",
5253
"search_pipeline",
5354
"search_pipeline_with_filters",
55+
"search_pipeline_with_params",
5456
"create_pipeline",
5557
"update_pipeline",
5658
"validate_pipeline",

src/deepset_mcp/tools/pipeline.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,54 @@ async def search_pipeline_with_filters(
417417
return f"Failed to search using pipeline '{pipeline_name}': {e}"
418418
except Exception as e:
419419
return f"An unexpected error occurred while searching with pipeline '{pipeline_name}': {str(e)}"
420+
421+
422+
async def search_pipeline_with_params(
423+
*,
424+
client: AsyncClientProtocol,
425+
workspace: str,
426+
pipeline_name: str,
427+
query: str,
428+
params: dict[str, Any] | None = None,
429+
) -> DeepsetSearchResponse | str:
430+
"""Searches using a pipeline with params.
431+
432+
Uses the specified pipeline to perform a search with the given query and params.
433+
Params can be arbitrary parameters to customize the search behavior.
434+
Filters can be used as well under the "filters" key in params.
435+
Filters follow the Haystack filter syntax: https://docs.haystack.deepset.ai/docs/metadata-filtering.
436+
Before executing the search, checks if the pipeline is deployed (status = DEPLOYED).
437+
Returns search results.
438+
439+
:param client: The async client for API communication.
440+
:param workspace: The workspace name.
441+
:param pipeline_name: Name of the pipeline to use for search.
442+
:param query: The search query to execute.
443+
:param params: The parameters to customize the search.
444+
445+
:returns: Search results or error message.
446+
"""
447+
try:
448+
# First, check if the pipeline exists and get its status
449+
pipeline = await client.pipelines(workspace=workspace).get(pipeline_name=pipeline_name)
450+
451+
# Check if pipeline is deployed
452+
if pipeline.status != "DEPLOYED":
453+
return (
454+
f"Pipeline '{pipeline_name}' is not deployed (current status: {pipeline.status}). "
455+
f"Please deploy the pipeline first using the deploy_pipeline tool before attempting to search."
456+
)
457+
458+
# Execute the search
459+
return await client.pipelines(workspace=workspace).search(
460+
pipeline_name=pipeline_name, query=query, params=params if params is not None else None
461+
)
462+
463+
except ResourceNotFoundError:
464+
return f"There is no pipeline named '{pipeline_name}' in workspace '{workspace}'."
465+
except BadRequestError as e:
466+
return f"Failed to search using pipeline '{pipeline_name}': {e}"
467+
except UnexpectedAPIError as e:
468+
return f"Failed to search using pipeline '{pipeline_name}': {e}"
469+
except Exception as e:
470+
return f"An unexpected error occurred while searching with pipeline '{pipeline_name}': {str(e)}"

0 commit comments

Comments
 (0)