Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
275 changes: 263 additions & 12 deletions docs/building-with-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,272 @@ sidebarTitle: "Overview"
description: "Tools and resources for building Trigger.dev projects with AI coding assistants."
---

We provide tools to help you build Trigger.dev projects with AI coding assistants. We recommend using them for the best developer experience.
## Quick setup

<CardGroup cols={1}>
<Card title="MCP Server" icon="sparkles" href="/mcp-introduction">
Give your AI assistant direct access to Trigger.dev tools - search docs, trigger tasks, deploy projects, and monitor runs.
We provide multiple tools to help AI coding assistants write correct Trigger.dev code. Use one or all of them for the best developer experience.


<Steps>

<Step title="Install the MCP Server">
Give your AI assistant direct access to Trigger.dev tools — search docs, trigger tasks, deploy projects, and monitor runs. Works with Claude Code, Cursor, Windsurf, VS Code (Copilot), and Zed.

```bash
npx trigger.dev@latest install-mcp
```

[Learn more →](/mcp-introduction)
</Step>

<Step title="Install Skills">
Portable instruction sets that teach any AI coding assistant Trigger.dev best practices. Works with Claude Code, Cursor, Windsurf, VS Code (Copilot), and any tool that supports the [Agent Skills standard](https://agentskills.io).

```bash
npx skills add triggerdotdev/skills
```

[Learn more →](/skills)
</Step>

<Step title="Install Agent Rules">
Comprehensive rule sets installed directly into your AI client's config files. Works with Cursor, Claude Code, VS Code (Copilot), Windsurf, Gemini CLI, Cline, and more. Claude Code also gets a dedicated subagent for hands-on help.

```bash
npx trigger.dev@latest install-rules
```

[Learn more →](/mcp-agent-rules)
</Step>

</Steps>

## Skills vs Agent Rules vs MCP

Not sure which tool to use? Here's how they compare:

| | **Skills** | **Agent Rules** | **MCP Server** |
|:--|:-----------|:----------------|:---------------|
| **What it does** | Drops skill files into your project | Installs rule sets into client config | Runs a live server your AI connects to |
| **Installs to** | `.claude/skills/`, `.cursor/skills/`, etc. | `.cursor/rules/`, `CLAUDE.md`, `AGENTS.md`, etc. | `mcp.json`, `~/.claude.json`, etc. |
| **Updates** | Re-run `npx skills add` | Re-run `npx trigger.dev@latest install-rules` or auto-prompted on `trigger dev` | Always latest (uses `@latest`) |
| **Best for** | Teaching patterns and best practices | Comprehensive code generation guidance | Live project interaction (deploy, trigger, monitor) |
| **Works offline** | Yes | Yes | No (calls Trigger.dev API) |

**Our recommendation:** Install all three. Skills and Agent Rules teach your AI *how* to write code. The MCP Server lets it *do things* in your project.

## Project-level context snippet

If you prefer a lightweight/passive approach, paste the snippet below into a context file at the root of your project. Different AI tools read different files:

| File | Read by |
|:-----|:--------|
| `CLAUDE.md` | Claude Code |
| `AGENTS.md` | OpenAI Codex, Jules, OpenCode |
| `.cursor/rules/*.md` | Cursor |
| `.github/copilot-instructions.md` | GitHub Copilot |
| `CONVENTIONS.md` | Windsurf, Cline, and others |

Create the file that matches your AI tool (or multiple files if your team uses different tools) and paste the snippet below. This gives the AI essential Trigger.dev context without installing anything.

<Accordion title="Copy the snippet">

````markdown
# Trigger.dev rules

## Imports

Always import from `@trigger.dev/sdk` — never from `@trigger.dev/sdk/v3` or use the deprecated `client.defineJob` pattern.

## Task pattern

Every task must be exported. Use `task()` from `@trigger.dev/sdk`:

```ts
import { task } from "@trigger.dev/sdk";

export const myTask = task({
id: "my-task",
retry: {
maxAttempts: 3,
factor: 1.8,
minTimeoutInMs: 500,
maxTimeoutInMs: 30_000,
},
run: async (payload: { url: string }) => {
// No timeouts — runs can take as long as needed
return { success: true };
},
});
```

## Triggering tasks

From your backend (Next.js route, Express handler, etc.):

```ts
import type { myTask } from "./trigger/my-task";
import { tasks } from "@trigger.dev/sdk";

// Fire and forget
const handle = await tasks.trigger<typeof myTask>("my-task", { url: "https://example.com" });

// Batch trigger (up to 1,000 items)
const batchHandle = await tasks.batchTrigger<typeof myTask>("my-task", [
{ payload: { url: "https://example.com/1" } },
{ payload: { url: "https://example.com/2" } },
]);
```

### From inside other tasks

```ts
export const parentTask = task({
id: "parent-task",
run: async (payload) => {
// Fire and forget
await childTask.trigger({ data: "value" });

// Wait for result — returns a Result object, NOT the output directly
const result = await childTask.triggerAndWait({ data: "value" });
if (result.ok) {
console.log(result.output); // The actual return value
} else {
console.error(result.error);
}

```bash
npx trigger.dev@latest install-mcp
```
// Or use .unwrap() to get output directly (throws on failure)
const output = await childTask.triggerAndWait({ data: "value" }).unwrap();
},
});
```

> Never wrap `triggerAndWait` or `batchTriggerAndWait` in `Promise.all` — this is not supported.

## Error handling

```ts
import { task, retry, AbortTaskRunError } from "@trigger.dev/sdk";

export const resilientTask = task({
id: "resilient-task",
retry: { maxAttempts: 5 },
run: async (payload) => {
// Permanent error — skip retrying
if (!payload.isValid) {
throw new AbortTaskRunError("Invalid payload, will not retry");
}

// Retry a specific block (not the whole task)
const data = await retry.onThrow(
async () => await fetchExternalApi(payload),
{ maxAttempts: 3 }
);

return data;
},
});
```

## Schema validation

Use `schemaTask` with Zod for payload validation:

```ts
import { schemaTask } from "@trigger.dev/sdk";
import { z } from "zod";

export const processVideo = schemaTask({
id: "process-video",
schema: z.object({ videoUrl: z.string().url() }),
run: async (payload) => {
// payload is typed and validated
},
});
```

## Waits

Use `wait.for` for delays, `wait.until` for dates, and `wait.forToken` for external callbacks:

```ts
import { wait } from "@trigger.dev/sdk";
await wait.for({ seconds: 30 });
await wait.until({ date: new Date("2025-01-01") });
```

## Configuration

`trigger.config.ts` lives at the project root:

```ts
import { defineConfig } from "@trigger.dev/sdk/build";

export default defineConfig({
project: "<your-project-ref>",
dirs: ["./trigger"],
});
```

## Common mistakes

1. **Forgetting to export tasks** — every task must be a named export
2. **Importing from `@trigger.dev/sdk/v3`** — this is the old v3 path; always use `@trigger.dev/sdk`
3. **Using `client.defineJob()`** — this is the deprecated v2 API
4. **Calling `task.trigger()` directly** — use `tasks.trigger<typeof myTask>("task-id", payload)` from your backend
5. **Using `triggerAndWait` result as output** — it returns a `Result` object; check `result.ok` then access `result.output`, or use `.unwrap()`
6. **Wrapping waits/triggerAndWait in `Promise.all`** — not supported in Trigger.dev tasks
7. **Adding timeouts to tasks** — tasks have no built-in timeout; use `maxDuration` in config if needed
````

</Accordion>

## llms.txt

We also publish machine-readable documentation for LLM consumption:

- [trigger.dev/docs/llms.txt](https://trigger.dev/docs/llms.txt) — concise overview
- [trigger.dev/docs/llms-full.txt](https://trigger.dev/docs/llms-full.txt) — full documentation

These follow the [llms.txt standard](https://llmstxt.org) and can be fed directly into any LLM context window.


## Troubleshooting

<AccordionGroup>

<Accordion title="AI keeps generating old v2/v3 code">
Install [Agent Rules](/mcp-agent-rules) or [Skills](/skills) — they override the outdated patterns in the AI's training data. The [context snippet](#project-level-context-snippet) above is a quick alternative.
</Accordion>

<Accordion title="MCP server won't connect">
1. Make sure you've restarted your AI client after adding the config
2. Run `npx trigger.dev@latest install-mcp` again — it will detect and fix common issues
3. Check that `npx trigger.dev@latest mcp` runs without errors in your terminal
4. See the [MCP introduction](/mcp-introduction) for client-specific config details
</Accordion>

<Accordion title="Which tool should I install?">
All three if possible. If you can only pick one:
- **Agent Rules** if you want the broadest code generation improvement
- **Skills** if you use multiple AI tools and want a single install
- **MCP Server** if you need to trigger tasks, deploy, and search docs from your AI
</Accordion>

</AccordionGroup>

## Next steps

<CardGroup cols={2}>
<Card title="MCP Server" icon="sparkles" href="/mcp-introduction">
Install and configure the MCP Server for live project interaction.
</Card>
<Card title="Skills" icon="wand-magic-sparkles" href="/skills">
Portable instruction sets that teach any AI coding assistant Trigger.dev best practices for writing tasks, configs, and more.

```bash
npx skills add triggerdotdev/skills
```
Portable instruction sets for any AI coding assistant.
</Card>
<Card title="Agent Rules" icon="scroll" href="/mcp-agent-rules">
Comprehensive rule sets installed into your AI client.
</Card>
<Card title="Writing tasks" icon="code" href="/tasks/overview">
Learn the task patterns your AI assistant will follow.
</Card>
</CardGroup>
5 changes: 3 additions & 2 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
"building-with-ai",
{
"group": "MCP Server",
"pages": ["mcp-introduction", "mcp-tools", "mcp-agent-rules"]
"pages": ["mcp-introduction", "mcp-tools"]
},
"skills"
"skills",
"mcp-agent-rules"
]
},
{
Expand Down
23 changes: 19 additions & 4 deletions docs/mcp-agent-rules.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
---
title: "Agent rules"
sidebarTitle: "Agent rules"
description: "Learn how to use the Trigger.dev agent rules with the MCP server"
description: "Install Trigger.dev agent rules to guide AI assistants toward correct, up-to-date code patterns."
---

## What are Trigger.dev agent rules?

Trigger.dev agent rules are comprehensive instruction sets that guide AI assistants to write optimal Trigger.dev code. These rules ensure your AI assistant understands best practices, current APIs, and recommended patterns when working with Trigger.dev projects.

<Note>
Agent Rules are one of three AI tools we provide. You can also install [Skills](/skills) for portable cross-editor instruction sets or the [MCP Server](/mcp-introduction) for live project interaction. See the [comparison table](/building-with-ai#skills-vs-agent-rules-vs-mcp) for details.
</Note>

## Installation

Install the agent rules with the following command:
Expand Down Expand Up @@ -112,6 +116,17 @@ npx trigger.dev@latest install-rules

## Next steps

- [Install the MCP server](/mcp-introduction) for complete Trigger.dev integration
- [Explore MCP tools](/mcp-tools) for project management and task execution

<CardGroup cols={2}>
<Card title="Skills" icon="wand-magic-sparkles" href="/skills">
Portable instruction sets that work across all AI coding assistants.
</Card>
<Card title="MCP Server" icon="sparkles" href="/mcp-introduction">
Give your AI assistant direct access to Trigger.dev tools and APIs.
</Card>
<Card title="Complete AI setup" icon="layer-group" href="/building-with-ai">
See all AI tools and how they compare.
</Card>
<Card title="Writing tasks" icon="code" href="/tasks/overview">
Learn the task patterns that agent rules teach your AI assistant.
</Card>
</CardGroup>
12 changes: 11 additions & 1 deletion docs/mcp-introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,14 @@ Once installed, you can start using the MCP server by asking your AI assistant q

## Next Steps

- [Explore available MCP tools](/mcp-tools)
<CardGroup cols={2}>
<Card title="MCP Tools" icon="wrench" href="/mcp-tools">
Explore all available MCP tools for managing your projects.
</Card>
<Card title="Skills" icon="wand-magic-sparkles" href="/skills">
Portable instruction sets that teach AI assistants Trigger.dev patterns.
</Card>
<Card title="Agent Rules" icon="scroll" href="/mcp-agent-rules">
Install comprehensive rule sets directly into your AI client.
</Card>
</CardGroup>
Loading