rhombus-node-mcp
Version:
MCP server for Rhombus API
95 lines (94 loc) • 3.66 kB
JavaScript
import { postApi } from "../network/network.js";
import { formatTimestamp } from "../util.js";
export async function getVehicleEvents(args, timeZone, requestModifiers, sessionId) {
const requestArgs = {
deviceUuidFilter: args.deviceUuidFilter,
locationUuidFilter: args.locationUuidFilter,
vehicleLabelQuery: args.vehicleLabelQuery,
licensePlateFuzzyQuery: args.licensePlateFuzzyQuery,
startTimeMs: args.startTime ? new Date(args.startTime).getTime() : undefined,
endTimeMs: args.endTime ? new Date(args.endTime).getTime() : undefined,
};
const res = await postApi({
route: "/vehicle/getVehicleEvents",
body: requestArgs,
modifiers: requestModifiers,
sessionId,
});
if (res.error) {
throw new Error(JSON.stringify(res));
}
return (res.events?.map(event => ({
uuid: event.uuid ?? "",
deviceUuid: event.deviceUuid ?? undefined,
eventTimestamp: formatTimestamp(event.eventTimestamp ?? Date.now(), timeZone),
imageS3Key: event.imageS3Key ?? undefined,
thumbnailS3Key: event.thumbnailS3Key ?? undefined,
locationUuid: event.locationUuid ?? undefined,
vehicleLicensePlate: event.vehicleLicensePlate ?? "No License Plate",
})) ?? []);
}
export async function getSavedVehicles(timeZone, requestModifiers, sessionId) {
const res = await postApi({
route: "/vehicle/getVehicles",
body: {},
modifiers: requestModifiers,
sessionId,
});
if (res.error) {
throw new Error(JSON.stringify(res));
}
return (res.vehicles?.map(vehicle => ({
createdTimestamp: formatTimestamp(vehicle.createdAtMillis ?? Date.now(), timeZone),
name: vehicle.name ?? "No Name",
description: vehicle.description ?? "No Description",
licensePlate: vehicle.licensePlate ?? "No License Plate",
orgUuid: vehicle.orgUuid ?? "",
})) ?? []);
}
export async function getVehicleLabels(requestModifiers, sessionId) {
const res = await postApi({
route: "/vehicle/getVehicleLabelsForOrg",
body: {},
modifiers: requestModifiers,
sessionId,
});
if (res.error) {
throw new Error(JSON.stringify(res));
}
const processedVehicleLabels = {};
for (const [licensePlate, labels] of Object.entries(res.vehicleLabels ?? {})) {
const filteredLabels = labels?.filter(label => label !== null) ?? [];
if (!filteredLabels || filteredLabels.length === 0) {
continue;
}
processedVehicleLabels[licensePlate] = filteredLabels;
}
return processedVehicleLabels;
}
export async function searchLicensePlates(query, timeZone, requestModifiers, sessionId) {
const res = await postApi({
route: "/search/searchLicensePlates",
body: { licensePlateQuery: query },
modifiers: requestModifiers,
sessionId,
});
if (res.error)
throw new Error(JSON.stringify(res));
return (res.licensePlateEvents || []).map((event) => ({
licensePlate: event.vehicleLicensePlate ?? undefined,
deviceUuid: event.deviceUuid ?? undefined,
timestampMs: event.eventTimestamp ?? undefined,
}));
}
export async function saveVehicle(name, licensePlate, description, requestModifiers, sessionId) {
const res = await postApi({
route: "/vehicle/saveVehicle",
body: { name, licensePlate, description: description || "" },
modifiers: requestModifiers,
sessionId,
});
if (res.error)
throw new Error(JSON.stringify(res));
return { success: true };
}