rhombus-node-mcp
Version:
MCP server for Rhombus API
53 lines (50 loc) • 2.64 kB
JavaScript
import { getCameraUptime, getFleetUptime } from "../api/camera-uptime-tool-api.js";
import { CameraUptimeRequestType, OUTPUT_SCHEMA, TOOL_ARGS, } from "../types/camera-uptime-tool-types.js";
import { createToolStructuredContent, extractFromToolExtra } from "../util.js";
const TOOL_NAME = "camera-uptime-tool";
const TOOL_DESCRIPTION = `
This tool analyzes camera uptime and reliability over a time period. It computes uptime percentages, outage counts, and longest outage durations.
It has the following modes of operation, determined by the "requestType" parameter:
- ${CameraUptimeRequestType.GET_CAMERA_UPTIME}: Get uptime statistics for a single camera. Requires cameraUuid, startTimeSec, and endTimeSec.
- ${CameraUptimeRequestType.GET_FLEET_UPTIME}: Get uptime statistics for ALL cameras in the organization, sorted by worst uptime first. Includes a fleet-wide summary with averages. Requires startTimeSec and endTimeSec.
startTimeSec and endTimeSec are UNIX timestamps in seconds.
`;
const TOOL_HANDLER = async (args, _extra) => {
const { requestModifiers, sessionId } = extractFromToolExtra(_extra);
try {
switch (args.requestType) {
case CameraUptimeRequestType.GET_CAMERA_UPTIME: {
if (!args.cameraUuid) {
return createToolStructuredContent({
error: "cameraUuid is required for get-camera-uptime.",
});
}
const cameraUptime = await getCameraUptime(args.cameraUuid, args.startTimeSec, args.endTimeSec, requestModifiers, sessionId);
return createToolStructuredContent({ cameraUptime });
}
case CameraUptimeRequestType.GET_FLEET_UPTIME: {
const result = await getFleetUptime(args.startTimeSec, args.endTimeSec, requestModifiers, sessionId);
return createToolStructuredContent({
fleetUptime: result.cameras,
fleetSummary: result.summary,
});
}
}
}
catch (error) {
if (error instanceof Error) {
return createToolStructuredContent({ error: error.message });
}
return createToolStructuredContent({ error: "Unknown error" });
}
return createToolStructuredContent({ error: "Invalid request type" });
};
export function createTool(server) {
server.registerTool(TOOL_NAME, {
title: "Camera Uptime",
description: TOOL_DESCRIPTION,
inputSchema: TOOL_ARGS,
outputSchema: OUTPUT_SCHEMA.shape,
annotations: { readOnlyHint: true },
}, TOOL_HANDLER);
}