From 1b18e31ffe270424e7d8df7ba56c15306dcbddcc Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 27 Mar 2025 19:23:50 +0100 Subject: [PATCH] chore: sse test (#59) --- tests/basic.spec.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/basic.spec.ts b/tests/basic.spec.ts index 765ebc4..09f5405 100644 --- a/tests/basic.spec.ts +++ b/tests/basic.spec.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { spawn } from 'node:child_process'; +import path from 'node:path'; import { test, expect } from './fixtures'; test('test tool list', async ({ server, visionServer }) => { @@ -450,3 +452,26 @@ test('stitched aria frames', async ({ server }) => { }, })); }); + +test('sse transport', async () => { + const cp = spawn('node', [path.join(__dirname, '../cli.js'), '--port', '0'], { stdio: 'pipe' }); + try { + let stdout = ''; + const url = await new Promise(resolve => cp.stdout?.on('data', data => { + stdout += data.toString(); + const match = stdout.match(/Listening on (http:\/\/.*)/); + if (match) + resolve(match[1]); + })); + + // need dynamic import b/c of some ESM nonsense + const { SSEClientTransport } = await import('@modelcontextprotocol/sdk/client/sse.js'); + const { Client } = await import('@modelcontextprotocol/sdk/client/index.js'); + const transport = new SSEClientTransport(new URL(url)); + const client = new Client({ name: 'test', version: '1.0.0' }); + await client.connect(transport); + await client.ping(); + } finally { + cp.kill(); + } +});