Skip to content

docs: Document stateful MCP session usage (Playwright)#522

Open
Dushyant Acharya (Dotify71) wants to merge 1 commit into
langchain-ai:mainfrom
Dotify71:docs/stateful-session-guidance
Open

docs: Document stateful MCP session usage (Playwright)#522
Dushyant Acharya (Dotify71) wants to merge 1 commit into
langchain-ai:mainfrom
Dotify71:docs/stateful-session-guidance

Conversation

@Dotify71

Copy link
Copy Markdown

Resolves langchain-ai/langchain#33966

Summary

This PR documents the crucial difference between client.get_tools() (stateless, creates a new MCP session per tool invocation) and client.session() (stateful, maintains connection across multiple tools).

This addresses the common pitfall where browser sessions terminate immediately after navigation when using Playwright MCP tools with agents, as reported in langchain-ai/langchain#33966. As noted by maintainers in that issue, this documentation belongs in the MCP adapters repository rather than the core langchain agent documentation.

Changes

  1. Added a prominent Stateful MCP Servers section to the README explaining the issue and the correct pattern.
  2. Updated the docstring for MultiServerMCPClient.get_tools() to explicitly warn developers about the stateless per-call session behavior.
  3. Added a comprehensive example script (examples/stateful_playwright_example.py) demonstrating a working Playwright agent.

@Dotify71

Copy link
Copy Markdown
Author

Hi Mason Daugherty (@mdrxy)! Since the related issue #33966 was closed as expected behavior (stateless client by default), this PR properly documents how users should implement the stateful session pattern to avoid the browser termination confusion.

Could you take a quick look when you have a chance? Happy to make any adjustments!

…right)

This documents the crucial difference between `client.get_tools()` (stateless,
creates a new MCP session per tool invocation) and `client.session()`
(stateful, maintains connection across multiple tools).

This addresses the common pitfall where browser sessions terminate immediately
after navigation when using Playwright MCP tools with agents.

Resolves langchain-ai/langchain#33966
@Dotify71
Dushyant Acharya (Dotify71) force-pushed the docs/stateful-session-guidance branch from e88e5f4 to a98eac5 Compare June 24, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant