Introduce a function to create a standard AsyncClient with options (#655)
Some checks failed
Main branch checks / checks (push) Has been cancelled
Some checks failed
Main branch checks / checks (push) Has been cancelled
This commit is contained in:
parent
72003d9cc0
commit
ed25167fa5
2 changed files with 95 additions and 8 deletions
|
|
@ -6,7 +6,6 @@ import time
|
|||
from typing import Any
|
||||
|
||||
import click
|
||||
import httpx
|
||||
from pydantic import AnyHttpUrl
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from starlette.exceptions import HTTPException
|
||||
|
|
@ -24,6 +23,7 @@ from mcp.server.auth.provider import (
|
|||
)
|
||||
from mcp.server.auth.settings import AuthSettings, ClientRegistrationOptions
|
||||
from mcp.server.fastmcp.server import FastMCP
|
||||
from mcp.shared._httpx_utils import create_mcp_http_client
|
||||
from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -123,7 +123,7 @@ class SimpleGitHubOAuthProvider(OAuthAuthorizationServerProvider):
|
|||
client_id = state_data["client_id"]
|
||||
|
||||
# Exchange code for token with GitHub
|
||||
async with httpx.AsyncClient() as client:
|
||||
async with create_mcp_http_client() as client:
|
||||
response = await client.post(
|
||||
self.settings.github_token_url,
|
||||
data={
|
||||
|
|
@ -325,7 +325,7 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
|
|||
"""
|
||||
github_token = get_github_token()
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
async with create_mcp_http_client() as client:
|
||||
response = await client.get(
|
||||
"https://api.github.com/user",
|
||||
headers={
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
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
|
||||
|
||||
|
||||
async def fetch_website(
|
||||
|
|
@ -11,7 +11,7 @@ async def fetch_website(
|
|||
headers = {
|
||||
"User-Agent": "MCP Test Server (github.com/modelcontextprotocol/python-sdk)"
|
||||
}
|
||||
async with httpx.AsyncClient(follow_redirects=True, headers=headers) as client:
|
||||
async with create_mcp_http_client(headers=headers) 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