---
title: "MCP Server"
sidebarTitle: "MCP Server"
description: "Chat with your agents from any AI coding tool using the Trigger.dev MCP server."
---

import RcBanner from "/snippets/ai-chat-rc-banner.mdx";

<RcBanner />

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.

## Available tools

| Tool | Description |
| --- | --- |
| `list_agents` | List all agents in the current worker |
| `start_agent_chat` | Start a conversation with an agent |
| `send_agent_message` | Send a message and get the response |
| `close_agent_chat` | Close a conversation |

See the [MCP Tools Reference](/mcp-tools#agent-chat-tools) for full details on each tool.

## Typical workflow

<Steps>
  <Step title="List available agents">
    Ask your AI assistant to list agents in your project. This calls `list_agents` which returns all tasks created with [`chat.agent()`](/ai-chat/backend#chat-agent) or [`chat.customAgent()`](/ai-chat/custom-agents).
  </Step>
  <Step title="Start a chat">
    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.

    If the agent uses `withClientData`, pass the required fields via `clientData`.
  </Step>
  <Step title="Send messages">
    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.
  </Step>
  <Step title="Close the chat">
    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.
  </Step>
</Steps>

## Example conversation

Here's what a typical MCP conversation with an agent looks like:

```
You: List my agents

AI: Found 3 agents in worker 20250402.12 (dev):
    - support-agent (src/trigger/support.ts)
    - pr-review (src/trigger/pr-review.ts)
    - research (src/trigger/research.ts)

You: Start a chat with the support agent

AI: Agent chat started and preloaded.
    - Chat ID: abc-123
    - Agent: support-agent
    - Run ID: run_xyz

You: Ask it to look up order #4821

AI: I found order #4821. It was placed on March 15 and shipped via
    FedEx (tracking: 7891234). Current status: In Transit, estimated
    delivery March 19.

    Tools used: lookupOrder, getShippingStatus

You: Close the chat

AI: Chat abc-123 closed.
```

## Setup

If you haven't set up the MCP server yet, see the [MCP Server introduction](/mcp-introduction) for installation and client configuration.

Agent chat tools require:
- A running dev server (`trigger dev`) or a deployed worker
- At least one agent defined with [`chat.agent()`](/ai-chat/backend#chat-agent) or [`chat.customAgent()`](/ai-chat/custom-agents)

## How it works

Under the hood, the MCP tools use the same protocol as the [frontend transport](/ai-chat/frontend) and [AgentChat SDK](/ai-chat/server-chat):

1. **`start_agent_chat`** triggers a task run with the `preload` trigger and stores the session (run ID, chat ID) in memory.
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.
3. **`close_agent_chat`** sends a close signal via the input stream and removes the session.

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.

<Note>
  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.
</Note>

## See also

- [AgentChat SDK](/ai-chat/server-chat) — programmatic server-side access to agents
- [Sub-Agents](/ai-chat/patterns/sub-agents) — agents calling other agents
- [MCP Tools Reference](/mcp-tools#agent-chat-tools) — full tool parameter reference
