|
| 1 | +--- |
| 2 | +title: "MCP Server" |
| 3 | +sidebarTitle: "MCP Server" |
| 4 | +description: "Chat with your agents from any AI coding tool using the Trigger.dev MCP server." |
| 5 | +--- |
| 6 | + |
| 7 | +The Trigger.dev MCP server includes tools for having conversations with your chat agents directly from AI coding tools like Claude Code, Cursor, Windsurf, and others. This lets your AI assistant interact with your agents without writing any code. |
| 8 | + |
| 9 | +## Available tools |
| 10 | + |
| 11 | +| Tool | Description | |
| 12 | +| --- | --- | |
| 13 | +| `list_agents` | List all agents in the current worker | |
| 14 | +| `start_agent_chat` | Start a conversation with an agent | |
| 15 | +| `send_agent_message` | Send a message and get the response | |
| 16 | +| `close_agent_chat` | Close a conversation | |
| 17 | + |
| 18 | +See the [MCP Tools Reference](/mcp-tools#agent-chat-tools) for full details on each tool. |
| 19 | + |
| 20 | +## Typical workflow |
| 21 | + |
| 22 | +<Steps> |
| 23 | + <Step title="List available agents"> |
| 24 | + Ask your AI assistant to list agents in your project. This calls `list_agents` which returns all tasks created with `chat.agent()` or `chat.customAgent()`. |
| 25 | + </Step> |
| 26 | + <Step title="Start a chat"> |
| 27 | + Start a conversation with an agent using `start_agent_chat`. This triggers a run and optionally preloads the agent so it's ready to respond immediately. |
| 28 | + |
| 29 | + If the agent uses `withClientData`, pass the required fields via `clientData`. |
| 30 | + </Step> |
| 31 | + <Step title="Send messages"> |
| 32 | + Send messages with `send_agent_message`. The agent processes each message and returns the full response text, including which tools were used. The agent retains full context across messages in the same chat. |
| 33 | + </Step> |
| 34 | + <Step title="Close the chat"> |
| 35 | + When done, close the conversation with `close_agent_chat`. This signals the agent to exit gracefully. If you skip this step, the agent will close on its own when its idle timeout expires. |
| 36 | + </Step> |
| 37 | +</Steps> |
| 38 | + |
| 39 | +## Example conversation |
| 40 | + |
| 41 | +Here's what a typical MCP conversation with an agent looks like: |
| 42 | + |
| 43 | +``` |
| 44 | +You: List my agents |
| 45 | +
|
| 46 | +AI: Found 3 agents in worker 20250402.12 (dev): |
| 47 | + - support-agent (src/trigger/support.ts) |
| 48 | + - pr-review (src/trigger/pr-review.ts) |
| 49 | + - research (src/trigger/research.ts) |
| 50 | +
|
| 51 | +You: Start a chat with the support agent |
| 52 | +
|
| 53 | +AI: Agent chat started and preloaded. |
| 54 | + - Chat ID: abc-123 |
| 55 | + - Agent: support-agent |
| 56 | + - Run ID: run_xyz |
| 57 | +
|
| 58 | +You: Ask it to look up order #4821 |
| 59 | +
|
| 60 | +AI: I found order #4821. It was placed on March 15 and shipped via |
| 61 | + FedEx (tracking: 7891234). Current status: In Transit, estimated |
| 62 | + delivery March 19. |
| 63 | +
|
| 64 | + Tools used: lookupOrder, getShippingStatus |
| 65 | +
|
| 66 | +You: Close the chat |
| 67 | +
|
| 68 | +AI: Chat abc-123 closed. |
| 69 | +``` |
| 70 | + |
| 71 | +## Setup |
| 72 | + |
| 73 | +If you haven't set up the MCP server yet, see the [MCP Server introduction](/mcp-introduction) for installation and client configuration. |
| 74 | + |
| 75 | +Agent chat tools require: |
| 76 | +- A running dev server (`trigger dev`) or a deployed worker |
| 77 | +- At least one agent defined with `chat.agent()` or `chat.customAgent()` |
| 78 | + |
| 79 | +## How it works |
| 80 | + |
| 81 | +Under the hood, the MCP tools use the same protocol as the [frontend transport](/ai-chat/frontend) and [AgentChat SDK](/ai-chat/server-chat): |
| 82 | + |
| 83 | +1. **`start_agent_chat`** triggers a task run with the `preload` trigger and stores the session (run ID, chat ID) in memory. |
| 84 | +2. **`send_agent_message`** sends the message via the run's input stream and subscribes to the output SSE stream to collect the agent's full response. |
| 85 | +3. **`close_agent_chat`** sends a close signal via the input stream and removes the session. |
| 86 | + |
| 87 | +Sessions are held in-memory within the MCP server process. If the MCP server restarts, active sessions are lost — but the underlying agent runs continue until their idle timeout. |
| 88 | + |
| 89 | +<Note> |
| 90 | + The `get_current_worker` tool also labels agents with `[agent]` in its output, making it easy to identify which tasks are agents even when listing all tasks. |
| 91 | +</Note> |
| 92 | + |
| 93 | +## See also |
| 94 | + |
| 95 | +- [AgentChat SDK](/ai-chat/server-chat) — programmatic server-side access to agents |
| 96 | +- [Sub-Agents](/ai-chat/patterns/sub-agents) — agents calling other agents |
| 97 | +- [MCP Tools Reference](/mcp-tools#agent-chat-tools) — full tool parameter reference |
0 commit comments