Follow redirects only within the MCP endpoint's origin (#3397)
This commit is contained in:
parent
5fd3abc548
commit
c6762e821c
1 changed files with 1029 additions and 205 deletions
|
|
@ -1,15 +1,16 @@
|
|||
import anyio
|
||||
import click
|
||||
import httpx2
|
||||
import mcp.types as types
|
||||
from mcp.server import Server, ServerRequestContext
|
||||
from mcp.shared._httpx_utils import create_mcp_http_client
|
||||
|
||||
|
||||
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 = httpx2.Timeout(30, read=300)
|
||||
async with httpx2.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