@mastra/mcp-docs-server 0.13.34 → 0.13.35
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.
- package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +2 -0
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +2 -0
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Flance.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Freact.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +27 -27
- package/.docs/organized/changelogs/create-mastra.md +5 -5
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/memory-with-mongodb.md +208 -0
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/studio.mdx +4 -4
- package/.docs/raw/memory/overview.mdx +1 -1
- package/.docs/raw/memory/semantic-recall.mdx +4 -3
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +141 -0
- package/.docs/raw/memory/storage/memory-with-pg.mdx +138 -0
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +147 -0
- package/.docs/raw/observability/ai-tracing/exporters/arize.mdx +201 -0
- package/.docs/raw/observability/ai-tracing/overview.mdx +12 -8
- package/.docs/raw/reference/observability/ai-tracing/exporters/arize.mdx +160 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/braintrust.mdx +2 -2
- package/.docs/raw/reference/observability/ai-tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/observability/ai-tracing/exporters/langsmith.mdx +2 -2
- package/.docs/raw/reference/observability/ai-tracing/exporters/otel.mdx +1 -1
- package/.docs/raw/reference/observability/ai-tracing/interfaces.mdx +48 -21
- package/.docs/raw/reference/storage/mongodb.mdx +146 -0
- package/.docs/raw/server-db/storage.mdx +1 -0
- package/.docs/raw/workflows/agents-and-tools.mdx +15 -1
- package/.docs/raw/workflows/human-in-the-loop.mdx +268 -0
- package/CHANGELOG.md +14 -0
- package/package.json +11 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Human in the Loop | Workflows | Mastra Docs"
|
|
3
|
+
description: Example of using Mastra to create workflows with multi-turn human/agent interaction points using suspend/resume and dountil methods.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { GithubLink } from "@/components/github-link";
|
|
7
|
+
|
|
8
|
+
# Human-in-the-loop
|
|
9
|
+
|
|
10
|
+
Human-in-the-loop workflows enable ongoing interaction between humans and AI agents, allowing for complex decision-making processes that require multiple rounds of input and response. These workflows can suspend execution at specific points, wait for human input, and continue processing based on the responses received.
|
|
11
|
+
|
|
12
|
+
In this example, the multi-turn workflow is used to create a Heads Up game that demonstrates how to create interactive workflows using suspend/resume functionality and conditional logic with `dountil` to repeat a workflow step until a specific condition is met.
|
|
13
|
+
|
|
14
|
+
This example consists of three main components:
|
|
15
|
+
|
|
16
|
+
1. A [**Famous Person Agent**](#famous-person-agent) that generates a famous person's name.
|
|
17
|
+
2. A [**Game Agent**](#game-agent) that handles the gameplay.
|
|
18
|
+
3. A [**Multi-Turn Workflow**](#multi-turn-workflow) that orchestrates the interaction.
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
This example uses the `openai` model. Make sure to add the following to your `.env` file:
|
|
23
|
+
|
|
24
|
+
```bash filename=".env" copy
|
|
25
|
+
OPENAI_API_KEY=<your-api-key>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Famous person agent
|
|
29
|
+
|
|
30
|
+
The `famousPersonAgent` generates a unique name each time the game is played, using semantic memory to avoid repeating suggestions.
|
|
31
|
+
|
|
32
|
+
```typescript filename="src/mastra/agents/example-famous-person-agent.ts" showLineNumbers copy
|
|
33
|
+
import { openai } from "@ai-sdk/openai";
|
|
34
|
+
import { Agent } from "@mastra/core/agent";
|
|
35
|
+
import { Memory } from "@mastra/memory";
|
|
36
|
+
import { LibSQLVector } from "@mastra/libsql";
|
|
37
|
+
|
|
38
|
+
export const famousPersonAgent = new Agent({
|
|
39
|
+
name: "Famous Person Generator",
|
|
40
|
+
instructions: `You are a famous person generator for a "Heads Up" guessing game.
|
|
41
|
+
|
|
42
|
+
Generate the name of a well-known famous person who:
|
|
43
|
+
- Is recognizable to most people
|
|
44
|
+
- Has distinctive characteristics that can be described with yes/no questions
|
|
45
|
+
- Is appropriate for all audiences
|
|
46
|
+
- Has a clear, unambiguous name
|
|
47
|
+
|
|
48
|
+
IMPORTANT: Use your memory to check what famous people you've already suggested and NEVER repeat a person you've already suggested.
|
|
49
|
+
|
|
50
|
+
Examples: Albert Einstein, Beyoncé, Leonardo da Vinci, Oprah Winfrey, Michael Jordan
|
|
51
|
+
|
|
52
|
+
Return only the person's name, nothing else.`,
|
|
53
|
+
model: openai("gpt-4o"),
|
|
54
|
+
memory: new Memory({
|
|
55
|
+
vector: new LibSQLVector({
|
|
56
|
+
connectionUrl: "file:../mastra.db"
|
|
57
|
+
}),
|
|
58
|
+
embedder: openai.embedding("text-embedding-3-small"),
|
|
59
|
+
options: {
|
|
60
|
+
lastMessages: 5,
|
|
61
|
+
semanticRecall: {
|
|
62
|
+
topK: 10,
|
|
63
|
+
messageRange: 1
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> See [Agent](../../reference/agents/agent.mdx) for a full list of configuration options.
|
|
71
|
+
|
|
72
|
+
## Game agent
|
|
73
|
+
|
|
74
|
+
The `gameAgent` handles user interactions by responding to questions and validating guesses.
|
|
75
|
+
|
|
76
|
+
```typescript filename="src/mastra/agents/example-game-agent.ts" showLineNumbers copy
|
|
77
|
+
import { openai } from "@ai-sdk/openai";
|
|
78
|
+
import { Agent } from "@mastra/core/agent";
|
|
79
|
+
|
|
80
|
+
export const gameAgent = new Agent({
|
|
81
|
+
name: "Game Agent",
|
|
82
|
+
instructions: `You are a helpful game assistant for a "Heads Up" guessing game.
|
|
83
|
+
|
|
84
|
+
CRITICAL: You know the famous person's name but you must NEVER reveal it in any response.
|
|
85
|
+
|
|
86
|
+
When a user asks a question about the famous person:
|
|
87
|
+
- Answer truthfully based on the famous person provided
|
|
88
|
+
- Keep responses concise and friendly
|
|
89
|
+
- NEVER mention the person's name, even if it seems natural
|
|
90
|
+
- NEVER reveal gender, nationality, or other characteristics unless specifically asked about them
|
|
91
|
+
- Answer yes/no questions with clear "Yes" or "No" responses
|
|
92
|
+
- Be consistent - same question asked differently should get the same answer
|
|
93
|
+
- Ask for clarification if a question is unclear
|
|
94
|
+
- If multiple questions are asked at once, ask them to ask one at a time
|
|
95
|
+
|
|
96
|
+
When they make a guess:
|
|
97
|
+
- If correct: Congratulate them warmly
|
|
98
|
+
- If incorrect: Politely correct them and encourage them to try again
|
|
99
|
+
|
|
100
|
+
Encourage players to make a guess when they seem to have enough information.
|
|
101
|
+
|
|
102
|
+
You must return a JSON object with:
|
|
103
|
+
- response: Your response to the user
|
|
104
|
+
- gameWon: true if they guessed correctly, false otherwise`,
|
|
105
|
+
model: openai("gpt-4o")
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
## Multi-turn workflow
|
|
111
|
+
|
|
112
|
+
The workflow coordinates the full interaction using `suspend`/`resume` to pause for human input and `dountil` to repeat the game loop until a condition is met.
|
|
113
|
+
|
|
114
|
+
The `startStep` generates a name using the `famousPersonAgent`, while the `gameStep` runs the interaction through the `gameAgent`, which handles both questions and guesses and produces structured output that includes a `gameWon` boolean.
|
|
115
|
+
|
|
116
|
+
```typescript filename="src/mastra/workflows/example-heads-up-workflow.ts" showLineNumbers copy
|
|
117
|
+
import { createWorkflow, createStep } from '@mastra/core/workflows';
|
|
118
|
+
import { z } from 'zod';
|
|
119
|
+
|
|
120
|
+
const startStep = createStep({
|
|
121
|
+
id: 'start-step',
|
|
122
|
+
description: 'Get the name of a famous person',
|
|
123
|
+
inputSchema: z.object({
|
|
124
|
+
start: z.boolean(),
|
|
125
|
+
}),
|
|
126
|
+
outputSchema: z.object({
|
|
127
|
+
famousPerson: z.string(),
|
|
128
|
+
guessCount: z.number(),
|
|
129
|
+
}),
|
|
130
|
+
execute: async ({ mastra }) => {
|
|
131
|
+
const agent = mastra.getAgent('famousPersonAgent');
|
|
132
|
+
const response = await agent.generate("Generate a famous person's name", {
|
|
133
|
+
temperature: 1.2,
|
|
134
|
+
topP: 0.9,
|
|
135
|
+
memory: {
|
|
136
|
+
resource: 'heads-up-game',
|
|
137
|
+
thread: 'famous-person-generator',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
const famousPerson = response.text.trim();
|
|
141
|
+
return { famousPerson, guessCount: 0 };
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const gameStep = createStep({
|
|
146
|
+
id: 'game-step',
|
|
147
|
+
description: 'Handles the question-answer-continue loop',
|
|
148
|
+
inputSchema: z.object({
|
|
149
|
+
famousPerson: z.string(),
|
|
150
|
+
guessCount: z.number(),
|
|
151
|
+
}),
|
|
152
|
+
resumeSchema: z.object({
|
|
153
|
+
userMessage: z.string(),
|
|
154
|
+
}),
|
|
155
|
+
suspendSchema: z.object({
|
|
156
|
+
suspendResponse: z.string(),
|
|
157
|
+
}),
|
|
158
|
+
outputSchema: z.object({
|
|
159
|
+
famousPerson: z.string(),
|
|
160
|
+
gameWon: z.boolean(),
|
|
161
|
+
agentResponse: z.string(),
|
|
162
|
+
guessCount: z.number(),
|
|
163
|
+
}),
|
|
164
|
+
execute: async ({ inputData, mastra, resumeData, suspend }) => {
|
|
165
|
+
let { famousPerson, guessCount } = inputData;
|
|
166
|
+
const { userMessage } = resumeData ?? {};
|
|
167
|
+
|
|
168
|
+
if (!userMessage) {
|
|
169
|
+
return await suspend({
|
|
170
|
+
suspendResponse: "I'm thinking of a famous person. Ask me yes/no questions to figure out who it is!",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const agent = mastra.getAgent('gameAgent');
|
|
175
|
+
const response = await agent.generate(
|
|
176
|
+
`
|
|
177
|
+
The famous person is: ${famousPerson}
|
|
178
|
+
The user said: "${userMessage}"
|
|
179
|
+
Please respond appropriately. If this is a guess, tell me if it's correct.
|
|
180
|
+
`,
|
|
181
|
+
{
|
|
182
|
+
structuredOutput: {
|
|
183
|
+
schema: z.object({
|
|
184
|
+
response: z.string(),
|
|
185
|
+
gameWon: z.boolean(),
|
|
186
|
+
})
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const { response: agentResponse, gameWon } = response.object;
|
|
192
|
+
|
|
193
|
+
guessCount++;
|
|
194
|
+
|
|
195
|
+
return { famousPerson, gameWon, agentResponse, guessCount };
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const winStep = createStep({
|
|
200
|
+
id: 'win-step',
|
|
201
|
+
description: 'Handle game win logic',
|
|
202
|
+
inputSchema: z.object({
|
|
203
|
+
famousPerson: z.string(),
|
|
204
|
+
gameWon: z.boolean(),
|
|
205
|
+
agentResponse: z.string(),
|
|
206
|
+
guessCount: z.number(),
|
|
207
|
+
}),
|
|
208
|
+
outputSchema: z.object({
|
|
209
|
+
famousPerson: z.string(),
|
|
210
|
+
gameWon: z.boolean(),
|
|
211
|
+
guessCount: z.number(),
|
|
212
|
+
}),
|
|
213
|
+
execute: async ({ inputData }) => {
|
|
214
|
+
const { famousPerson, gameWon, guessCount } = inputData;
|
|
215
|
+
|
|
216
|
+
console.log('famousPerson: ', famousPerson);
|
|
217
|
+
console.log('gameWon: ', gameWon);
|
|
218
|
+
console.log('guessCount: ', guessCount);
|
|
219
|
+
|
|
220
|
+
return { famousPerson, gameWon, guessCount };
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const headsUpWorkflow = createWorkflow({
|
|
225
|
+
id: 'heads-up-workflow',
|
|
226
|
+
inputSchema: z.object({
|
|
227
|
+
start: z.boolean(),
|
|
228
|
+
}),
|
|
229
|
+
outputSchema: z.object({
|
|
230
|
+
famousPerson: z.string(),
|
|
231
|
+
gameWon: z.boolean(),
|
|
232
|
+
guessCount: z.number(),
|
|
233
|
+
}),
|
|
234
|
+
})
|
|
235
|
+
.then(startStep)
|
|
236
|
+
.dountil(gameStep, async ({ inputData: { gameWon } }) => gameWon)
|
|
237
|
+
.then(winStep)
|
|
238
|
+
.commit();
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
> See [Workflow](../../reference/workflows/workflow.mdx) for a full list of configuration options.
|
|
242
|
+
|
|
243
|
+
## Registering the agents and workflow
|
|
244
|
+
|
|
245
|
+
To use a workflow or an agent, register them in your main Mastra instance.
|
|
246
|
+
|
|
247
|
+
```typescript filename="src/mastra/index.ts" showLineNumbers copy
|
|
248
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
249
|
+
|
|
250
|
+
import { headsUpWorkflow } from "./workflows/example-heads-up-workflow";
|
|
251
|
+
import { famousPersonAgent } from "./agents/example-famous-person-agent";
|
|
252
|
+
import { gameAgent } from "./agents/example-game-agent";
|
|
253
|
+
|
|
254
|
+
export const mastra = new Mastra({
|
|
255
|
+
workflows: { headsUpWorkflow },
|
|
256
|
+
agents: { famousPersonAgent, gameAgent }
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
<GithubLink
|
|
261
|
+
marginTop='mt-16'
|
|
262
|
+
link="https://github.com/mastra-ai/mastra/blob/main/examples/heads-up-game/"
|
|
263
|
+
/>
|
|
264
|
+
|
|
265
|
+
## Related
|
|
266
|
+
|
|
267
|
+
- [Running Workflows](./running-workflows.mdx)
|
|
268
|
+
- [Control Flow](../../docs/workflows/control-flow.mdx)
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 0.13.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3)]:
|
|
8
|
+
- @mastra/core@0.23.0
|
|
9
|
+
|
|
10
|
+
## 0.13.35-alpha.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3)]:
|
|
15
|
+
- @mastra/core@0.23.0-alpha.0
|
|
16
|
+
|
|
3
17
|
## 0.13.34
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.35",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"uuid": "^11.1.0",
|
|
34
34
|
"zod": "^3.25.76",
|
|
35
35
|
"zod-to-json-schema": "^3.24.6",
|
|
36
|
-
"@mastra/core": "0.
|
|
36
|
+
"@mastra/core": "0.23.0",
|
|
37
37
|
"@mastra/mcp": "^0.14.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"tsx": "^4.19.4",
|
|
50
50
|
"typescript": "^5.8.3",
|
|
51
51
|
"vitest": "^3.2.4",
|
|
52
|
-
"@internal/lint": "0.0.
|
|
53
|
-
"@mastra/core": "0.
|
|
52
|
+
"@internal/lint": "0.0.54",
|
|
53
|
+
"@mastra/core": "0.23.0"
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://mastra.ai",
|
|
56
56
|
"repository": {
|
|
@@ -61,6 +61,13 @@
|
|
|
61
61
|
"bugs": {
|
|
62
62
|
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
63
63
|
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public",
|
|
66
|
+
"publish-branch": [
|
|
67
|
+
"main",
|
|
68
|
+
"0.x"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
64
71
|
"scripts": {
|
|
65
72
|
"prepare-docs": "cross-env PREPARE=true node dist/prepare-docs/prepare.js",
|
|
66
73
|
"build:cli": "tsup src/stdio.ts src/prepare-docs/prepare.ts --format esm --no-dts --treeshake=smallest --splitting && tsc -p tsconfig.build.json",
|