Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/mcp/client/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import Any

import anyio
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
Expand All @@ -17,6 +18,7 @@
@asynccontextmanager
async def websocket_client(
url: str,
headers: dict[str, Any] | None = None,
) -> AsyncGenerator[
tuple[
MemoryObjectReceiveStream[types.JSONRPCMessage | Exception],
Expand Down Expand Up @@ -48,7 +50,9 @@ async def websocket_client(
write_stream, write_stream_reader = anyio.create_memory_object_stream(0)

# Connect using websockets, requesting the "mcp" subprotocol
async with ws_connect(url, subprotocols=[Subprotocol("mcp")]) as ws:
async with ws_connect(
url, subprotocols=[Subprotocol("mcp")], additional_headers=headers
) as ws:

async def ws_reader():
"""
Expand Down
Loading