Skip to content

The agent that grows with you

feat(connectors): manage_connections targets can name an account

Siddharth Balyanec8a971c0891
diff --git a/tools/connectors/targets.py b/tools/connectors/targets.py
index 3071b262924..9086ed005da 100644
--- a/tools/connectors/targets.py
+++ b/tools/connectors/targets.py
@@ -1,27 +1,50 @@
from __future__ import annotations
import logging
+import re
+from dataclasses import dataclass
from typing import Any, List, Optional, Set, Tuple
logger = logging.getLogger(__name__)
-CONNECTOR_ACTIONS = ("status", "connect", "reconnect")
+CONNECTOR_ACTIONS = ("status", "connect", "reconnect", "rename")
MCP_ACTIONS = ("install", "enable", "authorize")
ALL_ACTIONS = CONNECTOR_ACTIONS + MCP_ACTIONS
-_TARGET_FIELDS = frozenset({"name", "mcp"})
+_TARGET_FIELDS = frozenset({"name", "mcp", "alias", "to"})
+ALIAS_PATTERN = r"^[a-z0-9][a-z0-9-]{0,31}$"
+_ALIAS_RE = re.compile(ALIAS_PATTERN)
+_ALIAS_FORMAT = "1-32 lowercase letters, digits or '-', starting with a letter or digit"
-def normalize_targets(raw: Any) -> tuple[list[str], list[str], Optional[str]]:
+
+@dataclass(frozen=True)
+class HostedTarget:
+ """A hosted connector target. ``alias`` names one account of that connector; ``to`` is the
+ new alias of a rename."""
+
+ name: str
+ alias: Optional[str] = None
+ to: Optional[str] = None
+
+
+def _bad_alias(key: str, value: Optional[str]) -> Optional[str]:
+ if value is None or _ALIAS_RE.fullmatch(value):
+ return None
+ return f"'{key}' {value!r} is not a valid account name: use {_ALIAS_FORMAT}."
+
+
+def normalize_targets(raw: Any) -> tuple[list[HostedTarget], list[str], Optional[str]]:
if raw is None:
return [], [], None
if isinstance(raw, (str, dict)):
raw = [raw]
if not isinstance(raw, list):
return [], [], "'connectors' must be a list of names or {name, mcp} objects."
- managed: list[str] = []
+ managed: list[HostedTarget] = []
mcp: list[str] = []
for item in raw:
+ alias = to = None
if isinstance(item, dict):
unknown = sorted(set(item) - _TARGET_FIELDS)
if unknown:
@@ -32,17 +55,25 @@ def normalize_targets(raw: Any) -> tuple[list[str], list[str], Optional[str]]:
)
name = str(item.get("name") or "").strip().lower()
is_mcp = bool(item.get("mcp", False))
+ if is_mcp and ("alias" in item or "to" in item):
+ return [], [], "'alias' and 'to' name hosted connector accounts; an MCP target takes neither."
+ alias = str(item["alias"]).strip() if item.get("alias") is not None else None
+ to = str(item["to"]).strip() if item.get("to") is not None else None
else:
name, is_mcp = str(item or "").strip().lower(), False
if not name:
return [], [], "every target needs a non-empty 'name'."
- bucket = mcp if is_mcp else managed
- if name not in bucket:
- bucket.append(name)
+ if is_mcp:
+ if name not in mcp:
+ mcp.append(name)
+ continue
+ target = HostedTarget(name, alias, to)
+ if all((t.name, t.alias) != (name, alias) for t in managed):
+ managed.append(target)
return managed, mcp, None
-def validate_action(action: str, managed: list[str], mcp: list[str]) -> Optional[str]:
+def validate_action(action: str, managed: list[HostedTarget], mcp: list[str]) -> Optional[str]:
if action not in ALL_ACTIONS:
return (
f"action must be one of {', '.join(ALL_ACTIONS)}. "
@@ -55,7 +86,7 @@ def validate_action(action: str, managed: list[str], mcp: list[str]) -> Optional
if managed:
return (
f"'{action}' is an MCP action: every target must carry \"mcp\": true "
- f"(got managed connector(s) {', '.join(managed)}). Managed connectors use "
+ f"(got managed connector(s) {', '.join(t.name for t in managed)}). Managed connectors use "
"connect / reconnect / status."
)
if not mcp:
@@ -68,7 +99,21 @@ def validate_action(action: str, managed: list[str], mcp: list[str]) -> Optional
f"'{action}' is a managed-connector action; MCP targets ({', '.join(mcp)}) use "
f"{', '.join(MCP_ACTIONS)}."
)
- return None
+ return _validate_accounts(action, managed)
+
+
+def _validate_accounts(action: str, managed: list[HostedTarget]) -> Optional[str]:
+ if action != "rename" and any(t.to for t in managed):
+ return "'to' is the new name of an account and applies to action rename only."
+ if action == "rename":
+ if len(managed) != 1 or not managed[0].alias or not managed[0].to:
+ return ("rename takes exactly one target {\"name\": \"<slug>\", \"alias\": \"<current name>\", "
+ "\"to\": \"<new name>\"}. Use action status to list each connector's accounts.")
+ # The current name may be the vendor's label of an unnamed account, so only the new one is checked.
+ return _bad_alias("to", managed[0].to)
+ if any(t.alias for t in managed) and len(managed) > 1:
+ return "a call with an 'alias' takes that one target only; name other accounts in separate calls."
+ return next((e for t in managed if (e := _bad_alias("alias", t.alias))), None)
def catalog_names() -> set[str]:
diff --git a/tools/connectors/tool.py b/tools/connectors/tool.py
index 931031ab964..09750e8e021 100644
--- a/tools/connectors/tool.py
+++ b/tools/connectors/tool.py
@@ -10,7 +10,7 @@ from tools.connectors.catalog_tool import MANAGE_CATALOG_SCHEMA, manage_catalog
from tools.connectors.gateway import config as gateway_config
from tools.connectors.managed import run_managed_action
from tools.connectors.mcp import run_mcp_operation
-from tools.connectors.targets import ALL_ACTIONS, MCP_ACTIONS, normalize_targets, validate_action
+from tools.connectors.targets import ALIAS_PATTERN, ALL_ACTIONS, MCP_ACTIONS, normalize_targets, validate_action
from tools.registry import registry, tool_error
@@ -39,7 +39,7 @@ def manage_connections(
)
return run_managed_action(
- action, managed, args,
+ action, [t.name for t in managed], args,
client_factory=client_factory, session_id=session_id, tool_call_id=tool_call_id,
connection_callback=connection_callback, connectors_available=connectors_available,
)
@@ -60,7 +60,9 @@ MANAGE_CONNECTIONS_SCHEMA = {
"Hosted actions: 'status' lists connectors and whether each is connected; 'connect' "
"starts an authorization for the given connectors; 'reconnect' checks each one and "
"repairs only what is not connected ('force': true restarts even a working one, for an "
- "account switch). Pass SEVERAL slugs in one call. In the desktop app, the terminal UI and "
+ "account switch). A second account of one app is 'connect' with a new 'alias': pick a short "
+ "lowercase name from the user's words (e.g. 'work'), and ask the user if unsure. 'status' lists "
+ "each connector's accounts; 'rename' names or renames one. Pass SEVERAL slugs in one call. In the desktop app, the terminal UI and "
"the interactive CLI the call shows the user a card and blocks until every app is "
"connected, skipped, or the deadline passes; the result lists each target as connected / "
"skipped / not_connected and never carries a link. Where no card exists (a one-shot run, "
@@ -86,7 +88,7 @@ MANAGE_CONNECTIONS_SCHEMA = {
"type": "string",
"enum": list(ALL_ACTIONS),
"description": (
- "Defaults to status. connect and reconnect take hosted connector slugs only. "
+ "Defaults to status. connect, reconnect and rename take hosted connector slugs only. "
"install, enable and authorize take mcp:true targets only."
),
},
@@ -106,6 +108,19 @@ MANAGE_CONNECTIONS_SCHEMA = {
"false = a hosted connector account."
),
},
+ "alias": {
+ "type": "string",
+ "description": (
+ "Hosted only: the account's name. connect: a new name adds another "
+ "account; reconnect: repairs that account; rename: its current name "
+ "(or its label when unnamed). One aliased target per call."
+ ),
+ },
+ "to": {
+ "type": "string",
+ "pattern": ALIAS_PATTERN,
+ "description": "rename only: the new name.",
+ },
},
"required": ["name"],
"additionalProperties": False,