@mastra/mcp-docs-server 1.2.15 → 1.2.16-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/.docs/docs/agents/agent-approval.md +5 -5
  2. package/.docs/docs/agents/overview.md +4 -4
  3. package/.docs/docs/browser/overview.md +1 -1
  4. package/.docs/docs/capabilities/channels.md +5 -5
  5. package/.docs/docs/capabilities/subagents.md +1 -1
  6. package/.docs/docs/connections/overview.md +1 -1
  7. package/.docs/docs/datasets/overview.md +1 -1
  8. package/.docs/docs/deployment/cloud-providers.md +4 -2
  9. package/.docs/docs/deployment/mastra-server.md +1 -1
  10. package/.docs/docs/deployment/monorepo.md +1 -1
  11. package/.docs/docs/deployment/overview.md +4 -1
  12. package/.docs/docs/deployment/sandbox.md +1 -1
  13. package/.docs/docs/deployment/web-framework.md +1 -1
  14. package/.docs/docs/deployment/workers.md +248 -2
  15. package/.docs/docs/evals/overview.md +1 -1
  16. package/.docs/docs/evals/quick-checks.md +1 -1
  17. package/.docs/docs/guides/multi-agent-systems.md +1 -1
  18. package/.docs/docs/harness/agent-controller.md +5 -5
  19. package/.docs/docs/harness/overview.md +1 -1
  20. package/.docs/docs/index.md +3 -3
  21. package/.docs/docs/long-running-agents/signal-providers.md +2 -2
  22. package/.docs/docs/mastra-platform/deploy.md +1 -1
  23. package/.docs/docs/mastra-platform/observability.md +63 -18
  24. package/.docs/docs/mastra-platform/overview.md +1 -1
  25. package/.docs/docs/mcp/overview.md +1 -1
  26. package/.docs/docs/memory/working-memory.md +1 -1
  27. package/.docs/docs/observability/integrations/exporters/mastra-storage.md +2 -2
  28. package/.docs/docs/observability/logging.md +1 -1
  29. package/.docs/docs/observability/metrics/overview.md +1 -1
  30. package/.docs/docs/observability/overview.md +1 -5
  31. package/.docs/docs/observability/tracing/overview.md +3 -6
  32. package/.docs/docs/server/auth/workers.md +1 -1
  33. package/.docs/docs/server/auth.md +5 -5
  34. package/.docs/docs/server/mastra-client.md +1 -1
  35. package/.docs/docs/server/mastra-server.md +1 -1
  36. package/.docs/docs/storage/overview.md +7 -6
  37. package/.docs/docs/workflows/human-in-the-loop.md +2 -2
  38. package/.docs/docs/workflows/overview.md +2 -2
  39. package/.docs/docs/workspace/lsp.md +27 -0
  40. package/.docs/docs/workspace/sandbox.md +11 -12
  41. package/.docs/integrations/agentic-ui/ai-sdk-ui.md +1 -1
  42. package/.docs/integrations/agentic-ui/assistant-ui.md +1 -1
  43. package/.docs/integrations/agentic-ui/copilotkit.md +1 -1
  44. package/.docs/integrations/agentic-ui/openui.md +1 -1
  45. package/.docs/integrations/databases/postgresql.md +8 -8
  46. package/.docs/integrations/deploy/amazon-ec2.md +2 -2
  47. package/.docs/integrations/deploy/aws-bedrock-agentcore.md +1 -1
  48. package/.docs/integrations/deploy/aws-lambda.md +2 -2
  49. package/.docs/integrations/deploy/azure-app-services.md +2 -2
  50. package/.docs/integrations/deploy/cloudflare.md +2 -2
  51. package/.docs/integrations/deploy/digital-ocean.md +2 -2
  52. package/.docs/integrations/deploy/inngest.md +1 -1
  53. package/.docs/integrations/deploy/kubernetes.md +2 -3
  54. package/.docs/integrations/deploy/netlify.md +2 -2
  55. package/.docs/integrations/deploy/temporal.md +1 -1
  56. package/.docs/integrations/deploy/vercel.md +2 -2
  57. package/.docs/integrations/file-storage/agentfs.md +1 -1
  58. package/.docs/integrations/file-storage/amazon-s3.md +1 -1
  59. package/.docs/integrations/file-storage/archil.md +1 -1
  60. package/.docs/integrations/file-storage/azure-blob.md +1 -1
  61. package/.docs/integrations/file-storage/google-cloud-storage.md +1 -1
  62. package/.docs/integrations/file-storage/google-drive.md +1 -1
  63. package/.docs/integrations/file-storage/mesa.md +1 -1
  64. package/.docs/integrations/file-storage/vercel-files.md +1 -1
  65. package/.docs/integrations/frameworks/astro.md +1 -1
  66. package/.docs/integrations/frameworks/electron.md +1 -1
  67. package/.docs/integrations/frameworks/express.md +1 -1
  68. package/.docs/integrations/frameworks/hono.md +1 -1
  69. package/.docs/integrations/frameworks/nestjs.md +1 -1
  70. package/.docs/integrations/frameworks/next-js.md +1 -1
  71. package/.docs/integrations/frameworks/nuxt.md +1 -1
  72. package/.docs/integrations/frameworks/sveltekit.md +1 -1
  73. package/.docs/integrations/frameworks/vite-react.md +1 -1
  74. package/.docs/integrations/sandboxes/agentcore.md +1 -1
  75. package/.docs/integrations/sandboxes/apple-container.md +1 -1
  76. package/.docs/integrations/sandboxes/blaxel.md +1 -1
  77. package/.docs/integrations/sandboxes/daytona.md +1 -1
  78. package/.docs/integrations/sandboxes/docker.md +1 -1
  79. package/.docs/integrations/sandboxes/e2b.md +1 -1
  80. package/.docs/integrations/sandboxes/modal.md +1 -1
  81. package/.docs/integrations/sandboxes/railway.md +1 -1
  82. package/.docs/integrations/sandboxes/vercel.md +3 -1
  83. package/.docs/integrations/tools/firecrawl.md +2 -2
  84. package/.docs/integrations/voice/livekit.md +3 -3
  85. package/.docs/integrations.md +108 -108
  86. package/.docs/models/environment-variables.md +2 -0
  87. package/.docs/models/gateways/openrouter.md +5 -1
  88. package/.docs/models/gateways/vercel.md +3 -2
  89. package/.docs/models/index.md +1 -1
  90. package/.docs/models/providers/aiand.md +3 -2
  91. package/.docs/models/providers/digitalocean.md +3 -2
  92. package/.docs/models/providers/edenai.md +88 -0
  93. package/.docs/models/providers/hyper.md +3 -3
  94. package/.docs/models/providers/inceptron.md +8 -9
  95. package/.docs/models/providers/kilo.md +11 -6
  96. package/.docs/models/providers/llmgateway.md +3 -1
  97. package/.docs/models/providers/merge-gateway.md +262 -0
  98. package/.docs/models/providers/nano-gpt.md +13 -37
  99. package/.docs/models/providers/opencode.md +2 -2
  100. package/.docs/models/providers/tinfoil.md +9 -8
  101. package/.docs/models/providers/xai.md +2 -1
  102. package/.docs/models/providers.md +2 -0
  103. package/.docs/reference/agents/getVoice.md +1 -1
  104. package/.docs/reference/configuration.md +1 -1
  105. package/.docs/reference/index.md +5 -1
  106. package/.docs/reference/manual-install.md +1 -1
  107. package/.docs/reference/migrations/network-to-supervisor.md +1 -1
  108. package/.docs/reference/migrations/upgrade-to-v1/tracing.md +1 -3
  109. package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +0 -1
  110. package/.docs/reference/observability/tracing/exporters/console-exporter.md +0 -1
  111. package/.docs/reference/observability/tracing/exporters/default-exporter.md +0 -1
  112. package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +0 -1
  113. package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +0 -1
  114. package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +111 -99
  115. package/.docs/reference/observability/tracing/span-filtering.md +1 -1
  116. package/.docs/reference/storage/overview.md +1 -1
  117. package/.docs/reference/templates/overview.md +1 -1
  118. package/.docs/{guides → reference}/voice/overview.md +3 -3
  119. package/.docs/{guides → reference}/voice/speech-to-speech.md +1 -1
  120. package/.docs/{guides → reference}/voice/speech-to-text.md +1 -1
  121. package/.docs/{guides → reference}/voice/text-to-speech.md +2 -2
  122. package/CHANGELOG.md +14 -0
  123. package/package.json +4 -4
  124. package/.docs/docs/observability/integrations/exporters/mastra-platform.md +0 -201
  125. package/.docs/docs/observability/integrations/overview.md +0 -47
  126. package/.docs/docs/observability/integrations/processors/sensitive-data-filter.md +0 -302
  127. package/.docs/guides/deployment/mastra-workers.md +0 -578
  128. package/.docs/guides/getting-started/quickstart.md +0 -88
  129. package/.docs/guides/guide/ai-recruiter.md +0 -228
  130. package/.docs/guides/guide/code-review-bot.md +0 -228
  131. package/.docs/guides/guide/coding-agent.md +0 -392
  132. package/.docs/guides/guide/dev-assistant.md +0 -309
  133. package/.docs/guides/guide/docs-manager.md +0 -240
  134. package/.docs/guides/guide/github-actions-pr-description.md +0 -238
  135. package/.docs/guides/guide/notes-mcp-server.md +0 -418
  136. package/.docs/guides/guide/research-assistant.md +0 -350
  137. package/.docs/guides/guide/research-coordinator.md +0 -418
  138. package/.docs/guides/guide/signal-provider.md +0 -221
  139. package/.docs/guides/index.md +0 -24
  140. /package/.docs/{reference → docs}/mastra-platform/api.md +0 -0
  141. /package/.docs/{guides/agent-frameworks/ai-sdk.md → reference/ai-sdk/overview.md} +0 -0
