From 46c71a9857576c0f682cb74baccc3b85c0b275a9 Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 10 Jul 2025 11:17:11 +0100 Subject: [PATCH] Tidying up static files --- debug-test-hang.sh | 98 ---------------------------------- package.json | 3 +- src/handlers/sse.ts | 2 +- src/index.ts | 9 +++- mcp.png => src/static/mcp.png | Bin src/utils/logger.ts | 2 +- 6 files changed, 12 insertions(+), 102 deletions(-) delete mode 100755 debug-test-hang.sh rename mcp.png => src/static/mcp.png (100%) diff --git a/debug-test-hang.sh b/debug-test-hang.sh deleted file mode 100755 index dd27972..0000000 --- a/debug-test-hang.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -# Script to debug why Jest tests hang after completion - -echo "=== Starting Jest test hang debugging ===" -echo "Expected: Tests should exit within 5 seconds" -echo "Actual: Tests hang indefinitely" -echo "" - -# Run tests with timeout and capture output -echo "Running tests with 10 second timeout..." -timeout 10s npm test > test_output.log 2>&1 & -TEST_PID=$! - -# Monitor the test process -sleep 1 -echo "Test process PID: $TEST_PID" - -# Wait for either completion or timeout -wait $TEST_PID -EXIT_CODE=$? - -echo "" -echo "=== Test Results ===" -if [ $EXIT_CODE -eq 124 ]; then - echo "❌ TESTS TIMED OUT (hung after 10 seconds)" -else - echo "✅ Tests completed normally with exit code: $EXIT_CODE" -fi - -echo "" -echo "=== Test Output (last 20 lines) ===" -tail -20 test_output.log - -echo "" -echo "=== Checking for Jest hanging indicators ===" -if grep -q "Jest did not exit one second after the test run has completed" test_output.log; then - echo "❌ Found Jest hanging message" - - echo "" - echo "=== Common causes of Jest hanging ===" - echo "1. Unclosed database connections" - echo "2. Open timers/intervals" - echo "3. Open file handles" - echo "4. Unresolved promises" - echo "5. WebSocket connections" - echo "6. Event listeners not cleaned up" - - echo "" - echo "=== Analyzing test files for potential issues ===" - - # Check for Redis connections - echo "Checking for Redis connection issues..." - grep -r "redisClient" src/ --include="*.test.ts" | head -5 - - # Check for timers - echo "" - echo "Checking for setTimeout/setInterval..." - grep -r "setTimeout\|setInterval" src/ --include="*.test.ts" | head -5 - - # Check for event listeners - echo "" - echo "Checking for event listeners..." - grep -r "addEventListener\|on(" src/ --include="*.test.ts" | head -5 - - echo "" - echo "=== Suggested fixes ===" - echo "1. Add --detectOpenHandles to Jest config" - echo "2. Ensure all Redis connections are closed in afterAll/afterEach" - echo "3. Clear all timers in test cleanup" - echo "4. Add explicit process.exit() if needed" - -else - echo "✅ No Jest hanging message found" -fi - -echo "" -echo "=== Running with --detectOpenHandles ===" -echo "This will show what's keeping Node.js alive..." -timeout 15s npm test -- --detectOpenHandles > detect_handles.log 2>&1 & -DETECT_PID=$! -wait $DETECT_PID -DETECT_EXIT=$? - -if [ $DETECT_EXIT -eq 124 ]; then - echo "❌ --detectOpenHandles also timed out" -else - echo "✅ --detectOpenHandles completed" -fi - -echo "" -echo "=== Open handles output ===" -tail -30 detect_handles.log - -echo "" -echo "=== Cleanup ===" -rm -f test_output.log detect_handles.log -echo "Debug complete!" \ No newline at end of file diff --git a/package.json b/package.json index c5ff68e..c1eee27 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "start": "node dist/index.js", "dev": "tsx watch src/index.ts", - "build": "tsc", + "build": "tsc && npm run copy-static", + "copy-static": "mkdir -p dist/static && cp -r src/static/* dist/static/", "lint": "eslint src/", "test": "NODE_OPTIONS=--experimental-vm-modules jest" }, diff --git a/src/handlers/sse.ts b/src/handlers/sse.ts index fb9a654..e80c67a 100644 --- a/src/handlers/sse.ts +++ b/src/handlers/sse.ts @@ -72,7 +72,7 @@ export async function handleSSEConnection(req: Request, res: Response) { logger.info('Listening on Redis channel', { sessionId: transport.sessionId, - channel: redisChannel + channel: redisChannelForSession(transport.sessionId) }); await mcpServer.connect(transport); } diff --git a/src/index.ts b/src/index.ts index 83eb92f..7b67dbd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,8 @@ import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextpro import { AuthRouterOptions, mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js"; import cors from "cors"; import express from "express"; +import path from "path"; +import { fileURLToPath } from "url"; import { EverythingAuthProvider } from "./auth/provider.js"; import { BASE_URI, PORT } from "./config.js"; import { authContext } from "./handlers/common.js"; @@ -13,6 +15,10 @@ import { logger } from "./utils/logger.js"; const app = express(); +// Get the directory of the current module +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + // Base security middleware - applied to all routes const baseSecurityHeaders = (req: express.Request, res: express.Response, next: express.NextFunction) => { // Basic security headers @@ -150,7 +156,8 @@ app.delete("/mcp", cors(corsOptions), bearerAuth, authContext, handleStreamableH // Static assets app.get("/mcp-logo.png", (req, res) => { - res.sendFile("mcp.png", { root: "." }); + const logoPath = path.join(__dirname, "static", "mcp.png"); + res.sendFile(logoPath); }); // Upstream auth routes diff --git a/mcp.png b/src/static/mcp.png similarity index 100% rename from mcp.png rename to src/static/mcp.png diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 88acc73..828ca92 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -169,4 +169,4 @@ class StructuredLogger { export const logger = new StructuredLogger(); // Re-export for convenience -export { LogContext, StructuredLogEntry }; \ No newline at end of file +export type { LogContext, StructuredLogEntry }; \ No newline at end of file