Tulip Logo IconTulip
Reference

Errors and Gotchas

Common integration mistakes when building with agents, runs, approvals and chat.

Server/client boundaries

  • Do not import agents/server, chat/server, tools/server, mcp/server or drizzle from client components.
  • Import types in client code from @tulip-systems/ai/types, not from a server entry.
  • Keep actual tool execution on the server.

Tool design

  • Put kind, confirmation and permission on tool(), so agents and MCP apply the same policy. MCP content goes in the content option of Mcp.init.
  • Define every tool with the app's one tool base (toolBuilder), so they all share authorize, verifyProof and context.
  • Every tool is refused when it runs without a tool call, also tools with permission: false. Run agents through the services (chat.send, agents.run, agents.stream, agents.start), which build it, and serve MCP tools with mcp.server().
  • Pass Tulip definitions to defineAgent() as they are; it is the only way to give an agent Tulip tools.
  • Don't write "the user approves this" in a tool's description: tools with a confirmation get "The user approves every call." added on their own.
  • Give every tool that changes data a confirmation of "approval" or "passkey"; kind only says what it does (MCP marks reads read-only).
  • Throw ORPCError for errors the model should read. Other errors are logged and replaced by a generic message, so a tool never leaks a database or provider error.
  • approvalProof only runs in the browser. Set verifyProof on the tool base to check the proof on the server; without it, every approval of a passkey tool is refused.
  • Add read/search tools before write tools.
  • Approvals are not a substitute for good agent instructions.

MCP

  • requireMcpAuth() reads the issuer from the auth base URL; with a base URL resolved per request it fails with a 500 instead of a 401. Use createMcpProtectedRequestHandler() with constants.
  • Access tokens stay valid after the user disconnects an app. Check the user's consent for the token's client on every request.
  • Some apps share one OAuth client id across users. Key per-app settings on user and client.
  • Tools with confirmation: "passkey" are always refused over MCP: an MCP client cannot give a proof.

Services

  • Chat needs Agents; Mcp needs neither. Set up only the services the app uses, each with its own tables.
  • Mcp.init without a database serves the tools with their default settings, and mcp.apps.setPolicy() and setEnabled() throw.
  • chat.send() takes a message or approvals, never both; anything else is a BAD_REQUEST.
  • Every chat method is scoped to the user you pass, so pass the user from the session. send() answers a chat id of another user with NOT_FOUND, get() with null.
  • The page context must be a JSON object of at most 16,000 characters.
  • "Approve for this chat" only applies to tools with confirmation: "approval". Approvals with a proof hold for one call.
  • A stored setting the tool does not offer falls back to the default, and agents.setPolicy() and mcp.apps.setPolicy() refuse it: a passkey tool can never be allowed.
  • The app owns the tables. Make userId and agent unique together in the MCP app settings table; the Drizzle adapter upserts on them.
  • Agent names must be unique in Agents.init({ agents }); it refuses two agents with the same name. Background runs find their agent by that name.
  • A new or turned off agent does not run: agents.run, agents.stream and agents.start return null, its queued runs fail and its chat refuses messages. Activate agents after deploying them, and turn null into a clear message in the procedure.
  • Do not deduplicate queue jobs by run id: a run is queued again when it continues after its approvals, and agents.runs.execute already picks each turn up once.
  • agents.stream cannot wait for approvals: it throws for an agent with a tool whose policy is "ask". Use agents.run or agents.start for such agents.
  • An agent running as itself with a tool that asks first needs identity.approvers, or its runs fail with "needs an approval, but has no approvers".
  • Call agents.approvals.expire() from a scheduled job, or approvals nobody decides keep their runs waiting.
  • Starting an agent from an event listener can import Agents in a cycle with the event bus, when its tools publish events. Import it inside the listener.

Agent behavior

  • Start with one agent with the tools it needs; add an agent only for its own permissions, trigger, output or focus.
  • Do not let agents mutate business records without explicit user intent.
  • Make duplicate checks and lookup steps part of the instructions.
  • Give agents that run as themselves only the grants of their job.

Chat UI

  • Pass status to both ChatThread and ChatComposer.
  • ChatComposer keeps typing available while streaming, but blocks submit until status === "ready".
  • Tools without a renderer get ToolCallCard with their title and an icon for their kind. A tool without a Tulip title, such as a provider's web search, shows its name (web search) instead: give it a renderer.
  • Set labels and toolRenderers once on ChatThread; ChatThreadMessage reads them from the thread and takes neither.
  • useAssistantChat creates its chat once. Mount the chat with key={chatId} to switch chats.

Streaming

  • Always forward abort signals from the request/RPC layer.
  • Keep server handlers focused on transport; put domain behavior in agents and tools.
  • If a stream fails, inspect provider errors and tool exceptions before changing the UI.

Heuristic

If a bug feels behavioral, inspect the agent instructions and tool descriptions first.

If a bug feels data-related, inspect the tool implementation and schemas.

If a bug feels visual, inspect the client tool renderer and chat composition.

On this page