Skip to content

Commit 4642773

Browse files
committed
feat: wrapup haystack service; update test structure
1 parent 7a8a969 commit 4642773

20 files changed

Lines changed: 277 additions & 265 deletions

src/deepset_mcp/api/haystack_service/__init__.py

Whitespace-only changes.

src/deepset_mcp/api/haystack_service/models.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/deepset_mcp/api/haystack_service/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, client: AsyncClientProtocol) -> None:
1111
"""Initializes a HaystackServiceResource instance."""
1212
self._client = client
1313

14-
async def get_component_schema(self) -> dict[str, Any]:
14+
async def get_component_schemas(self) -> dict[str, Any]:
1515
"""Fetch the component schema from the API.
1616
1717
Returns:

src/deepset_mcp/api/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class HaystackServiceProtocol(Protocol):
99
"""Protocol defining the implementation for HaystackService."""
1010

11-
async def get_component_schema(self) -> dict[str, Any]:
11+
async def get_component_schemas(self) -> dict[str, Any]:
1212
"""Fetch the component schema from the API."""
1313
...
1414

src/deepset_mcp/main.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import Any
23

34
from mcp.server.fastmcp import FastMCP
45

@@ -86,20 +87,16 @@ async def update_pipeline(
8687
return response
8788

8889

89-
#
90-
#
91-
# @mcp.tool()
92-
# async def get_component_schemas() -> Any:
93-
# """Retrieves the schemas for all available Haystack components from the deepset API.
94-
#
95-
# These schemas define the expected input and output parameters for each component type, which is useful for
96-
# constructing or validating componets in a pipeline YAML.
97-
# """
98-
# async with AsyncDeepsetClient() as client:
99-
# response = await client.request(endpoint="v1/haystack/components", method="GET")
100-
# return response.json
101-
#
102-
#
90+
@mcp.tool()
91+
async def get_component_schemas() -> Any:
92+
"""Retrieves the schemas for all available Haystack components from the deepset API.
93+
94+
These schemas define the expected input and output parameters for each component type, which is useful for
95+
constructing or validating componets in a pipeline YAML.
96+
"""
97+
async with AsyncDeepsetClient() as client:
98+
response = await client.request(endpoint="v1/haystack/components", method="GET")
99+
return response.json
103100

104101

105102
@mcp.tool()

test/__init__.py

Whitespace-only changes.

test/integration/__init__.py

Whitespace-only changes.

test/integration/conftest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import uuid
3+
from collections.abc import AsyncGenerator
4+
from datetime import datetime
5+
6+
import pytest
7+
from dotenv import load_dotenv
8+
9+
from deepset_mcp.api.client import AsyncDeepsetClient
10+
11+
load_dotenv()
12+
13+
14+
@pytest.fixture
15+
def test_workspace_name() -> str:
16+
"""Create a unique workspace name for testing."""
17+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
18+
return f"test-workspace-{timestamp}-{uuid.uuid4().hex[:8]}"
19+
20+
21+
@pytest.fixture
22+
async def client() -> AsyncGenerator[AsyncDeepsetClient, None]:
23+
"""Create and configure the deepset client."""
24+
api_key = os.environ.get("DEEPSET_API_KEY")
25+
if not api_key:
26+
pytest.skip("DEEPSET_API_KEY environment variable not set")
27+
28+
async with AsyncDeepsetClient(api_key=api_key) as client:
29+
yield client
30+
31+
32+
@pytest.fixture
33+
async def test_workspace(
34+
client: AsyncDeepsetClient,
35+
test_workspace_name: str,
36+
) -> AsyncGenerator[str, None]:
37+
"""Create a test workspace and clean it up after tests."""
38+
# Create a test workspace
39+
await client.request(
40+
endpoint="v1/workspaces",
41+
method="POST",
42+
data={"name": test_workspace_name},
43+
)
44+
45+
yield test_workspace_name
46+
47+
# Clean up the workspace after tests
48+
try:
49+
await client.request(
50+
endpoint=f"v1/workspaces/{test_workspace_name}",
51+
method="DELETE",
52+
)
53+
except Exception as e:
54+
print(f"Failed to delete test workspace: {e}")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from deepset_mcp.api.client import AsyncDeepsetClient
4+
from deepset_mcp.api.haystack_service.resource import HaystackServiceResource
5+
6+
pytestmark = pytest.mark.integration
7+
8+
9+
@pytest.fixture
10+
async def haystack_service_resource(
11+
client: AsyncDeepsetClient,
12+
) -> HaystackServiceResource:
13+
"""Create a PipelineResource instance for testing."""
14+
return HaystackServiceResource(client=client)
15+
16+
17+
@pytest.mark.asyncio
18+
async def test_get_component_schemas(
19+
haystack_service_resource: HaystackServiceResource,
20+
) -> None:
21+
"""Test for getting component schemas."""
22+
response = await haystack_service_resource.get_component_schemas()
23+
24+
assert isinstance(response, dict)
25+
assert "component_schema" in response

test/integration/test_integration_pipeline_resource.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,11 @@
1-
import os
2-
import uuid
3-
from collections.abc import AsyncGenerator
4-
from datetime import datetime
5-
61
import pytest
7-
from dotenv import load_dotenv
82

93
from deepset_mcp.api.client import AsyncDeepsetClient
104
from deepset_mcp.api.exceptions import ResourceNotFoundError
115
from deepset_mcp.api.pipeline.models import DeepsetPipeline
126
from deepset_mcp.api.pipeline.resource import PipelineResource
137

148
pytestmark = pytest.mark.integration
15-
load_dotenv()
16-
17-
18-
@pytest.fixture
19-
def test_workspace_name() -> str:
20-
"""Create a unique workspace name for testing."""
21-
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
22-
return f"test-workspace-{timestamp}-{uuid.uuid4().hex[:8]}"
23-
24-
25-
@pytest.fixture
26-
async def client() -> AsyncGenerator[AsyncDeepsetClient, None]:
27-
"""Create and configure the deepset client."""
28-
api_key = os.environ.get("DEEPSET_API_KEY")
29-
if not api_key:
30-
pytest.skip("DEEPSET_API_KEY environment variable not set")
31-
32-
async with AsyncDeepsetClient(api_key=api_key) as client:
33-
yield client
34-
35-
36-
@pytest.fixture
37-
async def test_workspace(
38-
client: AsyncDeepsetClient,
39-
test_workspace_name: str,
40-
) -> AsyncGenerator[str, None]:
41-
"""Create a test workspace and clean it up after tests."""
42-
# Create a test workspace
43-
await client.request(
44-
endpoint="v1/workspaces",
45-
method="POST",
46-
data={"name": test_workspace_name},
47-
)
48-
49-
yield test_workspace_name
50-
51-
# Clean up the workspace after tests
52-
try:
53-
await client.request(
54-
endpoint=f"v1/workspaces/{test_workspace_name}",
55-
method="DELETE",
56-
)
57-
except Exception as e:
58-
print(f"Failed to delete test workspace: {e}")
599

6010

6111
@pytest.fixture

0 commit comments

Comments
 (0)