Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(connectors): each custom connector is an app a hire can use
trohitga513e1c00eaa
diff --git a/CLAUDE.md b/CLAUDE.mdindex 171be396..32ce477a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -33,7 +33,7 @@ This is a React Flow-based workflow automation platform implementing n8n-inspire| **[Email Service](./docs-internal/email_service.md)** | IMAP/SMTP integration via Himalaya CLI with EmailService orchestrator, provider presets, custom credential fallback, and polling triggers || **[Browser](./docs-internal/browser.md)** | Current `browser` node: installed Chrome/Edge/Chromium in a dedicated profile rendered inside the workspace by default (`BROWSER_RUNTIME=system`, `BROWSER_HEADLESS=true`) and pinned browser-use CLI. Chrome for Testing requires explicit `BROWSER_RUNTIME=testing`. System mode retains the native user agent and OS password-store/keychain integration; basic/mock keychain flags are restricted to testing mode. Includes persistent employee/shared profiles (the Credentials / Connectors "Web browser" panel adds, deletes and imports logins from a session file; the node's profile dropdown lists only the caller's profiles, via `current_load_options_principal()`), session leases, agent/user handoff, network policy, screenshots as workspace FileRefs and authenticated `/ws/browser` live viewing. Plugin-owned installation is lazy (`_install_chrome.py`, `_install_bu.py`); importing or shutting down the plugin never installs it. Replaces the former agent-browser and separate `browserHarness` implementations. || **[Browser Workspace](./docs-internal/browser_workspace.md)** | Home and Dev share `WorkspaceTabs` and `BrowserWorkspace`: Browser / Canvas / Mobile, capability-based discovery, binary JPEG frames, bounded frame credit and decoding, Take control / Hand back, the agent's cursor (`agent_action`: where each click, hover, type or select happened, beside the agent's result and never during a protected login), visibility cleanup and payload-free opt-in diagnostics. The Browser node's parameter panel shows the same viewer, and the Dev dock opens on its Browser tab when an agent in the open workflow asks for help (`browser_updated`). Mobile shows the managed local Android phone. |-| **[MCP Connectors](./docs-internal/mcp_connectors.md)** | Custom connectors: the owner adds an outside MCP server from Connectors → Add (URL, name, sign-in: none, bearer or one header), and OpenCompany is its MCP *client* (`server/nodes/mcp/`, official `mcp` SDK; unrelated to the CLI agents' `/mcp/ide` server). The server reads the tools before keeping anything: streamable HTTP, then SSE; our own httpx client with redirects off; host and resolved addresses checked against `services/netpolicy.py` (shared with the Browser node: never cloud metadata or OpenCompany's own ports, plain http only on the owner's network), within `DISCOVER_S` (45 s, under the app's 60 s probe wait). Kept as `mcp:<slug>` (sign-in, encrypted; plain `model_params._mcp`: tools as accepted, per-tool `{enabled, ask}`, a waiting refresh) and `mcp:<slug>_proxy` (URL). A tool no model could call is kept with the reason, never renamed. Each connector is its own card through the generic `Credential.catalogue_entries` hook and the `_mcp_connector` template. Commands `mcp_connector_add` / `_test` / `_refresh` / `_review` / `_set_tool` / `_remove`; Refresh holds every change for Accept. Client: `AddConnectorForm.tsx` and `panels/McpConnectorPanel.tsx`. The `mcpConnector` node on an agent's Tools gives one tool per tool that is on (`ToolNode.tool_bindings`, named `<slug>__<tool>`, run with its binding's locked `mcp_tool` / `mcp_ask` / labels; arguments checked with jsonschema; Ask first per tool through the node's `approval` spec); CLI agents leave it out and RLM refuses it. |+| **[MCP Connectors](./docs-internal/mcp_connectors.md)** | Custom connectors: the owner adds an outside MCP server from Connectors → Add (URL, name, sign-in: none, bearer or one header), and OpenCompany is its MCP *client* (`server/nodes/mcp/`, official `mcp` SDK; unrelated to the CLI agents' `/mcp/ide` server). The server reads the tools before keeping anything: streamable HTTP, then SSE; our own httpx client with redirects off; host and resolved addresses checked against `services/netpolicy.py` (shared with the Browser node: never cloud metadata or OpenCompany's own ports, plain http only on the owner's network), within `DISCOVER_S` (45 s, under the app's 60 s probe wait). Kept as `mcp:<slug>` (sign-in, encrypted; plain `model_params._mcp`: tools as accepted, per-tool `{enabled, ask}`, a waiting refresh) and `mcp:<slug>_proxy` (URL). A tool no model could call is kept with the reason, never renamed. Each connector is its own card through the generic `Credential.catalogue_entries` hook and the `_mcp_connector` template. Commands `mcp_connector_add` / `_test` / `_refresh` / `_review` / `_set_tool` / `_remove`; Refresh holds every change for Accept. Client: `AddConnectorForm.tsx` and `panels/McpConnectorPanel.tsx`. The `mcpConnector` node on an agent's Tools gives one tool per tool that is on (`ToolNode.tool_bindings`, named `<slug>__<tool>`, run with its binding's locked `mcp_tool` / `mcp_ask` / labels; arguments checked with jsonschema; Ask first per tool through the node's `approval` spec); CLI agents leave it out and RLM refuses it. Each connector is also an app a hire can use: `connector_apps`, registered with `services/employees/apps.register_app_source`, is read by `Connections.apps` with `employee_apps.json`'s apps (a saved one counts as connected), `mcpConnector` is on the hire allowlist, and the employee's card reads the connector from the node's `app_field` (`mcp_connector`). || **[WhatsApp Business Service](./docs-internal/whatsapp_business_service.md)** | Official Meta Cloud API plugin in [`server/nodes/whatsapp_business/`](./server/nodes/whatsapp_business/) — **distinct from `nodes/whatsapp/`**, which is a personal account over an unofficial Go bridge; they share no node type, credential or palette group. Four nodes: `whatsappBusinessSend` (10 ops — Meta models message type as a *field* on one `/messages` endpoint, so text / media / template / interactive are operations, not nodes), `whatsappBusinessMedia` (the one genuinely separate endpoint family), and the `Receive` / `Status` triggers (kept separate because a canary trigger registers exactly one CloudEvents type). `phone_number_id` is deliberately **absent from Params** and comes from the credential only, because it selects the sending identity — `server_controlled_fields` would keep a model-set value out on every tool path, but an ActionNode's tool schema is its whole `Params` (`ToolInput` is ToolNode-only), so a declared field would still appear in the schema the model sees. Webhook via `register_webhook_source` on the shared catch-all, `X-Hub-Signature-256` HMAC failing closed, composite `wamid:status` dedup ids so `sent→delivered→read` don't collapse. || **[Stripe Service](./docs-internal/stripe_service.md)** | Stripe CLI integration — `stripeAction` (CLI pass-through) + `stripeReceive` (signed-webhook trigger, on a canvas Run and deployed: every Stripe event travels under one CloudEvents type, `com.opencompany.stripe.event.received`, with the Stripe type in `subject` and `data.event_type`, where the node's own `build_filter` reads it; the source shapes the payload once, wakes the in-process waiter through `WebhookSource.handle` and reaches deployed listeners through `dispatch.emit`; deploying starts `stripe listen` through the generic `TriggerNode.prepare_deployment` hook, at Start and at the boot re-arm). Reference plugin for the Wave 12 event framework AND the **CLI-managed-auth pattern**: browser OAuth via `stripe login --non-interactive` + `--complete <url>` (URL extracted from `next_step` shell command via `shlex.split`) + auto-installed binary (`ensure_stripe_cli` from GitHub releases) + marker-token reuse of `auth_service.store_oauth_tokens` + CloudEvents-shaped `broadcast_credential_event("credential.oauth.connected" \| ".disconnected", provider=...)` — zero per-provider hardcoding in the frontend. Daemon stdout/stderr ingested via `ProcessService`'s `line_handler` callback (no log-file tailing); credential gate routed through `await self.has_credential()` so non-api-key auth (`is_logged_in()`) plugs in via subclass override. || **[Vercel Service](./docs-internal/vercel_service.md)** | Vercel CLI integration — `vercelAction` (deploy / inspect / list + `custom` CLI passthrough; AI tool `vercel`). Second reference for the CLI-managed-auth pattern: the **device-flow variant** (`vercel login` is one blocking process — no two-step `--complete`; direct `create_subprocess_exec` + chunk-based banner read for the code-embedding URL, pumps drain pipes for the process lifetime, success gate = auth.json mtime advance + sniff). Dual auth: optional `vercel_token` field (injected as `VERCEL_TOKEN` env, never argv) OR CLI login with marker tokens. All invocations pin `--global-config <DATA_DIR>/vercel/` (the `CLAUDE_CONFIG_DIR` isolation idiom). `bun add` into the shared packages tree (pinned version, via `core/js_runtime.add_package`; the CLI runs on bun). First-deploy project guard raises `NodeUserError` instead of letting Vercel derive an invalid name from the workspace dir. Shipped with the generic OAuthConnect change: Login gates on **required** fields only, so optional fields never block CLI login. |diff --git a/docs-internal/mcp_connectors.md b/docs-internal/mcp_connectors.mdindex d0e29e54..6b707a04 100644--- a/docs-internal/mcp_connectors.md+++ b/docs-internal/mcp_connectors.md@@ -16,7 +16,7 @@ thing: see [CLI Agent Framework](./cli_agent_framework.md).| What is kept (two credential rows) | `server/nodes/mcp/_store.py` || One catalogue card per connector | `server/nodes/mcp/_credentials.py` || The Connectors page's commands | `server/nodes/mcp/_handlers.py` |-| The node that gives an agent the tools | `server/nodes/mcp/mcp_connector.py` |+| The node that gives an agent the tools, and each connector as an app a hire can use | `server/nodes/mcp/mcp_connector.py` || The outbound address rules, shared with the Browser node | `server/services/netpolicy.py` || The cards' shared fields, and the `custom` categories | `server/config/credential_providers.json` (`_mcp_connector`) || The Add form | `client/src/components/credentials/AddConnectorForm.tsx` |@@ -152,6 +152,27 @@ settings, which are locked so the model never sets them: `mcp_tool`, `mcp_ask`next run. A tool turned off is refused at once.- CLI agents (Claude Code, Codex) leave the node out; an RLM agent refuses it.+## In hires++Each saved connector is also an app a hire can use. `connector_apps`+(registered with `register_app_source`, see+[apps.py](../server/services/employees/apps.py)) gives one app per connector:+its id and provider id are the connector's reference (`mcp:<slug>`), its name+the connector's, and its one tool the node set to that connector.+`Connections.apps` reads them with the registry's apps, so:++- the setup model is told about them with the connected apps, and a hire that+ names one gets the node on its agent (`mcpConnector` is on the hire+ allowlist, `enabled_nodes`);+- a saved connector counts as connected;+- under Ask first the node stays, since each call waits for the owner per its+ tool's setting.++The employee's card lists the connector its node names. The node declares+`app_field = "mcp_connector"`, so the summaries read that parameter+(`GraphIndex.app_params`, one query for the whole team list). A removed+connector is no longer listed.+## The page- **Add** on the Connectors page (`CatalogLayout.primaryAction`) opens@@ -172,8 +193,8 @@ settings, which are locked so the model never sets them: `mcp_tool`, `mcp_ask`## Known gaps-- Hiring does not add a connector: an employee uses one only when its- workflow gets the Custom Connector node in Dev mode.+- The Agent Builder does not add a connector from Talk yet: an employee gets+ one at hire, or in Dev mode with the Custom Connector node.- No OAuth sign-in.- A host's addresses are checked when connecting, not pinned for theconnection.diff --git a/docs-internal/normal_mode.md b/docs-internal/normal_mode.mdindex c7eeafe6..074b7f27 100644--- a/docs-internal/normal_mode.md+++ b/docs-internal/normal_mode.md@@ -418,8 +418,15 @@ the client's `HIRE_PAYLOAD_KEYS` must match, locked by([config/employee_apps.json](../server/config/employee_apps.json),[apps.py](../server/services/employees/apps.py)): each app's provider,its trigger / reply / notify-owner / tool nodes with parameter templates,- and a `side_effects` class. Apps the registry does not know are recorded as- unsupported, named in the instructions, and never block a start;+ and a `side_effects` class. The owner's own apps join them: a plugin+ registers a source (`register_app_source`) that gives what the owner saved,+ such as each custom connector ([MCP Connectors](./mcp_connectors.md#in-hires)),+ and `Connections.apps` reads both, so the setup screen, Hire and the+ employee's card see the same apps. A saved app counts as connected. A node+ whose app a parameter names rather than its type declares that parameter+ (`BaseNode.app_field`), and the card reads it. Apps nobody knows are+ recorded as unsupported, named in the instructions, and never block a+ start;3. builds the graph ([builder.py](../server/services/employees/builder.py),pure): one trigger (an app event, a schedule on `cronScheduler`, or manualchat), one `aiAgent` whose system message comes from@@ -1094,9 +1101,9 @@ chat's rollback), `lib/__tests__/workflowOps.test.ts` and- Billing has no plans, payment method or invoices: no billing account sitsbehind OpenCompany. A deleted employee's runs leave the month's count,because deleting a workflow deletes its run records.-- Hiring does not add a custom (MCP) connector: an employee uses one only- when its workflow gets the Custom Connector node (`mcpConnector`) in Dev- mode.+- The Agent Builder does not add a custom (MCP) connector from Talk yet: an+ employee gets one at hire, or in Dev mode with the Custom Connector node+ (`mcpConnector`).- Skill library changes reach only new hires: an employee keeps the skills itwas hired with, and one hired before the library existed has none, untilthe owner asks them in Talk to add one. The library is shared across usersdiff --git a/docs-internal/plugin_system.md b/docs-internal/plugin_system.mdindex 5df9c94b..73e17c9e 100644--- a/docs-internal/plugin_system.md+++ b/docs-internal/plugin_system.md@@ -406,6 +406,15 @@ after the static providers, and those cards carry their own `stored` /`nodes/mcp/_credentials.py` is the one user: one card per custom MCPconnector ([MCP Connectors](./mcp_connectors.md)).+**Apps from what was saved**: when a node's app is one the owner saved, not+one of `config/employee_apps.json`'s, the plugin registers a source with+`services.employees.apps.register_app_source(kind, source)`. `source(principal)`+returns `AppSpec`s, and `Connections.apps` reads them with the file's, so the+setup screen, Hire and the employee's card see them. Such a node declares+`app_field`, the parameter that holds its app's id, so the card can tell two+nodes of one type apart. `nodes/mcp` is the one user: each custom connector+is an app.+**Shipped credentials** (Wave 11.E → E.1):| File | Class(es) | Auth | Covers |diff --git a/server/config/node_allowlist.json b/server/config/node_allowlist.jsonindex ac5f4028..88f36144 100644--- a/server/config/node_allowlist.json+++ b/server/config/node_allowlist.json@@ -62,6 +62,8 @@"stripeAction",+ "mcpConnector",+"httpRequest","timer","cronScheduler",diff --git a/server/nodes/mcp/__init__.py b/server/nodes/mcp/__init__.pyindex 76adb209..8336aac5 100644--- a/server/nodes/mcp/__init__.py+++ b/server/nodes/mcp/__init__.py@@ -10,18 +10,21 @@ something employees can use.- ``_handlers.py``: add, test, refresh, accept or discard what a refreshfound, set a tool, and remove.- ``mcp_connector.py``: the node that gives an agent a connector's tools,- one per tool (``ToolNode.tool_bindings``).+ one per tool (``ToolNode.tool_bindings``), and each connector as an app a+ hire can use (``connector_apps``)."""from __future__ import annotations+from services.employees.apps import register_app_sourcefrom services.ws_handler_registry import register_option_loader, register_ws_handlersfrom ._credentials import McpConnectorCredentialfrom ._handlers import WS_HANDLERS-from .mcp_connector import McpConnectorNode, load_connectors+from .mcp_connector import McpConnectorNode, connector_apps, load_connectorsregister_ws_handlers(WS_HANDLERS)register_option_loader("mcpConnectors", load_connectors)+register_app_source("mcp", connector_apps)__all__ = ["McpConnectorCredential", "McpConnectorNode", "WS_HANDLERS"]diff --git a/server/nodes/mcp/mcp_connector.py b/server/nodes/mcp/mcp_connector.pyindex f0c5ef1f..e4aba1a4 100644--- a/server/nodes/mcp/mcp_connector.py+++ b/server/nodes/mcp/mcp_connector.py@@ -7,20 +7,26 @@ What a call runs with (``mcp_tool``, ``mcp_ask`` and the labels its cardshows) comes from its binding and is locked: the model never sets it. Whilethe employee asks first, a call of a tool set to Ask first waits for theowner (``approval``).++Each saved connector is also an app a hire can use (``connector_apps``,+registered as an app source): its one tool is this node set to it, and its+id is the node's ``mcp_connector`` value (``app_field``)."""from __future__ import annotations+from types import MappingProxyTypefrom typing import Any, Dict, List, Mapping, Optionalfrom pydantic import BaseModel, ConfigDict, Field+from services.employees.apps import AppSpec, ToolTemplatefrom services.plugin import NodeContext, NodeUserError, Operation, TaskQueue, ToolNodefrom services.plugin.approval import ApprovalSpecfrom services.plugin.tool import ToolBinding, inline_schema_refsfrom ._client import ConnectorError, call_name, call_tool, check_arguments-from ._credentials import McpConnectorCredential+from ._credentials import TEMPLATE, McpConnectorCredentialfrom ._store import get_connector, list_connectors, read_access, slug_of@@ -71,6 +77,7 @@ class McpConnectorNode(ToolNode):ToolInput = McpToolInputOutput = McpToolOutputserver_controlled_fields = frozenset({"mcp_connector", "mcp_tool", "mcp_ask", "mcp_label", "mcp_title"})+ app_field = "mcp_connector"approval = ApprovalSpec(channel="Custom connector",@@ -136,4 +143,37 @@ class McpConnectorNode(ToolNode):return McpToolOutput(text=result.text, structured=result.structured)-__all__ = ["McpConnectorNode", "McpConnectorParams", "McpToolInput", "McpToolOutput", "load_connectors"]+async def connector_apps(principal: Optional[str] = None) -> List[AppSpec]:+ """Each connector the owner saved, as an app a hire can use. Its tools+ can do anything the server does, so they count as sending; a call+ waits for the owner per the tool's Ask first (``approval``)."""+ from services.credential_registry import get_credential_registry++ icon_ref = (get_credential_registry().get_template(TEMPLATE) or {}).get("icon_ref")+ scope = {"principal": principal} if principal is not None else {}+ return [+ AppSpec(+ id=connector.ref,+ name=connector.name,+ provider_id=connector.ref,+ aliases=(),+ trigger=None,+ reply=None,+ notify_owner=None,+ tools=(+ ToolTemplate(+ type=McpConnectorNode.type,+ params=MappingProxyType({McpConnectorNode.app_field: connector.ref}),+ label=connector.name,+ side_effects="send",+ ),+ ),+ side_effects="send",+ phrases=MappingProxyType({}),+ icon_ref=icon_ref,+ )+ for connector in await list_connectors(**scope)+ ]+++__all__ = ["McpConnectorNode", "McpConnectorParams", "McpToolInput", "McpToolOutput", "connector_apps", "load_connectors"]diff --git a/server/services/employees/apps.py b/server/services/employees/apps.pyindex 510e20d0..361e9073 100644--- a/server/services/employees/apps.py+++ b/server/services/employees/apps.py@@ -13,6 +13,13 @@ exact, then prefix, then word, then substring (3+ characters), preferringa connected app within a tier. A name that matches nothing is kept as anunsupported app: it never blocks a start and the employee's instructionsname it.++More apps come from what an owner saved rather than from the file: a+plugin registers a source (``register_app_source``) that gives one owner's+apps, such as each custom connector (nodes/mcp). Such an app exists only+while it is saved, so it is connected. Its tool's node type says which+parameter names the app (``BaseNode.app_field``), and that parameter holds+the app's id. ``Connections.apps`` reads both kinds."""from __future__ import annotations@@ -22,9 +29,10 @@ import refrom dataclasses import dataclass, fieldfrom pathlib import Pathfrom types import MappingProxyType-from typing import Any, Dict, Iterable, Mapping, Optional, Sequence, Tuple+from typing import Any, Awaitable, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Tuplefrom core.logging import get_logger+from services.plugin.registry import IdempotentRegistrylogger = get_logger(__name__)@@ -89,6 +97,9 @@ class AppSpec:#: Slash commands this app adds to the employee's chat#: (``{command, description, fill, suggest}``; get_chat_context).commands: Tuple[Mapping[str, Any], ...] = ()+ #: Its icon, for an app whose provider has no entry of its own in the+ #: credential registry (an app from a source).+ icon_ref: Optional[str] = None@propertydef node_types(self) -> frozenset:@@ -243,6 +254,31 @@ def app_for_node_type(node_type: str) -> Optional[AppSpec]:return _by_node_type.get(node_type)+# ----- apps from what an owner saved -----++#: ``source(principal)``: the apps one owner saved (None: the install's).+AppSource = Callable[[Optional[str]], Awaitable[Iterable[AppSpec]]]++_SOURCES: Dict[str, AppSource] = {}+_SOURCE_REGISTRY: IdempotentRegistry[str, AppSource] = IdempotentRegistry("app_source", items=_SOURCES)+++def register_app_source(kind: str, source: AppSource) -> None:+ """Idempotent on re-import; a different source for a kind raises."""+ _SOURCE_REGISTRY.register(kind, source)+++async def source_apps(principal: Optional[str] = None) -> List[AppSpec]:+ """Every source's apps for one owner. A source that fails gives none."""+ apps: List[AppSpec] = []+ for kind, source in _SOURCES.items():+ try:+ apps.extend(await source(principal))+ except Exception:+ logger.warning("Could not read an app source", kind=kind, exc_info=True)+ return apps++def _keys(app: AppSpec) -> Iterable[Tuple[str, int]]:"""(normalized key, preference): the id and name first, aliases after."""yield normalize_name(app.id.replace("_", " ")), 0@@ -269,19 +305,20 @@ def _score(query: str, key: str) -> Optional[Tuple[int, int]]:return None-def resolve_app(name: str, connected: Optional[Sequence[str]] = None) -> Optional[AppSpec]:+def resolve_app(name: str, connected: Optional[Sequence[str]] = None, apps: Optional[Iterable[AppSpec]] = None) -> Optional[AppSpec]:"""The app a free-text name refers to, or None when nothing matches.- Within the best tier a connected app wins, then a name match over an- alias match, then declaration order: "email" picks Gmail when Gmail is- connected and IMAP is not, and "calendar" picks whichever calendar is- connected."""+ ``apps`` are the apps to choose from (``Connections.apps``); the+ registry's when not given. Within the best tier a connected app wins,+ then a name match over an alias match, then declaration order: "email"+ picks Gmail when Gmail is connected and IMAP is not, and "calendar"+ picks whichever calendar is connected."""query = normalize_name(name)if not query:return Noneconnected_ids = set(connected or ())best: Optional[Tuple[Tuple[int, int, int, int, int], AppSpec]] = None- for index, app in enumerate(get_apps().values()):+ for index, app in enumerate(get_apps().values() if apps is None else apps):for key, preference in _keys(app):score = _score(query, key)if score is None:@@ -295,6 +332,7 @@ def resolve_app(name: str, connected: Optional[Sequence[str]] = None) -> Optiona__all__ = ["AUDIENCES","AppRegistryError",+ "AppSource","AppSpec","CONFIG_PATH","NodeTemplate",@@ -306,7 +344,9 @@ __all__ = ["get_app","get_apps","normalize_name",+ "register_app_source","reload_apps","resolve_app","side_effect_rank",+ "source_apps",]diff --git a/server/services/employees/connections.py b/server/services/employees/connections.pyindex c97869e6..03ac018f 100644--- a/server/services/employees/connections.py+++ b/server/services/employees/connections.py@@ -2,16 +2,18 @@Wraps ``services.credential_registry.provider_connection_state`` (the samerules the credential catalogue serves) with a per-request cache, so a team-list that mentions Gmail five times asks the credential store once.+list that mentions Gmail five times asks the credential store once. The+owner's apps (the registry's and the ones they saved, such as custom+connectors; apps.py) are read once per request too."""from __future__ import annotations-from typing import Any, Dict, List, Optional+from typing import Any, Dict, List, Mapping, Optionalfrom core.logging import get_loggerfrom services.credential_registry import get_credential_registry, provider_connection_state-from services.employees.apps import AppSpec, get_apps+from services.employees.apps import AppSpec, get_apps, source_appslogger = get_logger(__name__)@@ -24,6 +26,28 @@ class Connections:self.principal = principalself._registry = get_credential_registry()self._states: Dict[str, Dict[str, Any]] = {}+ self._apps: Optional[Dict[str, AppSpec]] = None+ self._saved: frozenset = frozenset()++ async def apps(self) -> Mapping[str, AppSpec]:+ """Every app the owner's employees can use: the registry's, in its+ order, then the ones the owner saved (apps.source_apps)."""+ if self._apps is None:+ apps = dict(get_apps())+ saved = [app for app in await source_apps(self.principal) if app.id not in apps]+ apps.update((app.id, app) for app in saved)+ self._saved = frozenset(app.id for app in saved)+ self._apps = apps+ return self._apps++ async def app(self, app_id: str) -> Optional[AppSpec]:+ return (await self.apps()).get(app_id)++ async def app_connected(self, app: AppSpec) -> bool:+ """Whether ``app`` can be used now. An app the owner saved exists+ only while it is saved, so it is connected."""+ await self.apps()+ return app.id in self._saved or await self.is_connected(app.provider_id)def provider(self, provider_id: str) -> Optional[Dict[str, Any]]:return self._registry.get_provider(provider_id)@@ -47,8 +71,8 @@ class Connections:return bool((await self.state(provider_id)).get("connected"))async def connected_app_ids(self) -> List[str]:- """Every app whose provider is connected, in registry order."""- return [app.id for app in get_apps().values() if await self.is_connected(app.provider_id)]+ """Every app that is connected, in ``apps`` order."""+ return [app.id for app in (await self.apps()).values() if await self.app_connected(app)]async def app_ref(self, app: AppSpec) -> Dict[str, Any]:"""The ``AppRef`` a summary shows for one app."""@@ -57,8 +81,8 @@ class Connections:"app_id": app.id,"provider_id": app.provider_id,"name": app.name,- "icon_ref": provider.get("icon_ref"),- "connected": await self.is_connected(app.provider_id),+ "icon_ref": provider.get("icon_ref") or app.icon_ref,+ "connected": await self.app_connected(app),"supported": True,}diff --git a/server/services/employees/context.py b/server/services/employees/context.pyindex d6b5fb32..d45081e6 100644--- a/server/services/employees/context.py+++ b/server/services/employees/context.py@@ -14,7 +14,6 @@ from typing import Any, List, Optionalfrom zoneinfo import ZoneInfo, ZoneInfoNotFoundErrorfrom core.logging import get_logger-from services.employees.apps import get_appsfrom services.employees.connections import Connectionslogger = get_logger(__name__)@@ -65,8 +64,8 @@ async def build_setup_prompt_context(connected: List[str] = []available: List[str] = []- for app in get_apps().values():- (connected if await connections.is_connected(app.provider_id) else available).append(app.name)+ for app in (await connections.apps()).values():+ (connected if await connections.app_connected(app) else available).append(app.name)team: List[str] = []try:diff --git a/server/services/employees/graph_index.py b/server/services/employees/graph_index.pyindex 1867ef6c..eaa4cbbe 100644--- a/server/services/employees/graph_index.py+++ b/server/services/employees/graph_index.py@@ -40,8 +40,12 @@ class GraphIndex:canvas_ids: Tuple[str, ...] = ()browser_ids: Tuple[str, ...] = ()gate_ids: Tuple[str, ...] = ()- #: Apps the graph's nodes belong to, in first-seen order.+ #: Apps the graph's nodes belong to by their type, in first-seen order.app_ids: Tuple[str, ...] = ()+ #: Nodes whose app a parameter names (their type's ``app_field``): node+ #: id -> that parameter. The graph does not hold parameters, so their+ #: apps come from :meth:`apps_named`.+ app_params: Mapping[str, str] = field(default_factory=dict)#: Whether the owner can talk to it, and through which agent.talk: TalkState = field(default_factory=lambda: TalkState("unsupported"))@@ -49,6 +53,12 @@ class GraphIndex:def trigger_types(self) -> Tuple[str, ...]:return tuple(self.node_types[node_id] for node_id in self.trigger_ids)+ def apps_named(self, parameters: Mapping[str, Mapping[str, Any]]) -> Tuple[str, ...]:+ """``app_ids``, then the apps the ``app_params`` nodes name in+ ``parameters`` (node id -> saved parameters)."""+ named = (str((parameters.get(node_id) or {}).get(param) or "") for node_id, param in self.app_params.items())+ return tuple(dict.fromkeys([*self.app_ids, *(app_id for app_id in named if app_id)]))+@propertydef has_agent(self) -> bool:return bool(self.agent_ids)@@ -74,6 +84,7 @@ def index_graph(graph: Optional[Mapping[str, Any]]) -> GraphIndex:browsers: List[str] = []gates: List[str] = []app_ids: List[str] = []+ app_params: Dict[str, str] = {}for node in nodes:if not isinstance(node, Mapping):continue@@ -103,6 +114,9 @@ def index_graph(graph: Optional[Mapping[str, Any]]) -> GraphIndex:canvases.append(node_id)if node_type == APPROVAL_GATE_TYPE:gates.append(node_id)+ if getattr(cls, "app_field", None):+ app_params[node_id] = cls.app_field+ continueapp = app_for_node_type(node_type)if app is not None and app.id not in app_ids:app_ids.append(app.id)@@ -116,6 +130,7 @@ def index_graph(graph: Optional[Mapping[str, Any]]) -> GraphIndex:browser_ids=tuple(browsers),gate_ids=tuple(gates),app_ids=tuple(app_ids),+ app_params=app_params,talk=talk_state(graph),)diff --git a/server/services/employees/hire.py b/server/services/employees/hire.pyindex 0cd5ec58..77abe89c 100644--- a/server/services/employees/hire.py+++ b/server/services/employees/hire.py@@ -33,7 +33,7 @@ import asyncioimport hashlibimport jsonfrom datetime import datetime, timedelta, timezone-from typing import Any, Dict, List, Optional, Set+from typing import Any, Dict, Iterable, List, Optional, Setfrom fastapi import WebSocketfrom pydantic import ValidationError@@ -82,9 +82,12 @@ def payload_hash(request: HireEmployeeRequest) -> str:return hashlib.sha256(json.dumps(body, sort_keys=True, separators=(",", ":")).encode()).hexdigest()-def _resolve_apps(request: HireEmployeeRequest, connected: List[str]) -> tuple:+def _resolve_apps(request: HireEmployeeRequest, connected: List[str], apps: Optional[Iterable[AppSpec]] = None) -> tuple:"""(known apps in the order named, unsupported names). Names come from- the hire's apps, the routine's steps, the trigger and the reply app."""+ the hire's apps, the routine's steps, the trigger and the reply app;+ ``apps`` are the owner's (``Connections.apps``), the registry's when+ not given."""+ apps = list(apps) if apps is not None else Nonenames: List[str] = list(request.apps)names += [step.app for step in request.steps if step.app]if request.trigger is not None and request.trigger.app:@@ -94,7 +97,7 @@ def _resolve_apps(request: HireEmployeeRequest, connected: List[str]) -> tuple:known: List[AppSpec] = []unsupported: List[str] = []for name in names:- app = resolve_app(name, connected)+ app = resolve_app(name, connected, apps)if app is None:if name.lower() not in (seen.lower() for seen in unsupported):unsupported.append(name)@@ -334,7 +337,7 @@ async def handle_hire_employee(data: Dict[str, Any], websocket: WebSocket) -> Diconnections = Connections(auth_service, principal=owner)connected = await connections.connected_app_ids()- apps, unsupported = _resolve_apps(request, connected)+ apps, unsupported = _resolve_apps(request, connected, (await connections.apps()).values())row, claim_token = await store.claim_hire(database,owner_id=owner,diff --git a/server/services/employees/setup.py b/server/services/employees/setup.pyindex e446ae81..bfae0096 100644--- a/server/services/employees/setup.py+++ b/server/services/employees/setup.py@@ -136,9 +136,10 @@ async def _resolve_apps(connections: Connections, reply: str) -> Dict[str, Dict[if not names:return {}connected = await connections.connected_app_ids()+ apps = (await connections.apps()).values()refs: Dict[str, Dict[str, Any]] = {}for name in names:- app = resolve_app(name, connected)+ app = resolve_app(name, connected, apps)if app is not None:refs[name.lower()] = {**await connections.app_ref(app), "can_trigger": app.trigger is not None}else:diff --git a/server/services/employees/summaries.py b/server/services/employees/summaries.pyindex e4692de1..70844aa1 100644--- a/server/services/employees/summaries.py+++ b/server/services/employees/summaries.py@@ -40,7 +40,7 @@ from services.deployment.control import serialize_controlfrom services.deployment.restart import LIVE_STATES, pending_changesfrom services.employees import runs, storefrom services.employees.context import SETTINGS_USER_ID-from services.employees.apps import get_app+from services.employees.apps import AppSpec, get_appfrom services.employees.connections import Connectionsfrom services.employees.graph_index import (CHAT_TRIGGER_TYPE,@@ -247,11 +247,33 @@ def _derived_role(graph: GraphIndex) -> str:return "Workflow"-def _app_ids(graph: GraphIndex) -> List[str]:+async def _apps(graph: GraphIndex, parameters: Mapping[str, Mapping[str, Any]], connections: Connections) -> List[AppSpec]:"""The apps the graph's nodes use, hired or not: an app the hire namedbut the graph left out (a tool that sends while they ask first) is not- one to connect, and one added later is."""- return [app_id for app_id in graph.app_ids if get_app(app_id) is not None]+ one to connect, and one added later is. ``parameters`` are the saved+ parameters of the nodes whose app a parameter names (a custom+ connector's); one that is no longer saved is not listed."""+ apps = [await connections.app(app_id) for app_id in graph.apps_named(parameters)]+ return [app for app in apps if app is not None]+++async def _node_parameters(database: Any, graphs: Iterable[GraphIndex]) -> Dict[str, Dict[str, Any]]:+ """The saved parameters of the nodes whose app a parameter names, for+ every graph in one query."""+ from sqlmodel import select++ from models.database import NodeParameter++ ids = [node_id for graph in graphs for node_id in graph.app_params]+ if not ids:+ return {}+ try:+ async with database.get_session() as session:+ rows = (await session.execute(select(NodeParameter).where(NodeParameter.node_id.in_(ids)))).scalars().all()+ except Exception:+ logger.warning("Could not read which apps employees' nodes name", exc_info=True)+ return {}+ return {row.node_id: dict(row.parameters or {}) for row in rows}def _talk(graph: GraphIndex, control_row: Any) -> TalkState:@@ -267,6 +289,8 @@ async def _summary(employee: Any,control_row: Any,*,+ graph: GraphIndex,+ parameters: Mapping[str, Mapping[str, Any]],connections: Connections,needs_ai: bool,pending: int,@@ -275,10 +299,9 @@ async def _summary() -> Dict[str, Any]:from services.workspace_capabilities import workspace_nodes- graph = index_graph(getattr(workflow, "data", None))control = serialize_control(control_row)control.setdefault("workflow_id", workflow.id)- apps = [await connections.app_ref(get_app(app_id)) for app_id in _app_ids(graph)]+ apps = [await connections.app_ref(app) for app in await _apps(graph, parameters, connections)]missing = [ref for ref in apps if not ref["connected"]]status = _status(control)roles = getattr(employee, "node_roles", None) or {}@@ -435,6 +458,8 @@ async def list_employee_summaries(database: Any, *, auth_service: Any, owner_id:pending = await _pending_counts(database, ids)done = await _done_today(database, ids)activations = await _activation_states(database, ids)+ graphs = {workflow.id: index_graph(getattr(workflow, "data", None)) for workflow in workflows}+ parameters = await _node_parameters(database, graphs.values())connections_by_owner = {}summaries = []for workflow in workflows:@@ -447,6 +472,8 @@ async def list_employee_summaries(database: Any, *, auth_service: Any, owner_id:workflow,employees.get(workflow.id),controls.get(workflow.id),+ graph=graphs[workflow.id],+ parameters=parameters,connections=connections,needs_ai=needs_ai,pending=pending.get(workflow.id, 0),@@ -466,10 +493,13 @@ async def _load_one(database: Any, workflow_id: str, *, auth_service: Any) -> Opdone = await _done_today(database, [workflow_id])activations = await _activation_states(database, [workflow_id])connections = Connections(auth_service, principal=employee_owner(workflow, employee))+ graph = index_graph(getattr(workflow, "data", None))summary = await _summary(workflow,employee,control,+ graph=graph,+ parameters=await _node_parameters(database, [graph]),connections=connections,needs_ai=not await connections.has_ai(),pending=pending.get(workflow_id, 0),diff --git a/server/services/plugin/base.py b/server/services/plugin/base.pyindex 07b232d3..2fa01b32 100644--- a/server/services/plugin/base.py+++ b/server/services/plugin/base.py@@ -320,6 +320,12 @@ class BaseNode:# (services/approvals/tool_calls.py).approval: ClassVar[Optional[Any]] = None+ # ``app_field``: for a node whose app a parameter names rather than its+ # type (the custom connector node: ``mcp_connector``), that parameter.+ # It holds the id of an app a plugin's source gives+ # (services/employees/apps.py, ``register_app_source``).+ app_field: ClassVar[Optional[str]] = None+# Set by __init_subclass__: {op_name: OperationSpec}_operations: ClassVar[Dict[str, OperationSpec]] = {}# Flag so concrete subclasses auto-register; abstract kinds don't.diff --git a/server/tests/nodes/test_mcp_connector.py b/server/tests/nodes/test_mcp_connector.pyindex 064128a4..dbb1a4f1 100644--- a/server/tests/nodes/test_mcp_connector.py+++ b/server/tests/nodes/test_mcp_connector.py@@ -391,3 +391,65 @@ class TestTheNode:# Without its binding's word, a call asks first.assert spec.sends({})assert spec.preview(LOOKUP)["details"] == [{"label": "Connector", "value": "Orders"}, {"label": "Tool", "value": "Look up an order"}]+++class TestInHires:+ """Each saved connector is an app a hire can use (services/employees/apps.py)."""++ @pytest.fixture+ def connections(self, auth, monkeypatch):+ from services.employees.connections import Connections++ async def no_other_app(self, provider_id):+ return False++ monkeypatch.setattr(Connections, "is_connected", no_other_app)+ return Connections(auth)++ async def test_each_connector_is_a_connected_app(self, auth, connections, monkeypatch):+ from services.employees.apps import resolve_app+ from services.employees.policy import check_tool++ async with serving(monkeypatch, orders_server()):+ await add()+ app = await connections.app("mcp:orders")+ assert app.name == "Orders" and [tool.type for tool in app.tools] == ["mcpConnector"]+ connected = await connections.connected_app_ids()+ assert connected == ["mcp:orders"]+ assert resolve_app("orders", connected, (await connections.apps()).values()) is app+ ref = await connections.app_ref(app)+ assert ref["connected"] and ref["icon_ref"] == "lucide:Plug"+ # Its calls wait for the owner one by one, so asking first keeps it.+ decision = check_tool("mcpConnector", employee=SimpleNamespace(rules={"ask_first": True}), connected=connected, app=app)+ assert decision.allowed and dict(decision.params) == {"mcp_connector": "mcp:orders"}++ async def test_a_hire_gets_it_and_the_card_names_it(self, auth, connections, monkeypatch):+ from services.employees import hire+ from services.employees.builder import BuildInputs, build_employee_graph+ from services.employees.connections import Connections+ from services.employees.graph_index import index_graph+ from services.employees.hire_request import HireEmployeeRequest+ from services.employees.llm import LLMChoice+ from services.employees.summaries import _apps+ from services.node_allowlist import is_hire_allowed++ async with serving(monkeypatch, orders_server()):+ await add()+ request = HireEmployeeRequest.model_validate({+ "idempotency_key": "k", "job": "Answer questions about orders", "name": "Ola", "role": "Support",+ "apps": ["Orders"], "steps": [{"title": "Answer", "role": "agent"}],+ "rules": {"ask_first": True, "items": []}, "trigger": {"kind": "manual"},+ })+ apps, unsupported = hire._resolve_apps(request, await connections.connected_app_ids(), (await connections.apps()).values())+ assert [app.id for app in apps] == ["mcp:orders"] and unsupported == []+ built = build_employee_graph(BuildInputs(+ workflow_id="7", request=request, apps=apps, llm=LLMChoice(provider="openai", model="gpt-x", local=False), allowed=is_hire_allowed,+ ))+ [tool] = [node for node in built.nodes if node["type"] == "mcpConnector"]+ assert built.parameters[tool["id"]] == {"mcp_connector": "mcp:orders"}+ assert built.app_ids == ["mcp:orders"]+ graph = index_graph({"nodes": built.nodes, "edges": built.edges})+ assert [app.id for app in await _apps(graph, built.parameters, connections)] == ["mcp:orders"]+ # Once it is removed, the card no longer lists it.+ await _handlers.handle_mcp_connector_remove({"ref": "mcp:orders"}, SOCKET)+ assert await _apps(graph, built.parameters, Connections(auth)) == []diff --git a/server/tests/services/employees/test_generate_setup.py b/server/tests/services/employees/test_generate_setup.pyindex 3f82f153..7b535120 100644--- a/server/tests/services/employees/test_generate_setup.py+++ b/server/tests/services/employees/test_generate_setup.py@@ -18,6 +18,7 @@ import pytestimport services.employees # noqa: F401 - registers the handlersfrom services.authz.ws_surface import INTERNAL_SOCKET_HANDLERSfrom services.employees import setup+from services.employees.apps import get_appsfrom services.employees.llm import LLMChoicefrom services.employees.setup_prompt import RETRY_NUDGEfrom services.llm.protocol import LLMResponse, Usage@@ -56,6 +57,12 @@ class FakeConnections:async def connected_app_ids(self):return ["whatsapp"]+ async def apps(self):+ return get_apps()++ async def app_connected(self, app):+ return await self.is_connected(app.provider_id)+async def app_ref(self, app):return {"app_id": app.id, "provider_id": app.provider_id, "name": app.name, "icon_ref": None, "connected": app.provider_id == "whatsapp", "supported": True}diff --git a/server/tests/services/employees/test_hire_handler.py b/server/tests/services/employees/test_hire_handler.pyindex 592a3144..f8c25840 100644--- a/server/tests/services/employees/test_hire_handler.py+++ b/server/tests/services/employees/test_hire_handler.py@@ -16,6 +16,7 @@ import pytestimport nodes # noqa: F401 - registers every plugin for the validatorimport services.employees # noqa: F401 - registers the handlersfrom services.employees import hire, store+from services.employees.apps import get_appsfrom services.employees.hire_request import HireEmployeeRequestfrom services.employees.llm import LLMChoicefrom services.ws_handler_registry import get_ws_handlers@@ -49,6 +50,15 @@ class FakeConnections:async def connected_app_ids(self):return []+ async def apps(self):+ return get_apps()++ async def app(self, app_id):+ return get_apps().get(app_id)++ async def app_connected(self, app):+ return False+async def is_connected(self, provider_id):return False