diff --git a/README.md b/README.md index de48c2d..3ea79ee 100644 --- a/README.md +++ b/README.md @@ -317,19 +317,19 @@ npx @playwright/mcp@latest --config path/to/config.json ### Standalone MCP server 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 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 { "mcpServers": { "playwright": { - "url": "http://localhost:8931/mcp" + "url": "http://localhost:8931/sse" } } } diff --git a/src/mcp/transport.ts b/src/mcp/transport.ts index 5a0381f..6804294 100644 --- a/src/mcp/transport.ts +++ b/src/mcp/transport.ts @@ -114,10 +114,10 @@ function startHttpTransport(httpServer: http.Server, serverBackendFactory: Serve const streamableSessions = new Map(); httpServer.on('request', async (req, res) => { const url = new URL(`http://localhost${req.url}`); - if (url.pathname.startsWith('/sse')) - await handleSSE(serverBackendFactory, req, res, url, sseSessions); - else + if (url.pathname.startsWith('/mcp')) await handleStreamable(serverBackendFactory, req, res, streamableSessions); + else + await handleSSE(serverBackendFactory, req, res, url, sseSessions); }); const url = httpAddressToString(httpServer.address()); const message = [ @@ -130,7 +130,7 @@ function startHttpTransport(httpServer: http.Server, serverBackendFactory: Serve } } }, 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'); // eslint-disable-next-line no-console console.error(message); diff --git a/tests/http.spec.ts b/tests/http.spec.ts index 4ff9ac9..51e07db 100644 --- a/tests/http.spec.ts +++ b/tests/http.spec.ts @@ -248,12 +248,3 @@ test('http transport browser lifecycle (persistent, multiclient)', async ({ serv await client1.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(); -}); diff --git a/tests/sse.spec.ts b/tests/sse.spec.ts index 60cc740..eab9248 100644 --- a/tests/sse.spec.ts +++ b/tests/sse.spec.ts @@ -234,3 +234,12 @@ test('sse transport browser lifecycle (persistent, multiclient)', async ({ serve await client1.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(); +});