Skip to content

Commit fddc22d

Browse files
committed
headers in handshake
1 parent c2ca8e0 commit fddc22d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/mcp/client/websocket.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from collections.abc import AsyncGenerator
44
from contextlib import asynccontextmanager
5+
from typing import Any
56

67
import anyio
78
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
@@ -17,6 +18,7 @@
1718
@asynccontextmanager
1819
async def websocket_client(
1920
url: str,
21+
headers: dict[str, Any] | None = None,
2022
) -> AsyncGenerator[
2123
tuple[
2224
MemoryObjectReceiveStream[types.JSONRPCMessage | Exception],
@@ -48,7 +50,7 @@ async def websocket_client(
4850
write_stream, write_stream_reader = anyio.create_memory_object_stream(0)
4951

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

5355
async def ws_reader():
5456
"""

0 commit comments

Comments
 (0)