|
1 | | -from typing import Optional, Tuple |
| 1 | +from typing import Annotated, Tuple |
2 | 2 | from urllib.parse import urlparse, urlunparse |
3 | 3 |
|
4 | 4 | import markdownify |
|
17 | 17 | INTERNAL_ERROR, |
18 | 18 | ) |
19 | 19 | from protego import Protego |
20 | | -from pydantic import BaseModel, Field, AnyUrl, conint |
| 20 | +from pydantic import BaseModel, Field, AnyUrl |
21 | 21 |
|
22 | 22 | DEFAULT_USER_AGENT_AUTONOMOUS = "ModelContextProtocol/1.0 (Autonomous; +https://github.com/modelcontextprotocol/servers)" |
23 | 23 | DEFAULT_USER_AGENT_MANUAL = "ModelContextProtocol/1.0 (User-Specified; +https://github.com/modelcontextprotocol/servers)" |
@@ -148,22 +148,35 @@ async def fetch_url( |
148 | 148 | class Fetch(BaseModel): |
149 | 149 | """Parameters for fetching a URL.""" |
150 | 150 |
|
151 | | - url: AnyUrl = Field(..., description="URL to fetch") |
152 | | - max_length: conint(gt=0, lt=1000000) = Field( |
153 | | - 5000, description="Maximum number of characters to return." |
154 | | - ) |
155 | | - start_index: conint(ge=0) = Field( |
156 | | - 0, |
157 | | - description="On return output starting at this character index, useful if a previous fetch was truncated and more context is required.", |
158 | | - ) |
159 | | - raw: bool = Field( |
160 | | - False, |
161 | | - description="Get the actual HTML content if the requested page, without simplification.", |
162 | | - ) |
| 151 | + url: Annotated[AnyUrl, Field(description="URL to fetch")] |
| 152 | + max_length: Annotated[ |
| 153 | + int, |
| 154 | + Field( |
| 155 | + default=5000, |
| 156 | + description="Maximum number of characters to return.", |
| 157 | + gt=0, |
| 158 | + lt=1000000, |
| 159 | + ), |
| 160 | + ] |
| 161 | + start_index: Annotated[ |
| 162 | + int, |
| 163 | + Field( |
| 164 | + default=0, |
| 165 | + description="On return output starting at this character index, useful if a previous fetch was truncated and more context is required.", |
| 166 | + ge=0, |
| 167 | + ), |
| 168 | + ] |
| 169 | + raw: Annotated[ |
| 170 | + bool, |
| 171 | + Field( |
| 172 | + default=False, |
| 173 | + description="Get the actual HTML content if the requested page, without simplification.", |
| 174 | + ), |
| 175 | + ] |
163 | 176 |
|
164 | 177 |
|
165 | 178 | async def serve( |
166 | | - custom_user_agent: Optional[str] = None, ignore_robots_txt: bool = False |
| 179 | + custom_user_agent: str | None = None, ignore_robots_txt: bool = False |
167 | 180 | ) -> None: |
168 | 181 | """Run the fetch MCP server. |
169 | 182 |
|
|
0 commit comments