Skip to content

Commit ef4af24

Browse files
committed
agent mcp tools docs
1 parent e4dfce8 commit ef4af24

File tree

5 files changed

+153
-2
lines changed

5 files changed

+153
-2
lines changed

docs/ai-chat/mcp.mdx

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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
File renamed without changes.

docs/ai-chat/server-chat.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const researchTool = tool({
175175

176176
This supports single-turn delegation, multi-turn LLM-driven conversations with persistent sub-agents, and cross-turn state that survives snapshot/restore.
177177

178-
See the [Sub-Agents guide](/ai-chat/sub-agents) for the full pattern including multi-turn conversations, cleanup, and what the frontend sees.
178+
See the [Sub-Agents guide](/ai-chat/patterns/sub-agents) for the full pattern including multi-turn conversations, cleanup, and what the frontend sees.
179179

180180
## Additional methods
181181

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@
9292
"ai-chat/backend",
9393
"ai-chat/frontend",
9494
"ai-chat/server-chat",
95-
"ai-chat/sub-agents",
9695
"ai-chat/types",
9796
"ai-chat/features",
9897
"ai-chat/compaction",
9998
"ai-chat/pending-messages",
10099
"ai-chat/background-injection",
100+
"ai-chat/mcp",
101101
{
102102
"group": "Patterns",
103103
"pages": [
104+
"ai-chat/patterns/sub-agents",
104105
"ai-chat/patterns/database-persistence",
105106
"ai-chat/patterns/code-sandbox"
106107
]

docs/mcp-tools.mdx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,56 @@ Check the status of the dev server and view recent output. Shows whether it is s
218218
<Callout type="warning">
219219
The deploy and list_preview_branches tools are not available when the MCP server is running with the `--dev-only` flag. The `--readonly` flag hides deploy, trigger_task, and cancel_run.
220220
</Callout>
221+
222+
## Agent Chat Tools
223+
224+
These tools let you have conversations with [chat agents](/ai-chat/overview) directly from your AI coding tool. See the [Agent MCP guide](/ai-chat/mcp) for a walkthrough.
225+
226+
### list_agents
227+
228+
List all chat agents registered in the current worker. Agents are tasks created with `chat.agent()` or `chat.customAgent()`.
229+
230+
**Example usage:**
231+
- `"What agents are available?"`
232+
- `"List my chat agents"`
233+
234+
### start_agent_chat
235+
236+
Start a conversation with a chat agent. Returns a chat ID for use with `send_agent_message`. Optionally preloads the agent so it initializes before the first message.
237+
238+
**Parameters:**
239+
- `agentId` (required) — The agent task slug (e.g., `"support-agent"`)
240+
- `chatId` (optional) — A custom conversation ID. Auto-generated if omitted
241+
- `clientData` (optional) — Client data to include with every message (e.g., `{ userId: "user_123" }`). Must match the agent's `clientDataSchema` if one is defined
242+
- `preload` (optional, default: `true`) — Whether to preload the agent before the first message
243+
244+
**Example usage:**
245+
- `"Start a chat with the support agent"`
246+
- `"Talk to the pr-review agent with userId abc"`
247+
248+
### send_agent_message
249+
250+
Send a message to an active agent chat and get the full response back. The agent remembers full context from previous messages in the same chat.
251+
252+
**Parameters:**
253+
- `chatId` (required) — The chat ID from `start_agent_chat`
254+
- `message` (required) — The message text to send
255+
256+
**Example usage:**
257+
- `"Tell the agent to review the latest PR"`
258+
- `"Ask it what tools it has available"`
259+
260+
### close_agent_chat
261+
262+
Close an agent chat conversation. The agent exits its loop gracefully. Without this, the agent will close on its own when its idle timeout expires.
263+
264+
**Parameters:**
265+
- `chatId` (required) — The chat ID to close
266+
267+
**Example usage:**
268+
- `"Close the chat"`
269+
- `"End the conversation"`
270+
271+
<Callout type="warning">
272+
The `start_agent_chat`, `send_agent_message`, and `close_agent_chat` tools are write operations and are not available in readonly mode.
273+
</Callout>

0 commit comments

Comments
 (0)