Skip to content

Commit 8243ca5

Browse files
Add tests, small refactor (#21)
1 parent c82bcf9 commit 8243ca5

File tree

8 files changed

+94
-47
lines changed

8 files changed

+94
-47
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ ipython_config.py
7070
__pypackages__/
7171

7272
# Environments
73-
*/.env
73+
.env
74+
tests/e2e/.env
7475
.venv
7576
env/
7677
venv/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [0.2.1] - 2025-05-23
4+
5+
### Added
6+
7+
- More tests
8+
9+
### Changed
10+
11+
- README.md
12+
313
## [0.2.0] - 2025-05-13
414

515
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "oxylabs-mcp"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Oxylabs MCP server"
55
authors = [
66
{name="Augis Braziunas", email="[email protected]"},

src/oxylabs_mcp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from . import server
1+
from oxylabs_mcp.server import mcp
22

33

44
def main() -> None:
55
"""Start the MCP server."""
6-
server.main()
6+
mcp.run()
77

88

99
# Optionally expose other important items at package level

src/oxylabs_mcp/server.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,5 @@ async def amazon_product_scraper(
222222
return e.stringify()
223223

224224

225-
def main() -> None:
226-
"""Run the MCP server."""
227-
mcp.run()
228-
229-
230225
if __name__ == "__main__":
231-
main()
226+
mcp.run()

src/oxylabs_mcp/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ def get_content(response: Response, *, output_format: str, parse: bool = False)
218218
if output_format == "links":
219219
links = extract_links_with_text(str(content))
220220
return "\n".join(links)
221-
if output_format in ("md", ""):
222-
striped_html = strip_html(str(content))
223-
return markdownify(striped_html) # type: ignore[no-any-return]
224221

225-
return str(content)
222+
stripped_html = strip_html(str(content))
223+
return markdownify(stripped_html) # type: ignore[no-any-return]

tests/integration/test_server.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
7-
from httpx import Request, Response
7+
from httpx import HTTPStatusError, Request, RequestError, Response
88
from mcp.server.fastmcp import FastMCP
99
from mcp.types import TextContent
1010

@@ -282,3 +282,74 @@ async def test_default_headers_are_set(
282282

283283
client_info_pattern = re.compile(r"oxylabs-mcp-fake_cursor/(\d+)\.(\d+)\.(\d+)$")
284284
assert re.match(client_info_pattern, client_info)
285+
286+
287+
@pytest.mark.asyncio
288+
@pytest.mark.parametrize(
289+
("tool", "arguments"),
290+
[
291+
pytest.param(
292+
"universal_scraper",
293+
{"url": "test_url"},
294+
id="universal_scraper",
295+
),
296+
pytest.param(
297+
"google_search_scraper",
298+
{"query": "Generic query"},
299+
id="google_search_scraper",
300+
),
301+
pytest.param(
302+
"amazon_search_scraper",
303+
{"query": "Generic query"},
304+
id="amazon_search_scraper",
305+
),
306+
pytest.param(
307+
"amazon_product_scraper",
308+
{"query": "Generic query"},
309+
id="amazon_product_scraper",
310+
),
311+
],
312+
)
313+
@pytest.mark.parametrize(
314+
("exception", "expected_text"),
315+
[
316+
pytest.param(
317+
HTTPStatusError(
318+
"HTTP status error",
319+
request=MagicMock(),
320+
response=MagicMock(status_code=500, text="Internal Server Error"),
321+
),
322+
"HTTP error during POST request: 500 - Internal Server Error",
323+
id="https_status_error",
324+
),
325+
pytest.param(
326+
RequestError("Request error"),
327+
"Request error during POST request: Request error",
328+
id="request_error",
329+
),
330+
pytest.param(
331+
Exception("Unexpected exception"),
332+
"Error: Unexpected exception",
333+
id="unhandled_exception",
334+
),
335+
],
336+
)
337+
async def test_request_client_error_handling(
338+
mcp: FastMCP,
339+
request_data: Request,
340+
oxylabs_client: AsyncMock,
341+
request_session: MagicMock,
342+
tool: str,
343+
arguments: dict,
344+
exception: Exception,
345+
expected_text: str,
346+
):
347+
request_session.client_params.clientInfo.name = "fake_cursor"
348+
349+
oxylabs_client.post.side_effect = [exception]
350+
oxylabs_client.get.side_effect = [exception]
351+
352+
with patch("os.environ", new=ENV_VARIABLES):
353+
result = await mcp.call_tool(tool, arguments=arguments)
354+
355+
assert result[0].text == expected_text

uv.lock

Lines changed: 4 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)