Skip to content

Commit 14e4107

Browse files
committed
test(fetch): add runtime validation tests for url field
Verifies that AnyUrl runtime validation is preserved after the WithJsonSchema override — invalid URLs still raise ValidationError, valid URLs parse successfully. Addresses review feedback on #3812.
1 parent 342a223 commit 14e4107

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/fetch/tests/test_server.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from unittest.mock import AsyncMock, patch, MagicMock
55
from mcp.shared.exceptions import McpError
6+
from pydantic import ValidationError
67

78
from mcp_server_fetch.server import (
89
Fetch,
@@ -45,6 +46,20 @@ def test_url_schema_omits_unsupported_keywords(self):
4546
assert "minLength" not in url_schema
4647
assert url_schema["type"] == "string"
4748

49+
def test_url_runtime_validation_still_rejects_invalid_urls(self):
50+
"""Ensure AnyUrl runtime validation is preserved after the WithJsonSchema override.
51+
52+
The override only simplifies the emitted JSON schema; invalid URLs
53+
must still be rejected at parse time with a ValidationError.
54+
"""
55+
with pytest.raises(ValidationError):
56+
Fetch(url="not-a-url")
57+
58+
def test_url_runtime_validation_accepts_valid_urls(self):
59+
"""Ensure valid URLs still parse successfully after the WithJsonSchema override."""
60+
fetch = Fetch(url="https://example.com/page")
61+
assert str(fetch.url) == "https://example.com/page"
62+
4863

4964
class TestGetRobotsTxtUrl:
5065
"""Tests for get_robots_txt_url function."""

0 commit comments

Comments
 (0)