# MCPSessionManager

> **Class** in `deepagents_cli`

📖 [View in docs](https://reference.langchain.com/python/deepagents-cli/mcp_tools/MCPSessionManager)

Manages persistent MCP sessions for stateful stdio servers.

This manager creates and maintains persistent sessions for stdio MCP
servers, preventing server restarts on every tool call. Sessions are kept
alive until explicitly cleaned up.

## Signature

```python
MCPSessionManager(
    self,
)
```

## Constructors

```python
__init__(
    self,
) -> None
```


## Properties

- `client`
- `exit_stack`

## Methods

- [`cleanup()`](https://reference.langchain.com/python/deepagents-cli/mcp_tools/MCPSessionManager/cleanup)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/3bcc51a95da80094cfc8bc4bcaf25dc1e2ad8f44/libs/cli/deepagents_cli/mcp_tools.py#L355)