diff --git a/src/fetch/README.md b/src/fetch/README.md
index 5324e50731..198ce6937c 100644
--- a/src/fetch/README.md
+++ b/src/fetch/README.md
@@ -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)
@@ -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.
+
+
+Using uvx
+
+```json
+"mcpServers": {
+ "fetch": {
+ "command": "uvx",
+ "args": ["mcp-server-fetch"],
+ "env": {
+ "MAX_LENGTH": "10000"
+ }
+ }
+}
+```
+
+
+
+Using Docker
+
+```json
+"mcpServers": {
+ "fetch": {
+ "command": "docker",
+ "args": ["run", "-i", "--rm", "-e", "MAX_LENGTH=10000", "mcp/fetch"]
+ }
+}
+```
+
+
## Debugging
You can use the MCP inspector to debug the server. For uvx installations:
diff --git a/src/fetch/src/mcp_server_fetch/server.py b/src/fetch/src/mcp_server_fetch/server.py
index 2df9d3b604..627e5e1d33 100644
--- a/src/fetch/src/mcp_server_fetch/server.py
+++ b/src/fetch/src/mcp_server_fetch/server.py
@@ -1,5 +1,6 @@
from typing import Annotated, Tuple
from urllib.parse import urlparse, urlunparse
+import os
import markdownify
import readabilipy.simple_json
@@ -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:
@@ -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,