Merge pull request #6 from modelcontextprotocol/ken/headers

Add header support for sse_client
This commit is contained in:
Kenneth Lien
2024-09-30 14:36:10 -07:00
committed by GitHub
2 changed files with 4 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import logging
from contextlib import asynccontextmanager
from typing import Any
from urllib.parse import urljoin, urlparse
import anyio
@@ -18,7 +19,7 @@ def remove_request_params(url: str) -> str:
@asynccontextmanager
async def sse_client(url: str, timeout: float = 5, sse_read_timeout: float = 60 * 5):
async def sse_client(url: str, headers: dict[str, Any] | None = None, timeout: float = 5, sse_read_timeout: float = 60 * 5):
"""
Client transport for SSE.
@@ -36,7 +37,7 @@ async def sse_client(url: str, timeout: float = 5, sse_read_timeout: float = 60
async with anyio.create_task_group() as tg:
try:
logger.info(f"Connecting to SSE endpoint: {remove_request_params(url)}")
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(headers=headers) as client:
async with aconnect_sse(
client,
"GET",

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "mcp-python"
version = "0.1.2"
version = "0.1.3"
description = "Model Context Protocol implementation for Python"
readme = "README.md"
requires-python = ">=3.8"