From b060d3fca04bee7eda751b50ca7ca0fabe05e79d Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Fri, 11 Jul 2025 16:36:32 -0700 Subject: [PATCH] test(mcp-inspector): add connection persistence test script - Create test script to verify WebSocket connections persist across requests - Test multiple sequential MCP requests using the same inspector URL - Demonstrate that connections are maintained in the worker thread --- .../bun-inspector-mcp/test-persistence.ts | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 packages/bun-inspector-mcp/test-persistence.ts diff --git a/packages/bun-inspector-mcp/test-persistence.ts b/packages/bun-inspector-mcp/test-persistence.ts new file mode 100644 index 0000000000..1fb37ba08d --- /dev/null +++ b/packages/bun-inspector-mcp/test-persistence.ts @@ -0,0 +1,94 @@ +import { createMcpHonoHttpStreamServer } from "./mcp"; + +// Create the server +const app = createMcpHonoHttpStreamServer(); + +// Start server on a test port +const port = 3333; +console.log(`Starting test server on port ${port}...`); + +// Simulate multiple requests to test connection persistence +async function testPersistence() { + console.log("\n=== Testing Connection Persistence ===\n"); + + // First request - register inspector + console.log("Request 1: Registering inspector..."); + const response1 = await fetch(`http://localhost:${port}/mcp`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + jsonrpc: "2.0", + method: "tools/call", + params: { + name: "registerInspector", + arguments: { + url: "ws://localhost:9229" + } + }, + id: 1 + }) + }); + console.log("Response 1:", await response1.text()); + + // Wait a bit + await new Promise(resolve => setTimeout(resolve, 1000)); + + // Second request - evaluate expression + console.log("\nRequest 2: Evaluating expression..."); + const response2 = await fetch(`http://localhost:${port}/mcp`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + jsonrpc: "2.0", + method: "tools/call", + params: { + name: "Runtime.evaluate", + arguments: { + url: "ws://localhost:9229", + expression: "1 + 1" + } + }, + id: 2 + }) + }); + console.log("Response 2:", await response2.text()); + + // Third request - check if connection is still alive + console.log("\nRequest 3: Evaluating another expression..."); + const response3 = await fetch(`http://localhost:${port}/mcp`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + jsonrpc: "2.0", + method: "tools/call", + params: { + name: "Runtime.evaluate", + arguments: { + url: "ws://localhost:9229", + expression: "process.version" + } + }, + id: 3 + }) + }); + console.log("Response 3:", await response3.text()); + + console.log("\n=== Test Complete ==="); + console.log("If you see responses for all 3 requests, the connection was persisted!"); +} + +// Start the server +const server = Bun.serve({ + port, + fetch: app.fetch +}); + +// Run the test after server starts +setTimeout(testPersistence, 1000); + +// Keep the process alive +process.on("SIGINT", () => { + console.log("\nShutting down..."); + server.stop(); + process.exit(0); +}); \ No newline at end of file