Skip to content

Commit 385384e

Browse files
Fix for the connector normalisation
1 parent f062dcf commit 385384e

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

stackone_ai/utils/normalize.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,43 @@
44

55
import re
66

7-
_VERSIONED_ACTION_RE = re.compile(r"^[a-z][a-z0-9]*_\d+(?:\.\d+)+_(.+)_global$")
7+
_VERSION_RE = re.compile(r"^\d+(?:\.\d+)+$")
88

99

10-
def _normalize_action_name(action_name: str) -> str:
11-
"""Convert semantic search API action name to MCP tool name.
10+
def _normalize_action_name(composite_id: str) -> str:
11+
"""Convert semantic search API composite ID to MCP tool name.
1212
13-
API: 'calendly_1.0.0_calendly_create_scheduling_link_global'
14-
MCP: 'calendly_create_scheduling_link'
13+
Composite ID format: {connector}_{version}_{actionId}_{projectId}
14+
15+
Examples:
16+
'slack_1.0.0_send_message_global' -> 'slack_send_message'
17+
'calendly_1.0.0_calendly_list_events_global' -> 'calendly_list_events'
18+
'jira_1.0.0_search_issues_103/dev-56501' -> 'jira_search_issues'
19+
'bamboohr_create_employee' -> 'bamboohr_create_employee' (unchanged)
1520
"""
16-
match = _VERSIONED_ACTION_RE.match(action_name)
17-
return match.group(1) if match else action_name
21+
parts = composite_id.split("_")
22+
23+
# Find the version segment (e.g. "1.0.0")
24+
version_idx = None
25+
for i, part in enumerate(parts):
26+
if _VERSION_RE.match(part):
27+
version_idx = i
28+
break
29+
30+
if version_idx is None or version_idx < 1:
31+
return composite_id
32+
33+
connector = "_".join(parts[:version_idx])
34+
35+
# Everything after version, excluding the last segment (projectId)
36+
after_version = parts[version_idx + 1 :]
37+
if len(after_version) < 2:
38+
return composite_id
39+
40+
action_parts = after_version[:-1] # drop projectId (last segment)
41+
action_id = "_".join(action_parts)
42+
43+
# If action_id already starts with connector prefix, don't duplicate
44+
if action_id.startswith(f"{connector}_"):
45+
return action_id
46+
return f"{connector}_{action_id}"

0 commit comments

Comments
 (0)