Skip to content

Commit 11bd9c8

Browse files
authored
Merge pull request #5017 from modelcontextprotocol/v2/fix/1624-fetch-schema-bounds
fix(fetch): emit inclusive minimum/maximum for max_length (#1624)
2 parents ba61613 + 62407ee commit 11bd9c8

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎src/fetch/src/mcp_server_fetch/server.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ class Fetch(BaseModel):
175175
Field(
176176
default=5000,
177177
description="Maximum number of characters to return.",
178-
gt=0,
179-
lt=1000000,
178+
# ge/le rather than gt/lt: the inclusive bounds emit minimum/maximum,
179+
# which every client accepts, while exclusiveMinimum/exclusiveMaximum
180+
# are rejected by some (Gemini, #1624). Same range for an int.
181+
ge=1,
182+
le=999999,
180183
),
181184
]
182185
start_index: Annotated[

‎src/fetch/tests/test_protocol.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ async def test_server_version_is_the_package_version(web: FakeWeb) -> None:
106106
# --------------------------------------------------------------------------
107107

108108

109-
# KNOWN BUG #1624: pins current (wrong) behavior; the fix changes this assertion.
110109
async def test_list_tools_wire_shape(web: FakeWeb) -> None:
111110
async with connect() as (session, _):
112111
result = await session.list_tools()
@@ -128,13 +127,13 @@ async def test_list_tools_wire_shape(web: FakeWeb) -> None:
128127
"title": "Url",
129128
"type": "string",
130129
},
131-
# #1624: pydantic's gt/lt emit the numeric (draft 6+) form of
132-
# exclusiveMinimum/exclusiveMaximum, which some clients reject.
130+
# #1624: inclusive minimum/maximum, never exclusiveMinimum/
131+
# exclusiveMaximum, which some clients (Gemini) reject.
133132
"max_length": {
134133
"default": 5000,
135134
"description": "Maximum number of characters to return.",
136-
"exclusiveMaximum": 1000000,
137-
"exclusiveMinimum": 0,
135+
"maximum": 999999,
136+
"minimum": 1,
138137
"title": "Max Length",
139138
"type": "integer",
140139
},
@@ -183,7 +182,8 @@ async def test_call_with_only_url_applies_defaults(web: FakeWeb) -> None:
183182
({}, "'url'"),
184183
({"url": ""}, "''"),
185184
({"url": 5}, "5"),
186-
# #1624: the bounds come from exclusiveMinimum/exclusiveMaximum.
185+
# #1624: the bounds are minimum 1 and maximum 999999, so the rejected
186+
# values are the same as under the old exclusive 0 and 1000000.
187187
({"url": PAGE, "max_length": 0}, "0"),
188188
({"url": PAGE, "max_length": 1000000}, "1000000"),
189189
({"url": PAGE, "start_index": -1}, "-1"),
@@ -204,6 +204,18 @@ async def test_schema_violations_are_rejected_by_the_sdk(
204204
assert web.requests == []
205205

206206

207+
@pytest.mark.parametrize("max_length", [1, 999999])
208+
async def test_max_length_bounds_are_inclusive(web: FakeWeb, max_length: int) -> None:
209+
# #1624: the edges of the inclusive range pass both the SDK's schema check
210+
# and Fetch's own validation, and the page is fetched.
211+
web.add(ROBOTS, plain("", status=404))
212+
web.add(PAGE, plain("hello"))
213+
async with connect() as (session, _):
214+
result = await call(session, {"url": PAGE, "max_length": max_length})
215+
assert wire(result)["isError"] is False
216+
assert web.urls() == [ROBOTS, PAGE]
217+
218+
207219
@pytest.mark.parametrize("url", ["not a url", "example.com/page", "http://"])
208220
async def test_invalid_url_is_rejected_by_pydantic(web: FakeWeb, url: str) -> None:
209221
# jsonschema does not check `format: uri`, so these reach Fetch(**arguments)

0 commit comments

Comments
 (0)