UNPKG

clickhouse-mcp

Version:
59 lines 2.11 kB
// test-clickhouse.ts import { createClient } from "@clickhouse/client"; async function testClickHouseConnection() { console.error("Starting ClickHouse connection test..."); // Using console.error to see in logs try { // Get config from environment variables const host = "localhost"; const port = "8123"; const secure = "false"; const protocol = "http"; const url = `${protocol}://${host}:${port}`; console.error(`Connecting to ClickHouse at ${url}`); const client = createClient({ host: url, username: "default", password: "clickhouse", request_timeout: 30000, }); console.error("Executing test query..."); const result = await client.query({ query: "SELECT 1 as test", format: "JSONEachRow", }); const data = await result.json(); console.error("Query successful, result:", JSON.stringify(data)); // Test database listing console.error("Listing databases..."); const dbResult = await client.query({ query: "SHOW DATABASES", format: "JSONEachRow", }); const databases = await dbResult.json(); console.error("Databases:", JSON.stringify(databases)); return true; // Connection successful } catch (error) { console.error("ClickHouse connection error:", error.message); if (error instanceof Error) { console.error("Error stack:", error.stack); } return false; // Connection failed } } // Main function to handle command async function main() { const command = process.argv[2]; if (command === "start") { const success = await testClickHouseConnection(); console.error(`Connection test ${success ? "succeeded" : "failed"}`); } else { console.error("Unknown command. Use 'start' to test connection."); } } main().catch(err => { console.error("Unhandled error:", err); process.exit(1); }); //# sourceMappingURL=test-clickhouse.js.map