Skip to content

Commit 34e3da6

Browse files
authored
Merge pull request #17 from deepset-ai/feat/update_mcp_pipeline_tools
feat: use pipeline tools in MCP
2 parents 4a2ace6 + 29e6b4b commit 34e3da6

10 files changed

Lines changed: 952 additions & 323 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies = [
1111
"uvicorn>=0.34.2",
1212
"httpx",
1313
"pydantic>=2.0.0",
14+
"pyyaml",
1415
]
1516

1617
[project.scripts]
@@ -28,15 +29,15 @@ dev = [
2829
"pytest",
2930
"pytest-asyncio",
3031
"python-dotenv",
31-
"pyyaml",
3232
]
3333
lint = [
3434
"ruff",
3535
]
3636

3737
types = [
3838
"mypy",
39-
"types-requests"
39+
"types-requests",
40+
"types-PyYAML",
4041
]
4142

4243
[tool.pytest.ini_options]

src/deepset_mcp/api/pipeline/resource.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from deepset_mcp.api.exceptions import UnexpectedAPIError
44
from deepset_mcp.api.pipeline.models import DeepsetPipeline, PipelineValidationResult, ValidationError
55
from deepset_mcp.api.protocols import AsyncClientProtocol
6-
from deepset_mcp.api.transport import raise_for_status
6+
from deepset_mcp.api.transport import TransportResponse, raise_for_status
77

88

99
class PipelineResource:
@@ -109,7 +109,7 @@ async def get(self, pipeline_name: str, include_yaml: bool = True) -> DeepsetPip
109109

110110
return pipeline
111111

112-
async def create(self, name: str, yaml_config: str) -> None:
112+
async def create(self, name: str, yaml_config: str) -> TransportResponse:
113113
"""Create a new pipeline with a name and YAML config."""
114114
data = {"name": name, "query_yaml": yaml_config}
115115
resp = await self._client.request(
@@ -120,12 +120,14 @@ async def create(self, name: str, yaml_config: str) -> None:
120120

121121
raise_for_status(resp)
122122

123+
return resp
124+
123125
async def update(
124126
self,
125127
pipeline_name: str,
126128
updated_pipeline_name: str | None = None,
127129
yaml_config: str | None = None,
128-
) -> None:
130+
) -> TransportResponse:
129131
"""Update name and/or YAML config of an existing pipeline."""
130132
# Handle name update first if any
131133
if updated_pipeline_name is not None:
@@ -139,6 +141,9 @@ async def update(
139141

140142
pipeline_name = updated_pipeline_name
141143

144+
if yaml_config is None:
145+
return name_resp
146+
142147
if yaml_config is not None:
143148
yaml_resp = await self._client.request(
144149
endpoint=f"v1/workspaces/{self._workspace}/pipelines/{pipeline_name}/yaml",
@@ -147,3 +152,7 @@ async def update(
147152
)
148153

149154
raise_for_status(yaml_resp)
155+
156+
return yaml_resp
157+
158+
raise ValueError("Either `updated_pipeline_name` or `yaml_config` must be provided.")

src/deepset_mcp/api/protocols.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from types import TracebackType
22
from typing import Any, Protocol, Self
33

4+
from deepset_mcp.api.pipeline.models import DeepsetPipeline, PipelineValidationResult
45
from deepset_mcp.api.transport import TransportResponse
56

67

@@ -30,3 +31,44 @@ async def __aexit__(
3031
) -> bool:
3132
"""Exit the AsyncContextmanager and clean up resources."""
3233
...
34+
35+
def pipelines(self, workspace: str) -> "PipelineResourceProtocol":
36+
"""Access pipelines in the specified workspace."""
37+
...
38+
39+
40+
class PipelineResourceProtocol(Protocol):
41+
"""Protocol defining the implementation for PipelineResource."""
42+
43+
def __init__(self, client: AsyncClientProtocol, workspace: str) -> None:
44+
"""Initialize a PipelineResource."""
45+
...
46+
47+
async def validate(self, yaml_config: str) -> PipelineValidationResult:
48+
"""Validate a pipeline's YAML configuration against the API."""
49+
...
50+
51+
async def get(self, pipeline_name: str) -> DeepsetPipeline:
52+
"""Fetch a single pipeline by its name."""
53+
...
54+
55+
async def list(
56+
self,
57+
page_number: int = 1,
58+
limit: int = 10,
59+
) -> list[DeepsetPipeline]:
60+
"""List pipelines in the configured workspace with optional pagination."""
61+
...
62+
63+
async def create(self, name: str, yaml_config: str) -> Any:
64+
"""Create a new pipeline with a name and YAML config."""
65+
...
66+
67+
async def update(
68+
self,
69+
pipeline_name: str,
70+
updated_pipeline_name: str | None = None,
71+
yaml_config: str | None = None,
72+
) -> Any:
73+
"""Update name and/or YAML config of an existing pipeline."""
74+
...

0 commit comments

Comments
 (0)