@@ -1,240 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Building a docs manager
4
-
5
- In this guide, you'll build a documentation manager that maintains your project's docs. It creates well-structured markdown files and keeps documentation organized while preventing accidental overwrites. You'll set up a workspace filesystem and create an agent with document management instructions. Then you'll use conversational prompts to generate and update documentation.
6
-
7
- ## Prerequisites
8
-
9
- - Node.js `v22.13.0` or later installed
10
- - An API key from a supported [Model Provider](https://mastra.ai/models)
11
- - An existing Mastra project (Follow the [installation guide](https://mastra.ai/guides/getting-started/quickstart) to set up a new project)
12
-
13
- ## Set up the workspace
14
-
15
- The workspace uses a local filesystem to manage documentation files. The agent reads and writes files within the workspace directory. In your `src/mastra/index.ts` file, import the [`Workspace`](https://mastra.ai/reference/workspace/workspace-class) and [`LocalFilesystem`](https://mastra.ai/reference/workspace/local-filesystem) classes.
16
-
17
- ```typescript
18
- import { Mastra } from '@mastra/core'
19
- import { resolve } from 'node:path'
20
- import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
21
-
22
- const workspace = new Workspace({
23
- filesystem: new LocalFilesystem({
24
- basePath: resolve(import.meta.dirname, '../../workspace'),
25
- }),
26
- })
27
-
28
- export const mastra = new Mastra({
29
- workspace,
30
- })
31
- ```
32
-
33
- At the root of your project, create a new folder called `workspace`. This is where all documentation files will be stored and managed by the agent.
34
-
35
- ## Add example documentation
36
-
37
- Inside the `workspace` directory, create the following folders:
38
-
39
- - `docs/guides/`: For how-to guides
40
- - `docs/api/`: For API reference documentation
41
- - `docs/tutorials/`: For step-by-step tutorials
42
-
43
- Create `workspace/docs/README.md` as the documentation index:
44
-
45
- ```markdown
46
- # Project Documentation
47
-
48
- Welcome to the documentation!
49
-
50
- ## Sections
51
-
52
- - [Guides](./guides/): How-to guides
53
- - [API](./api/): API reference
54
- - [Tutorials](./tutorials/): Step-by-step tutorials
55
- ```
56
-
57
- Add a sample guide so the agent can see the existing documentation style:
58
-
59
- ````markdown
60
- # Getting Started
61
-
62
- Quickstart guide for the project.
63
-
64
- ## Installation
65
-
66
- ```bash npm2yarn
67
- npm install example-package
68
- ```
69
-
70
- ## Quick example
71
-
72
- ```typescript
73
- import { Example } from 'example-package'
74
-
75
- const example = new Example()
76
- example.run()
77
- ```
78
- ````
79
-
80
- ## Create the docs manager
81
-
82
- Now it's time to create the documentation manager agent. This agent will have instructions for creating and updating markdown files in the workspace. Create a new file `src/mastra/agents/docs-manager.ts` and define the agent:
83
-
84
- ```typescript
85
- import { Agent } from '@mastra/core/agent'
86
-
87
- export const docsManager = new Agent({
88
- id: 'docs-manager',
89
- name: 'Docs Manager',
90
- instructions: `You are a documentation manager that creates and maintains markdown docs.
91
-
92
- When creating new docs:
93
- 1. Ask for topic and target audience
94
- 2. Create well-structured markdown with clear sections
95
- 3. Include relevant code examples with syntax highlighting
96
- 4. Save in the appropriate directory:
97
- - /docs/guides/ for user guides and how-tos
98
- - /docs/api/ for API reference
99
- - /docs/tutorials/ for step-by-step tutorials
100
-
101
- When updating existing docs:
102
- 1. ALWAYS read the file first
103
- 2. Make targeted updates without removing unrelated content
104
- 3. Preserve existing structure and formatting
105
-
106
- Use kebab-case naming for files (getting-started.md).
107
- Always explain what you're creating and why.`,
108
- model: 'openai/gpt-5.6-sol',
109
- })
110
- ```
111
-
112
- Define the agent by importing it inside `src/mastra/index.ts` and registering it with the `Mastra` instance:
113
-
114
- ```typescript
115
- import { Mastra } from '@mastra/core'
116
- import { resolve } from 'node:path'
117
- import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
118
- import { docsManager } from './agents/docs-manager'
119
-
120
- const workspace = new Workspace({
121
- filesystem: new LocalFilesystem({
122
- basePath: resolve(import.meta.dirname, '../../workspace'),
123
- }),
124
- })
125
-
126
- export const mastra = new Mastra({
127
- workspace,
128
- agents: { docsManager },
129
- })
130
- ```
131
-
132
- ## Test the docs manager
133
-
134
- Start [Studio](https://mastra.ai/docs/studio/overview) and interact with the agent to see it in action.
135
-
136
- **npm**:
137
-
138
- ```bash
139
- npm run dev
140
- ```
141
-
142
- **pnpm**:
143
-
144
- ```bash
145
- pnpm run dev
146
- ```
147
-
148
- **Yarn**:
149
-
150
- ```bash
151
- yarn dev
152
- ```
153
-
154
- **Bun**:
155
-
156
- ```bash
157
- bun run dev
158
- ```
159
-
160
- Open [localhost:4111](http://localhost:4111) and navigate to the docs manager.
161
-
162
- ### Create a new document
163
-
164
- Ask the agent to create a tutorial:
165
-
166
- ```text
167
- Create a tutorial for setting up authentication. Cover installation, configuration, and a basic example.
168
- ```
169
-
170
- The agent should create a file like `docs/tutorials/authentication-setup.md`. Since agent responses are non-deterministic, the exact content will vary, but you should see something similar to:
171
-
172
- ````md
173
- # Authentication Setup
174
-
175
- Learn how to add authentication to your application.
176
-
177
- ## Installation
178
-
179
- Install the auth package:
180
-
181
- ```bash npm2yarn
182
- npm install @example/auth
183
- ```
184
-
185
- ## Configuration
186
-
187
- Create a config file:
188
-
189
- ```typescript
190
- // auth.config.ts
191
- export const authConfig = {
192
- provider: 'oauth',
193
- clientId: process.env.AUTH_CLIENT_ID,
194
- secret: process.env.AUTH_SECRET,
195
- }
196
- ```
197
-
198
- ## Basic example
199
-
200
- ```typescript
201
- import { createAuth } from '@example/auth'
202
- import { authConfig } from './auth.config'
203
-
204
- const auth = createAuth(authConfig)
205
-
206
- app.get('/protected', auth.requireAuth(), (req, res) => {
207
- res.json({ user: req.user })
208
- })
209
- ```
210
- ````
211
-
212
- ### Update an existing document
213
-
214
- Try updating an existing document:
215
-
216
- ```text
217
- Update the getting started guide to include a section on configuration after the Quick Example
218
- ```
219
-
220
- The agent should read the existing `getting-started.md` file and find the right insertion point. It should add the new section without disrupting existing content.
221
-
222
- ### Organize documentation
223
-
224
- Ask the agent to create an index:
225
-
226
- ```text
227
- List all tutorial files and create an index page that links to all of them
228
- ```
229
-
230
- The agent should create a file like `/docs/tutorials/index.md` that links to all available tutorials.
231
-
232
- ## Next steps
233
-
234
- You can extend this manager to:
235
-
236
- - Add BM25 or vector search to find relevant documentation
237
- - Create skills for documentation templates
238
- - Build automated doc generation from source code
239
- - Integrate with GitHub to update docs on commits
240
- - Add validation to check links and formatting
@@ -1,238 +0,0 @@
1
- > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
-
3
- # Building a PR description agent for GitHub Actions
4
-
5
- In this guide, you'll build a [GitHub Action](https://docs.github.com/en/actions) that uses a Mastra agent to read pull request diffs, generate multi-language summaries, and write them directly to the PR description in the GitHub UI. The action runs whenever a pull request is created or updated and regenerates the description as the diff changes.
6
-
7
- This approach is similar to AI-powered PR tools like [CodeRabbit](https://coderabbit.ai/) and [Greptile](https://www.greptile.com/), but built using native GitHub Actions workflows and Mastra agents.
8
-
9
- The setup consists of three parts:
10
-
11
- - A Mastra agent that generates the description
12
- - A GitHub Actions workflow that triggers on pull requests
13
- - A Node.js script that connects the workflow to the agent
14
-
15
- The finished action writes a description with summaries in English, Spanish, and Japanese, each marked with a flag emoji for quick scanning. For example:
16
-
17
- ```text
18
- 🇬🇧 English
19
- This PR integrates Astro into the project, adding configuration files and updating scripts to support Astro development.
20
-
21
- 🇪🇸 Español
22
- Este PR integra Astro en el proyecto, añadiendo archivos de configuración y actualizando scripts para soportar el desarrollo con Astro.
23
-
24
- 🇯🇵 日本語
25
- このPRは、Astroをプロジェクトに統合し、Astro開発をサポートするための設定ファイルを追加し、スクリプトを更新します。
26
- ```
27
-
28
- ## Before you begin
29
-
30
- - A Mastra project (see [Quickstart](https://mastra.ai/guides/getting-started/quickstart))
31
- - An API key from a supported [model provider](https://mastra.ai/models). If you don't have a preference, use [OpenAI](https://mastra.ai/models/providers/openai)
32
- - Node.js `v22.13.0` or later
33
-
34
- ### Set up repository secrets
35
-
36
- The workflow needs access to your model provider API key. Add it as a repository secret in GitHub:
37
-
38
- 1. Go to your repository on GitHub
39
-
40
- 2. Navigate to **Settings** > **Secrets and variables** > **Actions**
41
-
42
- 3. Click **New repository secret**
43
-
44
- 4. Add your API key with the name `OPENAI_API_KEY` (or the appropriate key for your provider)
45
-
46
- ![Screenshot of repository secrets in GitHub UI](/assets/images/github-action-repository-secrets-4e97642b3aa65178a3459a5deebe6f79.jpg)
47
-
48
- The workflow references this secret as `${{ secrets.OPENAI_API_KEY }}` and makes it available to the Mastra agent at runtime.
49
-
50
- ## Create the description agent
51
-
52
- The PR description agent is responsible for turning a git diff into a clear, reviewer-friendly pull request description.
53
-
54
- This agent receives the raw diff from a pull request. It generates descriptions in the configured languages and formats the output using emoji flags so each language section is quick to scan in the PR.
55
-
56
- ```ts
57
- import { Agent } from '@mastra/core/agent'
58
-
59
- export const descriptionAgent = new Agent({
60
- id: 'description-agent',
61
- name: 'PR Description Agent',
62
- instructions: `You are a helpful assistant that creates clear, concise PR descriptions.
63
-
64
- When given a git diff of changed files, you will:
65
- 1. Analyze the changes to understand what was modified
66
- 2. Write a brief summary and list of changes
67
- 3. Output the same content in English, Spanish, and Japanese
68
-
69
- Guidelines:
70
- - Be concise but informative
71
- - Focus on the "what" and "why" of changes
72
- - Use technical terms appropriately
73
- - Keep bullet points short and scannable
74
- - Each language section should contain the same information, naturally translated
75
-
76
- Output format:
77
-
78
- ### 🇬🇧 English
79
-
80
- [1-2 sentence summary]
81
-
82
- - [Change 1]
83
- - [Change 2]
84
- - [Change 3]
85
-
86
- ---
87
-
88
- ### 🇪🇸 Español
89
-
90
- [Same summary in Spanish]
91
-
92
- - [Same changes in Spanish]
93
-
94
- ---
95
-
96
- ### 🇯🇵 日本語
97
-
98
- [Same summary in Japanese]
99
-
100
- - [Same changes in Japanese]
101
- `,
102
- model: 'openai/gpt-5.6-sol',
103
- })
104
- ```
105
-
106
- ### Test the agent locally
107
-
108
- Before deploying the workflow, you can test the agent in [Studio](https://mastra.ai/docs/studio/overview) to verify it generates descriptions correctly.
109
-
110
- 1. Get a diff from any public GitHub PR by appending `.diff` to the PR URL:
111
-
112
- ```text
113
- https://github.com/owner/repo/pull/123.diff
114
- ```
115
-
116
- 2. Open the PR Description Agent in Studio and paste the diff content with this prompt:
117
-
118
- "Please create a PR description for the following changes. `<paste the diff content here>`"
119
-
120
- The agent will return a formatted description with sections in English, Spanish, and Japanese.
121
-
122
- ## GitHub actions
123
-
124
- GitHub Actions run your workflows in short-lived environments on GitHub's infrastructure. Each run starts with a clean virtual machine and checks out your code. It installs dependencies before running your workflow steps. The environment shuts down when the run completes. Nothing persists between runs unless you explicitly save it as an artifact or cache.
125
-
126
- ### Create the workflow
127
-
128
- GitHub Actions workflows live in the `.github/workflows` directory. Create a `.github` directory at the root of your project, then create a `workflows` directory inside it. Add `pr-description.yml`.
129
-
130
- This workflow runs whenever a pull request is opened or updated. It generates a diff for the PR, calls the Mastra agent to describe the changes, and writes the description directly into the PR in the GitHub UI.
131
-
132
- ```yaml
133
- name: PR Description Generator
134
-
135
- on:
136
- pull_request:
137
- types: [opened, synchronize]
138
-
139
- permissions:
140
- contents: read
141
- pull-requests: write
142
-
143
- env:
144
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145
- OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
146
- PR_DIFF_FILE: /tmp/pr_diff.txt
147
- PR_DESCRIPTION_FILE: /tmp/pr_description.md
148
-
149
- jobs:
150
- generate-description:
151
- runs-on: ubuntu-latest
152
- steps:
153
- - uses: actions/checkout@v4
154
- with:
155
- fetch-depth: 0
156
-
157
- - uses: actions/setup-node@v4
158
- with:
159
- node-version: '22'
160
- cache: 'npm'
161
-
162
- - run: npm ci
163
-
164
- - id: pr
165
- run: |
166
- BASE_REF=$(gh pr view ${{ github.event.pull_request.number }} --json baseRefName -q '.baseRefName')
167
- git fetch origin $BASE_REF
168
- git diff origin/$BASE_REF...HEAD -- . ':!package-lock.json' > $PR_DIFF_FILE
169
-
170
- - run: npx tsx .github/scripts/generate-description.ts
171
-
172
- - run: gh pr edit ${{ github.event.pull_request.number }} --body-file $PR_DESCRIPTION_FILE
173
- ```
174
-
175
- #### The workflow explained
176
-
177
- - **`on: pull_request`**: Runs when a pull request is opened or updated.
178
- - **`permissions: pull-requests: write`**: Allows the workflow to update the PR description.
179
- - **`env`**: Defines shared file paths used across steps and reads required values from repository secrets, including the model API key used by the Mastra agent.
180
- - **`actions/checkout@v4` + git commands**: Checks out the full repository history, fetches the PR base branch, and writes the PR diff to `/tmp/pr_diff.txt`.
181
- - **`actions/setup-node@v4`**: Sets up the Node.js runtime used by the workflow.
182
- - **`npm ci`**: Installs the repository's Node.js dependencies from the lockfile.
183
- - **`generate-description.ts`**: Reads `/tmp/pr_diff.txt`, calls the Mastra agent, and writes the generated description to `/tmp/pr_description.md`.
184
- - **`gh pr edit`**: Updates the pull request description using the contents of `/tmp/pr_description.md`.
185
-
186
- > **Note:** The workflow excludes `package-lock.json` when generating the diff. Lockfiles are often large and noisy, and including them can overwhelm the agent's context window and make the resulting description harder to reason about.
187
-
188
- ### Create the workflow script
189
-
190
- Create a `scripts` directory inside `.github` and add `generate-description.ts`.
191
-
192
- This script reads the PR diff from `PR_DIFF_FILE`, generates a description using the Mastra agent, and writes the result to `PR_DESCRIPTION_FILE` for the workflow to publish to the pull request.
193
-
194
- ```typescript
195
- import { readFileSync, writeFileSync } from 'fs'
196
- import { mastra } from '../../src/mastra'
197
-
198
- const agent = mastra.getAgent('descriptionAgent')
199
-
200
- await agent.generate(
201
- `Please create a PR description for the following changes.
202
-
203
- Git diff:
204
- \`\`\`diff
205
- ${readFileSync(process.env.PR_DIFF_FILE!, 'utf-8')}
206
- \`\`\``,
207
- {
208
- onError: () => {
209
- writeFileSync(
210
- process.env.PR_DESCRIPTION_FILE!,
211
- 'This PR diff is too large to generate a description automatically.',
212
- )
213
- },
214
- onFinish: result => {
215
- writeFileSync(process.env.PR_DESCRIPTION_FILE!, result.text)
216
- },
217
- },
218
- )
219
- ```
220
-
221
- #### The workflow script explained
222
-
223
- - **`mastra.getAgent("descriptionAgent")`**: Gets the Mastra agent that generates the PR description.
224
- - **`agent.generate(...)`**: Reads the pull request diff from `PR_DIFF_FILE` and asks the agent to write a PR description.
225
- - **`onError` callback**: Writes a fallback message to `PR_DESCRIPTION_FILE` when the diff is too large to process.
226
- - **`onFinish` callback**: Writes the generated PR description to `PR_DESCRIPTION_FILE`.
227
-
228
- ## Next steps
229
-
230
- You now have a GitHub Action that generates multi-language PR descriptions using a Mastra agent. Once the workflow and supporting files are merged into your main branch, the agent will run automatically the next time a pull request is created or updated. You can monitor the run in the **Actions** tab of your repository.
231
-
232
- From here, customize the agent instructions or change the output languages. You can also extend the workflow to handle other events.
233
-
234
- To learn more:
235
-
236
- - Read the [agents](https://mastra.ai/docs/agents/overview) documentation
237
- - Give your agent [tools](https://mastra.ai/docs/agents/using-tools) to fetch additional context
238
- - Explore other [GitHub Actions triggers](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows) like issue comments or releases