|
| 1 | +from deepset_mcp.api.client import AsyncDeepsetClient |
| 2 | +from deepset_mcp.api.pipeline.log_level import LogLevel |
| 3 | +from deepset_mcp.tools.pipeline import ( |
| 4 | + create_pipeline as create_pipeline_tool, |
| 5 | + deploy_pipeline as deploy_pipeline_tool, |
| 6 | + get_pipeline as get_pipeline_tool, |
| 7 | + get_pipeline_logs as get_pipeline_logs_tool, |
| 8 | + list_pipelines as list_pipelines_tool, |
| 9 | + search_pipeline as search_pipeline_tool, |
| 10 | + update_pipeline as update_pipeline_tool, |
| 11 | + validate_pipeline as validate_pipeline_tool, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +async def list_pipelines(workspace: str) -> str: |
| 16 | + """Retrieves a list of all pipeline available within the currently configured deepset workspace. |
| 17 | +
|
| 18 | + Use this when you need to know the names or IDs of existing pipeline. |
| 19 | + This does not return the pipeline configuration. |
| 20 | + """ |
| 21 | + async with AsyncDeepsetClient() as client: |
| 22 | + response = await list_pipelines_tool(client, workspace) |
| 23 | + |
| 24 | + return response |
| 25 | + |
| 26 | + |
| 27 | +async def get_pipeline(workspace: str, pipeline_name: str) -> str: |
| 28 | + """Fetches detailed configuration information for a specific pipeline, identified by its unique `pipeline_name`. |
| 29 | +
|
| 30 | + This includes its components, connections, and metadata. |
| 31 | + Use this when you need to inspect the structure or settings of a known pipeline. |
| 32 | +
|
| 33 | + :param workspace: The deepset workspace to operate on. |
| 34 | + :param pipeline_name: Name of the pipeline to retrieve. |
| 35 | + """ |
| 36 | + async with AsyncDeepsetClient() as client: |
| 37 | + response = await get_pipeline_tool(client, workspace, pipeline_name) |
| 38 | + |
| 39 | + return response |
| 40 | + |
| 41 | + |
| 42 | +async def create_pipeline(workspace: str, pipeline_name: str, yaml_configuration: str) -> str: |
| 43 | + """Creates a new pipeline in deepset. |
| 44 | +
|
| 45 | + :param workspace: The deepset workspace to operate on. |
| 46 | + :param pipeline_name: Name of the pipeline to create |
| 47 | + :param yaml_configuration: YAML configuration for the pipeline |
| 48 | + """ |
| 49 | + async with AsyncDeepsetClient() as client: |
| 50 | + response = await create_pipeline_tool(client, workspace, pipeline_name, yaml_configuration) |
| 51 | + |
| 52 | + return response |
| 53 | + |
| 54 | + |
| 55 | +async def update_pipeline( |
| 56 | + workspace: str, pipeline_name: str, original_configuration_snippet: str, replacement_configuration_snippet: str |
| 57 | +) -> str: |
| 58 | + """Updates an existing pipeline in deepset. |
| 59 | +
|
| 60 | + The update is performed by replacing the original configuration snippet with the new one. |
| 61 | + Make sure that your original snippet only has a single exact match in the pipeline configuration. |
| 62 | + Respect whitespace and formatting. |
| 63 | +
|
| 64 | + :param workspace: The deepset workspace to operate on. |
| 65 | + :param pipeline_name: Name of the pipeline to update |
| 66 | + :param original_configuration_snippet: The configuration snippet to replace |
| 67 | + :param replacement_configuration_snippet: The new configuration snippet |
| 68 | + """ |
| 69 | + async with AsyncDeepsetClient() as client: |
| 70 | + response = await update_pipeline_tool( |
| 71 | + client=client, |
| 72 | + workspace=workspace, |
| 73 | + pipeline_name=pipeline_name, |
| 74 | + original_config_snippet=original_configuration_snippet, |
| 75 | + replacement_config_snippet=replacement_configuration_snippet, |
| 76 | + ) |
| 77 | + |
| 78 | + return response |
| 79 | + |
| 80 | + |
| 81 | +async def validate_pipeline(workspace: str, yaml_configuration: str) -> str: |
| 82 | + """ |
| 83 | + Validates the structure and syntax of a provided pipeline YAML configuration against the deepset API specifications. |
| 84 | +
|
| 85 | + Provide the YAML configuration as a string. |
| 86 | + Returns a validation result, indicating success or detailing any errors or warnings found. |
| 87 | + Use this *before* attempting to create or update a pipeline with new YAML. |
| 88 | +
|
| 89 | + :param workspace: The deepset workspace to operate on. |
| 90 | + :param yaml_configuration: YAML configuration to validate. |
| 91 | + """ |
| 92 | + async with AsyncDeepsetClient() as client: |
| 93 | + response = await validate_pipeline_tool(client, workspace, yaml_configuration) |
| 94 | + |
| 95 | + return response |
| 96 | + |
| 97 | + |
| 98 | +async def get_pipeline_logs(workspace: str, pipeline_name: str, limit: int = 30, level: str | None = None) -> str: |
| 99 | + """Fetches logs for a specific pipeline in the deepset workspace. |
| 100 | +
|
| 101 | + Use this to debug pipeline issues, monitor pipeline execution, or understand what happened during pipeline runs. |
| 102 | + The logs provide detailed information about pipeline operations, errors, and warnings. |
| 103 | +
|
| 104 | + :param workspace: The deepset workspace to operate on. |
| 105 | + :param pipeline_name: Name of the pipeline to fetch logs for. |
| 106 | + :param limit: Maximum number of log entries to return (default: 30, max: 100). |
| 107 | + :param level: Filter logs by level. Valid values: 'info', 'warning', 'error'. If not specified, returns all levels. |
| 108 | + """ |
| 109 | + # Convert string level to LogLevel enum if provided |
| 110 | + log_level: LogLevel | None = None |
| 111 | + if level is not None: |
| 112 | + try: |
| 113 | + log_level = LogLevel(level) |
| 114 | + except ValueError: |
| 115 | + return f"Invalid log level '{level}'. Valid values are: 'info', 'warning', 'error'." |
| 116 | + |
| 117 | + async with AsyncDeepsetClient() as client: |
| 118 | + response = await get_pipeline_logs_tool( |
| 119 | + client=client, |
| 120 | + workspace=workspace, |
| 121 | + pipeline_name=pipeline_name, |
| 122 | + limit=limit, |
| 123 | + level=log_level, |
| 124 | + ) |
| 125 | + return response |
| 126 | + |
| 127 | + |
| 128 | +async def deploy_pipeline(workspace: str, pipeline_name: str) -> str: |
| 129 | + """Deploys a pipeline to production in the deepset workspace. |
| 130 | +
|
| 131 | + Use this to deploy a pipeline that has been created and validated. |
| 132 | + The deployment process will validate the pipeline configuration and deploy it if valid. |
| 133 | + If deployment fails due to validation errors, you will receive detailed error information. |
| 134 | +
|
| 135 | + :param workspace: The deepset workspace to operate on. |
| 136 | + :param pipeline_name: Name of the pipeline to deploy. |
| 137 | + """ |
| 138 | + async with AsyncDeepsetClient() as client: |
| 139 | + response = await deploy_pipeline_tool( |
| 140 | + client=client, workspace=workspace, pipeline_name=pipeline_name, wait_for_deployment=True |
| 141 | + ) |
| 142 | + return response |
| 143 | + |
| 144 | + |
| 145 | +async def search_pipeline(workspace: str, pipeline_name: str, query: str) -> str: |
| 146 | + """Search using a deployed pipeline in the deepset workspace. |
| 147 | +
|
| 148 | + This tool allows you to execute a search query using a specific pipeline. |
| 149 | + The pipeline must already be deployed (status = DEPLOYED) for the search to work. |
| 150 | + If the pipeline is not deployed, you will receive an error message instructing you to deploy it first. |
| 151 | +
|
| 152 | + Use this tool when you want to: |
| 153 | + - Test a deployed pipeline with a specific query |
| 154 | + - Get search results from a knowledge base using a specific pipeline |
| 155 | + - Retrieve answers or documents based on a search query |
| 156 | +
|
| 157 | + :param workspace: The deepset workspace to operate on. |
| 158 | + :param pipeline_name: Name of the deployed pipeline to use for search. |
| 159 | + :param query: The search query to execute. |
| 160 | + """ |
| 161 | + async with AsyncDeepsetClient() as client: |
| 162 | + response = await search_pipeline_tool( |
| 163 | + client=client, workspace=workspace, pipeline_name=pipeline_name, query=query |
| 164 | + ) |
| 165 | + return response |
0 commit comments