Corsair MCP tools
Agent tool definitions, approval flow, and execution model
Source: src/lib/agent/mcp-tools.ts, src/lib/agent/action-tools.ts, @corsair-dev/mcp.
The agent embeds Corsair MCP tools in-process — no standalone MCP HTTP server required for in-app chat. A separate stdio MCP server (mcp-server.ts) is available for Cursor.
buildAgentMcpTools
function buildAgentMcpTools(
tenant: ReturnType<CorsairInstance["withTenant"]>,
userId: string,
userEmail: string
): ToolSetCalled per request in POST /api/agent/chat with the authenticated user's Corsair tenant.
Tool layers
1. Typed workflow tools (writes + inbox reads)
Defined in src/lib/agent/action-tools.ts. Write tools use needsApproval: true and rich preview cards in agent-tool-approval.tsx.
| Tool | Approval | Purpose |
|---|---|---|
send_email | Yes | Send mail with optional attachments |
schedule_send | Yes | Queue mail for later |
create_calendar_invite | Yes | Event + Google Meet |
reschedule_calendar_event | Yes | Move event by id |
cancel_calendar_event | Yes | Delete event by id |
stage_thread_attachment | No | Stage inbound attachment for send |
search_threads | No | Gmail query + optional lane filter |
list_calendar_events | No | Events in date range |
2. Corsair discovery tools (read-only)
From buildCorsairToolDefs() with an explicit allowlist (corsair-tool-allowlist.ts):
| Tool | Purpose |
|---|---|
list_operations | Discover Gmail/Calendar API paths |
get_schema | Inspect schema for a path from list_operations |
Not exposed: run_script, corsair_setup — writes use typed tools above.
Execution flow
- User sends message →
POST /api/agent/chat createInboxAgentStream()runsstreamTextwith merged tools- Agent may call discovery tools and read-only workflow tools freely
- On
send_email,create_calendar_invite, etc. → stream pauses for approval - User approves →
execute()runs against Corsair tenant - Stream continues with tool result
Error handling
If Corsair returns isError: true, toolResultToOutput throws with the text content — surfaced via agentStreamErrorHandler.
System prompt
src/lib/agent/system-prompt.ts instructs the model to prefer typed tools for writes and search_threads / list_calendar_events for reads.
Security model
| Property | Value |
|---|---|
| Tenant isolation | Tools scoped to userId tenant only |
| Credentials | User's OAuth tokens via Corsair |
| Approval gate | Typed write tools require explicit user consent |
| Timeout | 60s max duration on chat route |
Example agent prompt
Send a calendar invite to friend@corsair.dev at 9 AM next Thursday
and email him saying I look forward to it.Expected tool sequence:
create_calendar_invite(approval)send_email(approval)
Related
- Agent chat user guide
- API routes — /api/agent/chat
- MCP server (Cursor) — repo
docs/mcp-server.md