Skip to content

Commit 1cce989

Browse files
authored
refactor: split up protocols per resource (#122)
* refactor: split up protocols per resource * chire: update gitignore * chore: update gitignore
1 parent b67789f commit 1cce989

23 files changed

Lines changed: 270 additions & 232 deletions

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ wheels/
1414
.env
1515
.env.prod
1616
.env.dev
17-
.env.test
17+
.env.test
18+
19+
20+
agent_runs/
21+
22+
misc.xml
23+
modules.xml
24+
profiles_settings.xml
25+
deepset-mcp-server.iml
26+
Project_Default.xml
27+
pyright-overrides.xml
28+
vcs.xml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Protocol
2+
3+
from deepset_mcp.api.custom_components.models import CustomComponentInstallationList
4+
5+
6+
class CustomComponentsProtocol(Protocol):
7+
"""Protocol defining the implementation for CustomComponentsResource."""
8+
9+
async def list_installations(
10+
self, limit: int = 20, page_number: int = 1, field: str = "created_at", order: str = "DESC"
11+
) -> CustomComponentInstallationList:
12+
"""List custom component installations."""
13+
...
14+
15+
async def get_latest_installation_logs(self) -> str | None:
16+
"""Get the logs from the latest custom component installation."""
17+
...

src/deepset_mcp/api/custom_components/resource.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any
22

33
from deepset_mcp.api.custom_components.models import CustomComponentInstallationList
4-
from deepset_mcp.api.protocols import AsyncClientProtocol, CustomComponentsProtocol
4+
from deepset_mcp.api.custom_components.protocols import CustomComponentsProtocol
5+
from deepset_mcp.api.protocols import AsyncClientProtocol
56
from deepset_mcp.api.transport import raise_for_status
67

78

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Any, Protocol
2+
3+
4+
class HaystackServiceProtocol(Protocol):
5+
"""Protocol defining the implementation for HaystackService."""
6+
7+
async def get_component_schemas(self) -> dict[str, Any]:
8+
"""Fetch the component schema from the API."""
9+
...
10+
11+
async def get_component_input_output(self, component_name: str) -> dict[str, Any]:
12+
"""Fetch input and output schema for a component from the API."""
13+
...

src/deepset_mcp/api/haystack_service/resource.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any
22

33
from deepset_mcp.api.exceptions import ResourceNotFoundError
4-
from deepset_mcp.api.protocols import AsyncClientProtocol, HaystackServiceProtocol
4+
from deepset_mcp.api.haystack_service.protocols import HaystackServiceProtocol
5+
from deepset_mcp.api.protocols import AsyncClientProtocol
56
from deepset_mcp.api.transport import raise_for_status
67

78

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from typing import Protocol
2+
3+
from deepset_mcp.api.indexes.models import Index, IndexList
4+
from deepset_mcp.api.pipeline.models import PipelineValidationResult
5+
6+
7+
class IndexResourceProtocol(Protocol):
8+
"""Protocol defining the implementation for IndexResource."""
9+
10+
async def list(self, limit: int = 10, page_number: int = 1) -> IndexList:
11+
"""List indexes in the configured workspace."""
12+
...
13+
14+
async def get(self, index_name: str) -> Index:
15+
"""Fetch a single index by its name."""
16+
...
17+
18+
async def create(self, name: str, yaml_config: str, description: str | None = None) -> Index:
19+
"""Create a new index with the given name and configuration.
20+
21+
:param name: Name of the index
22+
:param yaml_config: YAML configuration for the index
23+
:param description: Optional description for the index
24+
:returns: Created index details
25+
"""
26+
...
27+
28+
async def update(
29+
self, index_name: str, updated_index_name: str | None = None, yaml_config: str | None = None
30+
) -> Index:
31+
"""Update name and/or configuration of an existing index.
32+
33+
:param index_name: Name of the index to update
34+
:param updated_index_name: Optional new name for the index
35+
:param yaml_config: Optional new YAML configuration
36+
:returns: Updated index details
37+
"""
38+
...
39+
40+
async def deploy(self, index_name: str) -> PipelineValidationResult:
41+
"""Deploy an index to production.
42+
43+
:param index_name: Name of the index to deploy.
44+
:returns: PipelineValidationResult containing deployment status and any errors.
45+
"""
46+
...
47+
48+
async def delete(self, index_name: str) -> None:
49+
"""Delete an index.
50+
51+
:param index_name: Name of the index to delete.
52+
"""
53+
...

src/deepset_mcp/api/indexes/resource.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from deepset_mcp.api.exceptions import UnexpectedAPIError
22
from deepset_mcp.api.indexes.models import Index, IndexList
3+
from deepset_mcp.api.indexes.protocols import IndexResourceProtocol
34
from deepset_mcp.api.pipeline.models import PipelineValidationResult, ValidationError
45
from deepset_mcp.api.protocols import AsyncClientProtocol
56
from deepset_mcp.api.transport import raise_for_status
67

78

8-
class IndexResource:
9+
class IndexResource(IndexResourceProtocol):
910
"""Resource for interacting with deepset indexes."""
1011

1112
def __init__(self, client: AsyncClientProtocol, workspace: str) -> None:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from collections.abc import AsyncIterator
2+
from typing import Any, Protocol
3+
4+
from deepset_mcp.api.pipeline.log_level import LogLevel
5+
from deepset_mcp.api.pipeline.models import (
6+
DeepsetPipeline,
7+
DeepsetSearchResponse,
8+
DeepsetStreamEvent,
9+
PipelineList,
10+
PipelineLogList,
11+
PipelineValidationResult,
12+
)
13+
from deepset_mcp.api.shared_models import NoContentResponse
14+
15+
16+
class PipelineResourceProtocol(Protocol):
17+
"""Protocol defining the implementation for PipelineResource."""
18+
19+
async def validate(self, yaml_config: str) -> PipelineValidationResult:
20+
"""Validate a pipeline's YAML configuration against the API."""
21+
...
22+
23+
async def get(self, pipeline_name: str, include_yaml: bool = True) -> DeepsetPipeline:
24+
"""Fetch a single pipeline by its name."""
25+
...
26+
27+
async def list(
28+
self,
29+
page_number: int = 1,
30+
limit: int = 10,
31+
) -> PipelineList:
32+
"""List pipelines in the configured workspace with optional pagination."""
33+
...
34+
35+
async def create(self, name: str, yaml_config: str) -> NoContentResponse:
36+
"""Create a new pipeline with a name and YAML config."""
37+
...
38+
39+
async def update(
40+
self,
41+
pipeline_name: str,
42+
updated_pipeline_name: str | None = None,
43+
yaml_config: str | None = None,
44+
) -> NoContentResponse:
45+
"""Update name and/or YAML config of an existing pipeline."""
46+
...
47+
48+
async def get_logs(
49+
self,
50+
pipeline_name: str,
51+
limit: int = 30,
52+
level: LogLevel | None = None,
53+
) -> PipelineLogList:
54+
"""Fetch logs for a specific pipeline."""
55+
...
56+
57+
async def deploy(self, pipeline_name: str) -> PipelineValidationResult:
58+
"""Deploy a pipeline."""
59+
...
60+
61+
async def search(
62+
self,
63+
pipeline_name: str,
64+
query: str,
65+
debug: bool = False,
66+
view_prompts: bool = False,
67+
params: dict[str, Any] | None = None,
68+
filters: dict[str, Any] | None = None,
69+
) -> DeepsetSearchResponse:
70+
"""Search using a pipeline."""
71+
...
72+
73+
def search_stream(
74+
self,
75+
pipeline_name: str,
76+
query: str,
77+
debug: bool = False,
78+
view_prompts: bool = False,
79+
params: dict[str, Any] | None = None,
80+
filters: dict[str, Any] | None = None,
81+
) -> AsyncIterator[DeepsetStreamEvent]:
82+
"""Search using a pipeline with response streaming."""
83+
...

src/deepset_mcp/api/pipeline/resource.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PipelineValidationResult,
1515
ValidationError,
1616
)
17+
from deepset_mcp.api.pipeline.protocols import PipelineResourceProtocol
1718
from deepset_mcp.api.shared_models import NoContentResponse
1819
from deepset_mcp.api.transport import raise_for_status
1920

@@ -23,7 +24,7 @@
2324
from deepset_mcp.api.protocols import AsyncClientProtocol
2425

2526

26-
class PipelineResource:
27+
class PipelineResource(PipelineResourceProtocol):
2728
"""Manages interactions with the deepset pipeline API."""
2829

2930
def __init__(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Protocol
2+
3+
from deepset_mcp.api.pipeline_template.models import PipelineTemplate, PipelineTemplateList
4+
5+
6+
class PipelineTemplateResourceProtocol(Protocol):
7+
"""Protocol defining the implementation for PipelineTemplateResource."""
8+
9+
async def get_template(self, template_name: str) -> PipelineTemplate:
10+
"""Fetch a single pipeline template by its name."""
11+
...
12+
13+
async def list_templates(
14+
self, limit: int = 100, field: str = "created_at", order: str = "DESC", filter: str | None = None
15+
) -> PipelineTemplateList:
16+
"""List pipeline templates in the configured workspace."""
17+
...

0 commit comments

Comments
 (0)