halton-iot-mcp-server
Version:
MCP Server for Halton IoT Data API - run with npx or Docker
126 lines • 5.49 kB
JavaScript
/**
* Test script to verify all MCP tools work correctly
*/
import { HaltonApiClient } from "./api-client.js";
const API_TOKEN = process.env.HALTON_API_TOKEN;
if (!API_TOKEN) {
console.error("Error: HALTON_API_TOKEN environment variable is required");
process.exit(1);
}
const client = new HaltonApiClient(API_TOKEN);
async function test() {
console.log("Testing Halton IoT API Client...\n");
// Test 1: Get all systems
console.log("1. get_all_systems");
try {
const systems = await client.getAllSystems();
const systemIds = Object.keys(systems);
console.log(` ✅ Found ${systemIds.length} system(s): ${systemIds.join(", ")}\n`);
if (systemIds.length === 0) {
console.log(" ⚠️ No systems found, skipping remaining tests");
return;
}
const systemId = systemIds[0];
// Test 2: Get specific system
console.log("2. get_systems");
const systemInfo = await client.getSystems([systemId]);
console.log(` ✅ System ${systemId}: ${systemInfo[systemId]?.systemName || "N/A"}\n`);
// Test 3: Get system variables
console.log("3. get_system_variables");
const variables = await client.getSystemVariables([systemId]);
const varCount = variables[systemId]?.variableCount || 0;
const varList = variables[systemId]?.systemVariables || [];
console.log(` ✅ Found ${varCount} variables\n`);
if (varList.length === 0) {
console.log(" ⚠️ No variables found, skipping remaining tests");
return;
}
// Get first variable name for testing
const testVar = varList[0]?.variableName;
console.log(` Using test variable: ${testVar}\n`);
// Test 4: Search variables
console.log("4. search_variables");
const searchResult = await client.searchSystemVariables({
systems: [systemId],
searchWords: ["Airflow"],
pagination: { pageNumber: 1, pageSize: 100, orderByType: "Ascending" }
}, false);
console.log(` ✅ Search returned results\n`);
// Test 5: Get last value (single variable)
console.log("5. get_last_value");
try {
const lastValue = await client.getLastEventValue(testVar, [systemId]);
const data = lastValue[systemId]?.data;
console.log(` ✅ Last value for ${testVar}: ${data?.value || "null"} at ${data?.timestamp || "N/A"}\n`);
}
catch (e) {
console.log(` ❌ Error: ${e instanceof Error ? e.message : e}\n`);
}
// Test 6: Get last values (multiple variables)
console.log("6. get_last_values_multiple");
try {
const testVars = varList.slice(0, 3).map(v => v.variableName).filter(Boolean);
const lastValues = await client.getLastEventValueMultiple({
systems: [systemId],
variables: testVars,
});
console.log(` ✅ Got last values for ${testVars.length} variables\n`);
// Show first result
const firstSystem = Object.keys(lastValues)[0];
if (firstSystem && lastValues[firstSystem]?.data) {
const firstData = lastValues[firstSystem].data[0];
console.log(` First: ${firstData?.variableName} = ${firstData?.value}\n`);
}
}
catch (e) {
console.log(` ❌ Error: ${e instanceof Error ? e.message : e}\n`);
}
// Test 7: Get aggregate data (single variable)
console.log("7. get_aggregate_data");
try {
const now = new Date();
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const aggData = await client.getAggregateSeries(testVar, {
systems: [systemId],
dateTimeRange: {
fromProperty: yesterday.toISOString(),
to: now.toISOString(),
},
intervalSeconds: 3600,
});
const dataPoints = aggData[systemId]?.data?.length || 0;
console.log(` ✅ Got ${dataPoints} hourly data points\n`);
}
catch (e) {
console.log(` ❌ Error: ${e instanceof Error ? e.message : e}\n`);
}
// Test 8: Get aggregate data (multiple variables)
console.log("8. get_aggregate_data_multiple");
try {
const now = new Date();
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const testVars = varList.slice(0, 2).map(v => v.variableName).filter(Boolean);
const aggMulti = await client.getAggregateSeriesMultiple({
systems: [systemId],
variables: testVars,
dateTimeRange: {
fromProperty: yesterday.toISOString(),
to: now.toISOString(),
},
intervalSeconds: 3600,
});
console.log(` ✅ Got aggregate data for ${testVars.length} variables\n`);
}
catch (e) {
console.log(` ❌ Error: ${e instanceof Error ? e.message : e}\n`);
}
console.log("=".repeat(50));
console.log("All tests completed!");
}
catch (error) {
console.error("❌ Test failed:", error);
process.exit(1);
}
}
test();
//# sourceMappingURL=test.js.map