Merge pull request #6 from modelcontextprotocol/ken/headers
Add header support for sse_client
This commit is contained in:
commit
f9baa82a1e
2 changed files with 4 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
from typing import Any
|
||||||
from urllib.parse import urljoin, urlparse
|
from urllib.parse import urljoin, urlparse
|
||||||
|
|
||||||
import anyio
|
import anyio
|
||||||
|
|
@ -18,7 +19,7 @@ def remove_request_params(url: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@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.
|
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:
|
async with anyio.create_task_group() as tg:
|
||||||
try:
|
try:
|
||||||
logger.info(f"Connecting to SSE endpoint: {remove_request_params(url)}")
|
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(
|
async with aconnect_sse(
|
||||||
client,
|
client,
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "mcp-python"
|
name = "mcp-python"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
description = "Model Context Protocol implementation for Python"
|
description = "Model Context Protocol implementation for Python"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.8"
|
requires-python = ">=3.8"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue