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/serverordrizzlefrom 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,confirmationandpermissionontool(), so agents and MCP apply the same policy. MCP content goes in thecontentoption ofMcp.init. - Define every tool with the app's one tool base (
toolBuilder), so they all shareauthorize,verifyProofandcontext. - 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 withmcp.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
confirmationof"approval"or"passkey";kindonly says what it does (MCP marks reads read-only). - Throw
ORPCErrorfor 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. approvalProofonly runs in the browser. SetverifyProofon 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. UsecreateMcpProtectedRequestHandler()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
ChatneedsAgents;Mcpneeds neither. Set up only the services the app uses, each with its own tables.Mcp.initwithout adatabaseserves the tools with their default settings, andmcp.apps.setPolicy()andsetEnabled()throw.chat.send()takes amessageorapprovals, never both; anything else is aBAD_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 withNOT_FOUND,get()withnull. - The page
contextmust 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()andmcp.apps.setPolicy()refuse it: a passkey tool can never be allowed. - The app owns the tables. Make
userIdandagentunique 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.streamandagents.startreturnnull, its queued runs fail and its chat refuses messages. Activate agents after deploying them, and turnnullinto 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.executealready picks each turn up once. agents.streamcannot wait for approvals: it throws for an agent with a tool whose policy is "ask". Useagents.runoragents.startfor 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
Agentsin 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
statusto bothChatThreadandChatComposer. ChatComposerkeeps typing available while streaming, but blocks submit untilstatus === "ready".- Tools without a renderer get
ToolCallCardwith theirtitleand an icon for theirkind. A tool without a Tulip title, such as a provider's web search, shows its name (web search) instead: give it a renderer. - Set
labelsandtoolRenderersonce onChatThread;ChatThreadMessagereads them from the thread and takes neither. useAssistantChatcreates its chat once. Mount the chat withkey={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.