> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Websocket

> WebSocket connection management for MCP implementations API Documentation

**Source Code**

View the source code for this module on GitHub: [[https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp\_use/client/task\_managers/websocket.py](https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/task_managers/websocket.py)](https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/task_managers/websocket.py)

WebSocket connection management for MCP implementations.

This module provides a connection manager for WebSocket-based MCP connections.

## WebSocketConnectionManager

`class` WebSocketConnectionManager

Connection manager for WebSocket-based MCP connections.

This class handles the lifecycle of WebSocket connections, ensuring proper
connection establishment and cleanup.

```python theme={null}
from mcp_use.client.task_managers.websocket import WebSocketConnectionManager
```

> [card]
>
> ### `method` **init**
>
> Initialize a new WebSocket connection manager.
>
> **Parameters**
>
> > **url** `str` *required*
> >
> > The WebSocket URL to connect to
> >
> > **headers** `dict[str, str] | None` (default: None)
> >
> > Optional HTTP headers
>
> **Signature**
>
> ```python wrap theme={null}
> def __init__(url: str, headers: dict[str, str] | None = None):
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.