Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions livekit-agents/livekit/agents/llm/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream

try:
from httpx import Auth
from mcp import ClientSession, stdio_client
from mcp.client.sse import sse_client
from mcp.client.stdio import StdioServerParameters
Expand Down Expand Up @@ -166,10 +167,12 @@ def __init__(
timeout: float = 5,
sse_read_timeout: float = 60 * 5,
client_session_timeout_seconds: float = 5,
auth: Auth | None = None,
) -> None:
super().__init__(client_session_timeout_seconds=client_session_timeout_seconds)
self.url = url
self.headers = headers
self.auth = auth
self._timeout = timeout
self._sse_read_timeout = sse_read_timeout
self._use_streamable_http = self._should_use_streamable_http(url)
Expand Down Expand Up @@ -204,13 +207,15 @@ def client_streams(
headers=self.headers,
timeout=timedelta(seconds=self._timeout),
sse_read_timeout=timedelta(seconds=self._sse_read_timeout),
auth=self.auth,
)
else:
return sse_client( # type: ignore[no-any-return]
url=self.url,
headers=self.headers,
timeout=self._timeout,
sse_read_timeout=self._sse_read_timeout,
auth=self.auth,
)

def __repr__(self) -> str:
Expand Down
Loading
Loading