Skip to content

Commit 26d0503

Browse files
committed
fix(fetch): use inclusive minimum/maximum instead of exclusive bounds in schema
The Fetch model used gt=0 and lt=1000000 Pydantic constraints on max_length, which generates exclusiveMinimum/exclusiveMaximum in the JSON Schema. Some LLM providers (e.g. Google Gemini 2.5) only support OpenAPI 3.0 schema keywords and reject these with a 400 error. Switch to ge=1 / le=999999 (identical semantics for integers) so Pydantic emits the universally supported minimum/maximum keywords instead. Fixes #1624 Made-with: Cursor
1 parent f424458 commit 26d0503

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/fetch/src/mcp_server_fetch/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class Fetch(BaseModel):
157157
Field(
158158
default=5000,
159159
description="Maximum number of characters to return.",
160-
gt=0,
161-
lt=1000000,
160+
ge=1,
161+
le=999999,
162162
),
163163
]
164164
start_index: Annotated[

src/fetch/tests/test_server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from mcp.shared.exceptions import McpError
66

77
from mcp_server_fetch.server import (
8+
Fetch,
89
extract_content_from_html,
910
get_robots_txt_url,
1011
check_may_autonomously_fetch_url,
@@ -13,6 +14,24 @@
1314
)
1415

1516

17+
class TestFetchToolSchema:
18+
"""Tests for the Fetch model JSON schema compatibility."""
19+
20+
def test_schema_uses_inclusive_bounds(self):
21+
"""Ensure the schema uses minimum/maximum instead of exclusiveMinimum/exclusiveMaximum.
22+
23+
Some LLM providers (e.g. Google Gemini) only support OpenAPI 3.0
24+
schema keywords and reject exclusiveMinimum/exclusiveMaximum.
25+
"""
26+
schema = Fetch.model_json_schema()
27+
max_length_schema = schema["properties"]["max_length"]
28+
29+
assert "exclusiveMinimum" not in max_length_schema
30+
assert "exclusiveMaximum" not in max_length_schema
31+
assert max_length_schema["minimum"] == 1
32+
assert max_length_schema["maximum"] == 999999
33+
34+
1635
class TestGetRobotsTxtUrl:
1736
"""Tests for get_robots_txt_url function."""
1837

0 commit comments

Comments
 (0)