Skip to content

Commit 77d78e7

Browse files
committed
chore: migrate to application structure
1 parent 3ca088b commit 77d78e7

6 files changed

Lines changed: 83 additions & 20 deletions

File tree

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ COPY pyproject.toml uv.lock .
1414
RUN uv sync
1515

1616
# Copy the rest of the application code
17-
COPY main.py .
17+
COPY src .
1818

1919
# Make port 8000 available to the world outside this container
2020
# Assuming FastMCP runs on port 8000 by default (common for FastAPI/Uvicorn)
@@ -27,10 +27,4 @@ ENV DEEPSET_WORKSPACE=""
2727
# Set PYTHONUNBUFFERED to ensure logs are output immediately
2828
ENV PYTHONUNBUFFERED=1
2929

30-
# Run main.py using uv when the container launches
31-
# Assumes main.py calls mcp.run(host="0.0.0.0", port=8000)
32-
CMD ["uv", "run", "mcp", "run", "main.py"]
33-
34-
# Alternative CMD if main.py directly runs the server using mcp.run()
35-
# CMD ["python", "main.py"]
36-
# Note: If using 'python main.py', ensure mcp.run() binds to 0.0.0.0
30+
CMD ["uv", "run", "deepset-mcp"]

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,20 @@ dependencies = [
1010
"requests>=2.32.3",
1111
"uvicorn>=0.34.2",
1212
]
13+
14+
[project.scripts]
15+
deepset-mcp = "deepset_mcp.main:launch_mcp"
16+
17+
[build-system]
18+
requires = ["hatchling"]
19+
build-backend = "hatchling.build"
20+
21+
[dependency-groups]
22+
dev = [
23+
"pytest"
24+
]
25+
26+
[tool.pytest.ini_options]
27+
testpaths = ["test"]
28+
29+

src/deepset_mcp/__init__.py

Whitespace-only changes.

main.py renamed to src/deepset_mcp/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,9 @@ def list_custom_component_installations() -> str:
539539
except Exception as e:
540540
return f"Error retrieving custom component installations: {str(e)}"
541541

542+
543+
def launch_mcp() -> None:
544+
mcp.run()
545+
542546
if __name__ == "__main__":
543-
# Using the built-in server runner
544-
# Ensure it binds to 0.0.0.0 to be accessible in Docker
545-
mcp.run()
547+
launch_mcp()

test_main.py renamed to test/test_main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
# Assuming your main code is in main.py
7-
from main import update_pipeline_yaml, DEEPSET_API_BASE_URL
7+
from deepset_mcp.main import update_pipeline_yaml, DEEPSET_API_BASE_URL
88

99
# --- Test Data ---
1010
TEST_WORKSPACE = "test-workspace"
@@ -42,7 +42,7 @@ def create_mock_response(status_code, json_data=None, text_data=None):
4242
# --- Test Cases ---
4343

4444
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
45-
@mock.patch('main.requests.put') # Mock requests.put used in update_pipeline_yaml
45+
@mock.patch('deepset_mcp.main.requests.put') # Mock requests.put used in update_pipeline_yaml
4646
def test_update_pipeline_yaml_success_json_response(mock_put):
4747
"""Tests successful update with JSON response."""
4848
mock_response = create_mock_response(200, json_data={"status": "success", "message": "Updated"})
@@ -64,7 +64,7 @@ def test_update_pipeline_yaml_success_json_response(mock_put):
6464
assert result == {"status": "success", "message": "Updated"}
6565

6666
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
67-
@mock.patch('main.requests.put')
67+
@mock.patch('deepset_mcp.main.requests.put')
6868
def test_update_pipeline_yaml_success_empty_response(mock_put):
6969
"""Tests successful update with empty response body."""
7070
mock_response = create_mock_response(200, text_data="") # Empty body
@@ -78,7 +78,7 @@ def test_update_pipeline_yaml_success_empty_response(mock_put):
7878
assert result == {"status": "success", "message": "Pipeline YAML updated successfully (empty response body)"}
7979

8080
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
81-
@mock.patch('main.requests.put')
81+
@mock.patch('deepset_mcp.main.requests.put')
8282
def test_update_pipeline_yaml_api_error_422_json(mock_put):
8383
"""Tests API error (422) with JSON details."""
8484
error_details = {"detail": [{"type": "validation_error", "msg": "Something is wrong"}]}
@@ -94,7 +94,7 @@ def test_update_pipeline_yaml_api_error_422_json(mock_put):
9494
}
9595

9696
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
97-
@mock.patch('main.requests.put')
97+
@mock.patch('deepset_mcp.main.requests.put')
9898
def test_update_pipeline_yaml_api_error_500_text(mock_put):
9999
"""Tests API error (500) with non-JSON text details."""
100100
error_text = "Internal Server Error"
@@ -110,7 +110,7 @@ def test_update_pipeline_yaml_api_error_500_text(mock_put):
110110
}
111111

112112
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
113-
@mock.patch('main.requests.put')
113+
@mock.patch('deepset_mcp.main.requests.put')
114114
def test_update_pipeline_yaml_request_exception(mock_put):
115115
"""Tests network request failure."""
116116
mock_put.side_effect = requests.exceptions.RequestException("Connection timed out")
@@ -122,15 +122,15 @@ def test_update_pipeline_yaml_request_exception(mock_put):
122122
assert "Request failed: Connection timed out" in result["error"]
123123

124124
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
125-
@mock.patch('main.requests.put') # Still need to mock put, even if not called
125+
@mock.patch('deepset_mcp.main.requests.put') # Still need to mock put, even if not called
126126
def test_update_pipeline_yaml_empty_content(mock_put):
127127
"""Tests the function's validation for empty YAML content."""
128128
result = update_pipeline_yaml(TEST_PIPELINE_NAME, "")
129129
assert result == {"error": "Empty YAML content provided"}
130130
mock_put.assert_not_called() # Ensure API wasn't called
131131

132132
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
133-
@mock.patch('main.requests.put')
133+
@mock.patch('deepset_mcp.main.requests.put')
134134
def test_update_pipeline_yaml_invalid_structure(mock_put):
135135
"""Tests the function's validation for missing 'components:'."""
136136
result = update_pipeline_yaml(TEST_PIPELINE_NAME, INVALID_YAML_CONTENT_NO_COMPONENTS)

uv.lock

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)