[v1.x] Follow redirects only within the MCP endpoint's origin (#3448)
This commit is contained in:
parent
3eed7ce0a6
commit
2106335745
1 changed files with 948 additions and 192 deletions
|
|
@ -2,9 +2,9 @@ from typing import Any
|
|||
|
||||
import anyio
|
||||
import click
|
||||
import httpx
|
||||
import mcp.types as types
|
||||
from mcp.server.lowlevel import Server
|
||||
from mcp.shared._httpx_utils import create_mcp_http_client
|
||||
from starlette.requests import Request
|
||||
|
||||
|
||||
|
|
@ -12,7 +12,8 @@ async def fetch_website(
|
|||
url: str,
|
||||
) -> list[types.ContentBlock]:
|
||||
headers = {"User-Agent": "MCP Test Server (github.com/modelcontextprotocol/python-sdk)"}
|
||||
async with create_mcp_http_client(headers=headers) as client:
|
||||
timeout = httpx.Timeout(30, read=300)
|
||||
async with httpx.AsyncClient(headers=headers, timeout=timeout, follow_redirects=True) as client:
|
||||
response = await client.get(url)
|
||||
response.raise_for_status()
|
||||
return [types.TextContent(type="text", text=response.text)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue