หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Important
The Playwright Workspaces remote Model Context Protocol (MCP) server is in preview. Preview features don't have a service-level agreement and aren't recommended for production workloads. Features, limits, and availability can change.
In this quickstart, you connect an AI agent to the Playwright Workspaces remote MCP server. The agent uses a managed cloud browser to open a webpage, inspect its accessibility snapshot, report page content, and close the browser session.
The remote MCP server provides browser automation tools over streamable HTTP. You don't need to install Playwright, browser binaries, or a local MCP server in the agent environment.
After you complete this quickstart, you have an MCP client connected to a Playwright workspace and can run an agent-driven browser task from GitHub Copilot CLI or Microsoft Foundry.
Prerequisites
- An Azure account with an active subscription. If you don't have an Azure subscription, create a free account before you begin.
- A Playwright workspace that is enabled for the remote MCP preview.
- The Contributor or Owner Azure role at the workspace scope. This role is required to create a workspace access token. For more information, see Manage access to a Playwright workspace.
- One of the following MCP clients:
- GitHub Copilot CLI with MCP support.
- A Microsoft Foundry project with permission to create project connections and configure agents.
Build the remote MCP endpoint
In the Azure portal, open the Overview page of your Playwright workspace. Use the workspace region and workspace ID to build the remote MCP endpoint.
The endpoint uses the following format:
https://<region>.mcp.playwright.microsoft.com/playwrightworkspaces/<workspace-id>/mcp
For example:
https://eastus.mcp.playwright.microsoft.com/playwrightworkspaces/00000000-0000-0000-0000-000000000000/mcp
Use the endpoint for the region where the workspace is deployed.
Create a workspace access token
This quickstart uses key-based authentication. The MCP client sends a workspace access token in the x-api-key request header.
Caution
Microsoft Entra ID is the recommended authentication method for Playwright Workspaces. Access tokens are less secure and are disabled by default. Treat an access token like a password. Never commit it to source control or include it in agent instructions, prompts, or logs.
- Sign in to the Azure portal.
- Open your Playwright workspace.
- Under Settings, select Access Management.
- Select the Playwright Service Access Token checkbox if it isn't already selected.
- Select Generate token.
- Enter a name and expiration date, and then generate the token.
- Copy the token immediately. You can't retrieve its value later.
The token is associated with the user who creates it. The service evaluates that user's current Azure role-based access control (RBAC) permissions when the token is used. Use a short expiration period for this quickstart.
For more information, see Manage workspace access tokens.
Connect an MCP client
Choose the MCP client that you want to use.
GitHub Copilot CLI
To add the Playwright Workspaces remote MCP server to GitHub Copilot CLI:
- Open GitHub Copilot CLI.
- Enter
/mcp add. - Enter a unique server name, such as
playwrightWorkspace. - Select HTTP as the server type.
- Enter the remote MCP endpoint.
- Add an HTTP header named
x-api-keyand use the workspace access token as its value. - Select Auto for deferred tools.
- Press Esc to finish adding the server.
Microsoft Foundry
Connect the remote server as a custom MCP tool. Foundry stores the workspace access token in a project connection.
Note
A key stored in a Foundry project connection is a shared project secret. Project members who use the connection use the identity and permissions associated with the token. Use a dedicated, least-privilege token and restrict access to the project.
To connect the remote MCP server:
- Open your project in the Microsoft Foundry portal.
- Select Build > Tools, and then select Add tool > Custom > Model Context Protocol.
- Enter
playwrightWorkspaceas the unique name. - Enter the remote MCP server endpoint.
- Select key-based authentication.
- Enter
x-api-keyas the credential name and the workspace access token as the credential value. - Select Connect. Foundry creates the project connection.
Create or open an agent, add the remote MCP tool, and select the project connection. Require approval for every tool call while you evaluate the integration. Requiring approval lets you inspect the tool name and arguments before each browser operation.
For current connection fields and approval behavior, see Connect Microsoft Foundry agents to MCP server endpoints.
Run your first browser task
Submit the following prompt to the agent:
Use the Playwright workspace tools to create a browser session, open
https://example.com, inspect the page snapshot, and report the main heading
and page URL. Close the browser session when the task finishes. Always close
the session if a browser step fails.
Verify that the agent follows this sequence:
- Calls
create_browser_sessionand retains the returnedbrowserSessionId. - Calls
browser_navigatewith the session ID andhttps://example.com. - Calls
browser_snapshotorbrowser_findwith the same session ID. - Reports the Example Domain heading and the page URL.
- Calls
close_browser_sessionwith the session ID.
A successful result resembles the following output:
Heading: Example Domain
URL: https://example.com/
Browser session closed.
The exact response varies by agent and model. The session creation result might also contain a live-view URL. The final response alone doesn't confirm cleanup. Inspect the tool-call history and verify that close_browser_session succeeded.
Caution
Remote browser sessions consume workspace capacity and might incur charges. Close each session as soon as the task finishes.
Clean up resources
When you finish the quickstart:
- Confirm that the agent called
close_browser_session. - Remove the test agent or project connection if you no longer need it.
- Revoke temporary workspace access tokens.
- In GitHub Copilot CLI, remove the MCP server if you no longer need the connection.
- If you created a Playwright workspace only for this quickstart, delete its resource group. Don't delete a resource group that contains resources you want to keep.