#!/usr/bin/env node
/**
* Simple test to verify the server starts correctly
*/
import { config } from "dotenv";
import { spawn } from "child_process";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
// Load environment variables
config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log("🧪 Simple Server Test\n");
// Check environment variables
console.log("📋 Environment Check:");
console.log(
`GITHUB_TOKEN: ${process.env.GITHUB_TOKEN ? "✅ Set" : "❌ Missing"}`
);
console.log(`GITHUB_USERNAME: ${process.env.GITHUB_USERNAME || "Not set"}\n`);
if (!process.env.GITHUB_TOKEN) {
console.error("❌ GITHUB_TOKEN is required!");
console.log("Please run: npm run setup");
process.exit(1);
}
// Start server and check if it starts without errors
console.log("🚀 Starting server...");
const server = spawn("node", [join(__dirname, "dist", "server.js")], {
stdio: ["pipe", "pipe", "pipe"],
});
let serverStarted = false;
let hasError = false;
server.stdout.on("data", (data) => {
const output = data.toString();
if (output.includes("GitHub MCP Server is running")) {
console.log("✅ Server started successfully!");
console.log("📤 Server output:");
console.log(output);
serverStarted = true;
server.kill();
}
});
server.stderr.on("data", (data) => {
const error = data.toString();
console.error("❌ Server error:", error);
hasError = true;
server.kill();
});
server.on("close", (code) => {
if (serverStarted) {
console.log("\n🎉 Test completed successfully!");
console.log("✅ Your GitHub MCP Server is working correctly!");
} else if (hasError) {
console.log("\n❌ Test failed - server had errors");
process.exit(1);
} else {
console.log("\n⚠️ Server closed without starting message");
process.exit(1);
}
});
// Timeout after 5 seconds
setTimeout(() => {
if (!serverStarted && !hasError) {
console.log("\n⏰ Test timeout - server did not start in time");
server.kill();
process.exit(1);
}
}, 5000);