chore: recommend sse by default (#758)

This commit is contained in:
Yury Semikhatsky 2025-07-25 09:51:01 -07:00 committed by GitHub
parent e934d5e23e
commit 26a2a6fc83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 16 deletions

View File

@ -317,19 +317,19 @@ npx @playwright/mcp@latest --config path/to/config.json
### Standalone MCP server ### Standalone MCP server
When running headed browser on system w/o display or from worker processes of the IDEs, When running headed browser on system w/o display or from worker processes of the IDEs,
run the MCP server from environment with the DISPLAY and pass the `--port` flag to enable HTTP transport. run the MCP server from environment with the DISPLAY and pass the `--port` flag to enable SSE transport.
```bash ```bash
npx @playwright/mcp@latest --port 8931 npx @playwright/mcp@latest --port 8931
``` ```
And then in MCP client config, set the `url` to the HTTP endpoint: And then in MCP client config, set the `url` to the SSE endpoint:
```js ```js
{ {
"mcpServers": { "mcpServers": {
"playwright": { "playwright": {
"url": "http://localhost:8931/mcp" "url": "http://localhost:8931/sse"
} }
} }
} }

View File

@ -114,10 +114,10 @@ function startHttpTransport(httpServer: http.Server, serverBackendFactory: Serve
const streamableSessions = new Map(); const streamableSessions = new Map();
httpServer.on('request', async (req, res) => { httpServer.on('request', async (req, res) => {
const url = new URL(`http://localhost${req.url}`); const url = new URL(`http://localhost${req.url}`);
if (url.pathname.startsWith('/sse')) if (url.pathname.startsWith('/mcp'))
await handleSSE(serverBackendFactory, req, res, url, sseSessions);
else
await handleStreamable(serverBackendFactory, req, res, streamableSessions); await handleStreamable(serverBackendFactory, req, res, streamableSessions);
else
await handleSSE(serverBackendFactory, req, res, url, sseSessions);
}); });
const url = httpAddressToString(httpServer.address()); const url = httpAddressToString(httpServer.address());
const message = [ const message = [
@ -130,7 +130,7 @@ function startHttpTransport(httpServer: http.Server, serverBackendFactory: Serve
} }
} }
}, undefined, 2), }, undefined, 2),
'For legacy SSE transport support, you can use the /sse endpoint instead.', 'If your client supports streamable HTTP, you can use the /mcp endpoint instead.',
].join('\n'); ].join('\n');
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(message); console.error(message);

View File

@ -248,12 +248,3 @@ test('http transport browser lifecycle (persistent, multiclient)', async ({ serv
await client1.close(); await client1.close();
await client2.close(); await client2.close();
}); });
test('http transport (default)', async ({ serverEndpoint }) => {
const { url } = await serverEndpoint();
const transport = new StreamableHTTPClientTransport(url);
const client = new Client({ name: 'test', version: '1.0.0' });
await client.connect(transport);
await client.ping();
expect(transport.sessionId, 'has session support').toBeDefined();
});

View File

@ -234,3 +234,12 @@ test('sse transport browser lifecycle (persistent, multiclient)', async ({ serve
await client1.close(); await client1.close();
await client2.close(); await client2.close();
}); });
test('sse transport (default)', async ({ serverEndpoint }) => {
const { url } = await serverEndpoint();
const transport = new SSEClientTransport(url);
const client = new Client({ name: 'test', version: '1.0.0' });
await client.connect(transport);
await client.ping();
await client.close();
});