All files / src/utils normalize.ts

100% Statements 3/3
100% Branches 2/2
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                        8x                                   26x 26x    
/**
 * Action name normalization utilities.
 *
 * The semantic search API returns versioned action names like:
 *   'calendly_1.0.0_calendly_create_scheduling_link_global'
 *
 * MCP tools use simplified names:
 *   'calendly_create_scheduling_link'
 *
 * This module bridges the two formats.
 */
 
const VERSIONED_ACTION_RE = /^[a-z][a-z0-9]*_\d+(?:\.\d+)+_(.+)_global$/;
 
/**
 * Convert semantic search API action name to MCP tool name.
 *
 * @param actionName - The raw action name from the API
 * @returns The normalized MCP-compatible tool name
 *
 * @example
 * ```typescript
 * normalizeActionName('calendly_1.0.0_calendly_create_scheduling_link_global');
 * // => 'calendly_create_scheduling_link'
 *
 * normalizeActionName('bamboohr_create_employee');
 * // => 'bamboohr_create_employee' (unchanged)
 * ```
 */
export function normalizeActionName(actionName: string): string {
	const match = VERSIONED_ACTION_RE.exec(actionName);
	return match ? match[1] : actionName;
}