On this page
The data assistant and the MCP server share one list of tools. A tool is a Zod input schema, a description and a resolve function that runs under the organization's row-level security. Below: adding a tool and the two ways it can reach an outside client.
When to use#
Add a tool when the assistant (or an MCP client such as Claude Desktop or Claude Code) needs a new read-only question answered from an organization's own data. Do not use it to hand an outside system raw data: that is Platform API and events (OIDC tokens, one scope per plane). MCP is the second external auth model, and the two are different:
| Property | MCP bridge | Platform API |
|---|---|---|
| Credential | Opaque yngmcp_ token, stored as a SHA-256 hash, pinned to one organization |
RFC 9068 JWT, ES256, 600 s at most, one org_ |
| Minted by | A super admin in the console ("MCP tokens"); default 90 days, at most 365 | The issuer, after an entitlement check |
| Authorization | The issuer must still hold organization-wide access and manage_; optional IP allowlist |
One scope per data plane |
| Limits | 30 calls a minute per address and per token on exec; 60 a minute per address on tools |
600 events a minute per organization and client on POST / |
| Audit | One audit-log row per call | Per route |
The contract#
ChatToolDefandresolveChatToolinapps/web/src/server/chat/tools/factory.ts:name,description,inputSchema(Zod), optionaldatabaseScope,resolve(ctx, input). A throw becomes{ ok: false, error }throughpublicToolErrorMessage(apps/web/src/server/public-tool-error.ts).CHAT_TOOL_DEFSinapps/web/src/server/chat/tools.ts: the core and marketing tools.GET /api/mcp/toolsreflects this list as JSON Schema;POST /api/mcp/execruns one tool (apps/web/src/app/api/mcp/{tools,exec}/route.ts,apps/web/src/server/mcp/{auth,exec}.ts).- The bridge:
apps/mcp-server/src/index.ts, a stdio program that fetches the list once at start. Its environment names areUCIP_API_URLandUCIP_API_TOKEN, the server nameyng-ucip, version0.1.0: legacy identifiers kept for client compatibility. - Gate flags on
ChatToolContext(factory.ts) decide which tools the assistant offers per organization.
How registration works#
- A tool in
CHAT_TOOL_DEFSreaches both the assistant and every MCP client at its next bridge restart. - A gated family (market intelligence, audience, social trends, organization datasets) is added inside
buildChatToolsbehind a context flag and its names are listed in*_TOOL_NAMES(apps/web/src/server/chat/tools/{market,audience,social-trends,org-datasets}-prompt.ts).apps/web/src/server/mcp/exec.tsthrows at module load if any of those names is also inCHAT_TOOL_DEFS, so the list can never serve third-party or customer-discussion data over MCP.
Add one#
- Write the tool in
apps/web/src/server/chat/tools/<family>.ts(ortools.tsfor a core metric): a named Zod input,resolvethat uses the shared metric formulas and Vietnam-time buckets, never an invented number. - Choose exposure. Both surfaces: append to
CHAT_TOOL_DEFS. Assistant only, behind a plane or plugin gate: add it inbuildChatTools, add the gate flag toChatToolContextand set it where the chat route builds the context, and list the name in the family's*_TOOL_NAMES. - Add the tool's guidance to the family prompt file (
<family>-prompt.ts) so the model knows when to call it. - Add tests: gating (
apps/web/src/__tests__/chat-*-gating.test.ts), failure text (public-tool-error.test.ts); for an MCP-visible tool also check it appears inlistMcpTools(). - Restart bridges to see the tool; token minting, revocation and the client setup are in MCP server.
Guards#
apps/web/src/server/mcp/exec.ts (load-time exclusion check); tests apps/web/src/__tests__/{mcp-auth-cidr,mcp-auth-pre-context,mcp-exec-token-rate-limit,mcp-startup-logging}.test.ts, chat-ecom-gating, chat-core-metric-gating, chat-social-trend-gating, chat-audience-gating, chat-org-datasets (same directory); rule §58 in .claude/rules/security-tenancy.md; the AI boundary audit ai-resolver-single-source.py for anything that calls a model.
Operating it#
- Auth failures return
invalid_token,revoked(410),ip_not_allowed,org_suspendedorissuer_scope_denied(403); a revoked token fails on the next call. - Rate-limited calls answer 429 with
retryAfterSec. - The execution context is a service identity with a nil user id,
isSuperAdmin: false, no brand and localevi.
Where it stops#
- The MCP execution context sets none of the gate flags (
marketingEnabled,ecomEnabledand the rest), while the listing is not gated per organization. The marketing tools checkctx.marketingEnabledfirst (apps/web/src/server/chat/tools/marketing.ts), so over MCP they answer their "no data" message whatever the organization has connected (read from code, not run). The product page says each marketing tool appears only when its data is connected; that is true of the assistant, not of the MCP list. - No write tools: every tool reads.
- The bridge is not part of any production container; each client runs its own copy (Project status).
- One organization per token; no per-tool scopes.