Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The fetch tool will truncate the response, but by using the `start_index` argume

- `fetch` - Fetches a URL from the internet and extracts its contents as markdown.
- `url` (string, required): URL to fetch
- `max_length` (integer, optional): Maximum number of characters to return (default: 5000)
- `max_length` (integer, optional): Maximum number of characters to return (default: 5000). This can be overridden (see customization below)
- `start_index` (integer, optional): Start content from this character index (default: 0)
- `raw` (boolean, optional): Get raw content without markdown conversion (default: false)

Expand Down Expand Up @@ -168,6 +168,39 @@ This can be customized by adding the argument `--user-agent=YourUserAgent` to th

The server can be configured to use a proxy by using the `--proxy-url` argument.

### Customization - Max Length

By default, the maximum length of content returned is 5000 characters. This can be customized by setting the `MAX_LENGTH` environment variable.

<details>
<summary>Using uvx</summary>

```json
"mcpServers": {
"fetch": {
"command": "uvx",
"args": ["mcp-server-fetch"],
"env": {
"MAX_LENGTH": "10000"
}
}
}
```
</details>

<details>
<summary>Using Docker</summary>

```json
"mcpServers": {
"fetch": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "MAX_LENGTH=10000", "mcp/fetch"]
}
}
```
</details>

## Debugging

You can use the MCP inspector to debug the server. For uvx installations:
Expand Down
4 changes: 3 additions & 1 deletion src/fetch/src/mcp_server_fetch/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Annotated, Tuple
from urllib.parse import urlparse, urlunparse
import os

import markdownify
import readabilipy.simple_json
Expand All @@ -22,6 +23,7 @@

DEFAULT_USER_AGENT_AUTONOMOUS = "ModelContextProtocol/1.0 (Autonomous; +https://github.com/modelcontextprotocol/servers)"
DEFAULT_USER_AGENT_MANUAL = "ModelContextProtocol/1.0 (User-Specified; +https://github.com/modelcontextprotocol/servers)"
MAX_LENGTH = os.environ.get("MAX_LENGTH", 5000)


def extract_content_from_html(html: str) -> str:
Expand Down Expand Up @@ -155,7 +157,7 @@ class Fetch(BaseModel):
max_length: Annotated[
int,
Field(
default=5000,
default=MAX_LENGTH,
description="Maximum number of characters to return.",
gt=0,
lt=1000000,
Expand Down