UNPKG

rhombus-node-mcp

Version:
51 lines (50 loc) 2.19 kB
import { getLocations, createLocation, updateLocation, getLocationLabels } from "../api/location-tool-api.js"; import { TOOL_ARGS } from "../types/location-tool-types.js"; const TOOL_NAME = "location-tool"; const TOOL_DESCRIPTION = `This tool performs operations on locations. - 'get': Retrieves all locations. When generating reports with location details, use location names not uuids. - 'create': Creates a new location with a name and optional address. - 'update': Updates an existing location (requires locationUuid). - 'get-labels': Retrieves all location labels for the organization.`; const TOOL_HANDLER = async (args, extra) => { const { action } = args; let ret; switch (action) { case "get": ret = await getLocations(extra._meta?.requestModifiers, extra.sessionId); break; case "create": { if (!args.locationName) { ret = { error: true, status: "locationName is required for 'create'" }; break; } ret = await createLocation(args.locationName, args.locationAddress ?? undefined, extra._meta?.requestModifiers, extra.sessionId); break; } case "update": { if (!args.locationUuid) { ret = { error: true, status: "locationUuid is required for 'update'" }; break; } ret = await updateLocation(args.locationUuid, args.locationUpdate?.name, args.locationAddress ?? undefined, extra._meta?.requestModifiers, extra.sessionId); break; } case "get-labels": ret = await getLocationLabels(extra._meta?.requestModifiers, extra.sessionId); break; default: ret = { error: true, status: `unsupported location tool call: ${action}` }; break; } return { content: [{ type: "text", text: JSON.stringify(ret) }], }; }; export function createTool(server) { server.registerTool(TOOL_NAME, { title: "Locations", description: TOOL_DESCRIPTION, inputSchema: TOOL_ARGS, annotations: { readOnlyHint: false, destructiveHint: false }, }, TOOL_HANDLER); }