Skip to content
MSO CloudDocumentation

Expose assistant and MCP tools

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_id
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_org_settings; 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 /events
Audit One audit-log row per call Per route

The contract#

  • ChatToolDef and resolveChatTool in apps/web/src/server/chat/tools/factory.ts: name, description, inputSchema (Zod), optional databaseScope, resolve(ctx, input). A throw becomes { ok: false, error } through publicToolErrorMessage (apps/web/src/server/public-tool-error.ts).
  • CHAT_TOOL_DEFS in apps/web/src/server/chat/tools.ts: the core and marketing tools. GET /api/mcp/tools reflects this list as JSON Schema; POST /api/mcp/exec runs 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 are UCIP_API_URL and UCIP_API_TOKEN, the server name yng-ucip, version 0.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_DEFS reaches 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 buildChatTools behind 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.ts throws at module load if any of those names is also in CHAT_TOOL_DEFS, so the list can never serve third-party or customer-discussion data over MCP.

Add one#

  1. Write the tool in apps/web/src/server/chat/tools/<family>.ts (or tools.ts for a core metric): a named Zod input, resolve that uses the shared metric formulas and Vietnam-time buckets, never an invented number.
  2. Choose exposure. Both surfaces: append to CHAT_TOOL_DEFS. Assistant only, behind a plane or plugin gate: add it in buildChatTools, add the gate flag to ChatToolContext and set it where the chat route builds the context, and list the name in the family's *_TOOL_NAMES.
  3. Add the tool's guidance to the family prompt file (<family>-prompt.ts) so the model knows when to call it.
  4. 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 in listMcpTools().
  5. 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_suspended or issuer_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 locale vi.

Where it stops#

  • The MCP execution context sets none of the gate flags (marketingEnabled, ecomEnabled and the rest), while the listing is not gated per organization. The marketing tools check ctx.marketingEnabled first (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.