Read a page with Playwright while observing MCP initialization, version
negotiation and HTTP session handling. server.py exposes
playwright_navigate (title, final URL and up to 2,000 characters of body text)
and playwright_screenshot (800 × 600 viewport PNG). client.py
prints outgoing POST messages, session information and tool results.
- Core MCP 2025-11-25 and its initialization lifecycle describe the client/server protocol, not a Python SDK release number.
- The client calls
initialize()and prints the negotiatedprotocolVersion; it does not hard-code the date. The installedmcp==1.27.0supports2025-11-25as its latest version, and negotiation to that date has been confirmed at runtime. This naming change does not represent a new test run. - pyproject.toml pins MCP SDK 1.27.0, Playwright 1.58.0 and
HTTPX 0.28.1; Python 3.13+ and
uvare required. No LLM API key is needed.
Run from the repository root; keep this sample's environment separate:
uv sync --directory mcp_learning_samples/mcp_v1_browser_tools --default-index https://packagefeedproxy.microsoft.io/pypi/simple/
uv run --directory mcp_learning_samples/mcp_v1_browser_tools --no-sync playwright install chromiumUse the approved package proxy; do not bypass it or disable TLS verification. Chromium is a separate download subject to organizational policy.
Both terminals start at the repository root. Port 8011 must be free.
Terminal 1 — server (leave running):
uv run --directory mcp_learning_samples/mcp_v1_browser_tools --no-sync python server.pyTerminal 2 — client:
uv run --directory mcp_learning_samples/mcp_v1_browser_tools --no-sync python client.py https://example.comThe client connects to http://127.0.0.1:8011/mcp, initializes, lists tools and
reads the page. Omitting the URL uses https://example.com.
For an additional screenshot tool call:
uv run --directory mcp_learning_samples/mcp_v1_browser_tools --no-sync python client.py https://example.com --screenshotThe screenshot response contains PNG data, but the CLI only prints content types and MIME types; it does not display or save an image. Stop the server with Ctrl+C.
Each tool call opens and closes a fresh browser; navigation and screenshot calls do not share page state. Only HTTP(S) input URLs are accepted, but there is no destination allowlist or authentication. Use only trusted URLs in this local teaching sample; it is not a production browser service or an MCP Apps UI.