@mastra/mcp-docs-server 0.0.0-default-storage-virtual-file-20250410035748
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/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +131 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +80 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +166 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +220 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +299 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +390 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +239 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +192 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +119 -0
- package/.docs/raw/deployment/server.mdx +276 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +362 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +188 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +167 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-quick-start",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.17.27",
|
|
17
|
+
"tsx": "^4.19.3",
|
|
18
|
+
"typescript": "^5.8.2",
|
|
19
|
+
"zod": "^3.24.2"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/anthropic": "^1.1.15",
|
|
23
|
+
"@ai-sdk/groq": "latest",
|
|
24
|
+
"@ai-sdk/openai": "latest",
|
|
25
|
+
"@mastra/core": "workspace:*",
|
|
26
|
+
"@mastra/loggers": "workspace:*",
|
|
27
|
+
"@mastra/memory": "workspace:*",
|
|
28
|
+
"ai": "latest"
|
|
29
|
+
},
|
|
30
|
+
"version": "0.0.1"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### index.ts
|
|
36
|
+
```typescript
|
|
37
|
+
import { z } from 'zod';
|
|
38
|
+
|
|
39
|
+
import { mastra } from './mastra';
|
|
40
|
+
|
|
41
|
+
const specieSchema = z.object({
|
|
42
|
+
species: z.string(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const main = async () => {
|
|
46
|
+
const agentCat = mastra.getAgent('catOne');
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const result = await agentCat.generate('What is the most popular cat species?', {
|
|
50
|
+
output: specieSchema,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const res = specieSchema.parse(result?.object);
|
|
54
|
+
|
|
55
|
+
console.log(res.species);
|
|
56
|
+
|
|
57
|
+
const { start } = mastra.getWorkflow('logCatWorkflow').createRun();
|
|
58
|
+
|
|
59
|
+
await start({ triggerData: { name: res.species } });
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error(err);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
main();
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### mastra/agents/agent.ts
|
|
70
|
+
```typescript
|
|
71
|
+
import { openai } from '@ai-sdk/openai';
|
|
72
|
+
import { Agent } from '@mastra/core';
|
|
73
|
+
|
|
74
|
+
export const catOne = new Agent({
|
|
75
|
+
name: 'cat-one',
|
|
76
|
+
instructions:
|
|
77
|
+
'You are a feline expert with comprehensive knowledge of all cat species, from domestic breeds to wild big cats. As a lifelong cat specialist, you understand their behavior, biology, social structures, and evolutionary history in great depth. If you are asked for a specie name, do not return a paragraph, a succint two or three letter name of the species will suffice.',
|
|
78
|
+
model: openai('gpt-4o'),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### mastra/index.ts
|
|
84
|
+
```typescript
|
|
85
|
+
import { createLogger, Mastra } from '@mastra/core';
|
|
86
|
+
|
|
87
|
+
import { catOne } from './agents/agent';
|
|
88
|
+
import { logCatWorkflow } from './workflow';
|
|
89
|
+
|
|
90
|
+
export const mastra = new Mastra({
|
|
91
|
+
agents: { catOne },
|
|
92
|
+
workflows: {
|
|
93
|
+
logCatWorkflow,
|
|
94
|
+
},
|
|
95
|
+
logger: createLogger({
|
|
96
|
+
name: 'Mastra',
|
|
97
|
+
level: 'debug',
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### mastra/workflow/index.ts
|
|
104
|
+
```typescript
|
|
105
|
+
import { Workflow, Step } from '@mastra/core';
|
|
106
|
+
import { z } from 'zod';
|
|
107
|
+
|
|
108
|
+
const logCatName = new Step({
|
|
109
|
+
id: 'logCatName',
|
|
110
|
+
outputSchema: z.object({
|
|
111
|
+
rawText: z.string(),
|
|
112
|
+
}),
|
|
113
|
+
execute: async ({ context }) => {
|
|
114
|
+
const name = context?.getStepResult<{ name: string }>('trigger')?.name;
|
|
115
|
+
console.log(`Hello, ${name} 🐈`);
|
|
116
|
+
return { rawText: `Hello ${name}` };
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const logCatWorkflow = new Workflow({
|
|
121
|
+
name: 'log-cat-workflow',
|
|
122
|
+
triggerSchema: z.object({
|
|
123
|
+
name: z.string(),
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
logCatWorkflow.step(logCatName).commit();
|
|
128
|
+
|
|
129
|
+
```
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-stock-price-tool",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "mastra dev",
|
|
10
|
+
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules --max-old-space-size=8192' jest"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"description": "",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@ai-sdk/openai": "latest",
|
|
18
|
+
"@mastra/core": "workspace:*",
|
|
19
|
+
"zod": "^3.24.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@jest/globals": "^29.7.0",
|
|
23
|
+
"jest": "^29.7.0",
|
|
24
|
+
"mastra": "workspace:*",
|
|
25
|
+
"ts-jest": "^29.2.6"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### index.ts
|
|
33
|
+
```typescript
|
|
34
|
+
import { mastra } from './mastra';
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
const stockAgent = mastra.getAgent('stockAgent');
|
|
38
|
+
const response = await stockAgent.generate('What is the current stock price of Apple (AAPL)?');
|
|
39
|
+
|
|
40
|
+
const toolCall: any = response.toolResults.find((result: any) => result.toolName === 'stockPrices');
|
|
41
|
+
|
|
42
|
+
const currentPrice = toolCall?.result?.currentPrice;
|
|
43
|
+
|
|
44
|
+
console.log(`The current price of Apple (AAPL) is $${currentPrice}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main();
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### mastra/agents/index.ts
|
|
52
|
+
```typescript
|
|
53
|
+
import { openai } from '@ai-sdk/openai';
|
|
54
|
+
import { Agent } from '@mastra/core/agent';
|
|
55
|
+
|
|
56
|
+
import { stockPrices } from '../tools/stock-price';
|
|
57
|
+
|
|
58
|
+
export const stockAgent = new Agent({
|
|
59
|
+
name: 'Stock Agent',
|
|
60
|
+
instructions:
|
|
61
|
+
'You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price.',
|
|
62
|
+
model: openai('gpt-4o'),
|
|
63
|
+
tools: {
|
|
64
|
+
stockPrices,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### mastra/index.ts
|
|
71
|
+
```typescript
|
|
72
|
+
import { Mastra } from '@mastra/core';
|
|
73
|
+
|
|
74
|
+
import { stockAgent } from './agents';
|
|
75
|
+
|
|
76
|
+
export const mastra = new Mastra({
|
|
77
|
+
agents: { stockAgent },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### mastra/tools/stock-price.ts
|
|
83
|
+
```typescript
|
|
84
|
+
import { createTool } from '@mastra/core/tools';
|
|
85
|
+
import { z } from 'zod';
|
|
86
|
+
|
|
87
|
+
export const getStockPrice = async (symbol: string) => {
|
|
88
|
+
const data = await fetch(`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`).then(r => r.json());
|
|
89
|
+
return data.prices['4. close'];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const stockPrices = createTool({
|
|
93
|
+
id: 'Get Stock Price',
|
|
94
|
+
inputSchema: z.object({
|
|
95
|
+
symbol: z.string(),
|
|
96
|
+
}),
|
|
97
|
+
description: `Fetches the last day's closing stock price for a given symbol`,
|
|
98
|
+
execute: async ({ context }) => {
|
|
99
|
+
console.log('Using tool to fetch stock price for', context.symbol);
|
|
100
|
+
return {
|
|
101
|
+
symbol: context.symbol,
|
|
102
|
+
currentPrice: await getStockPrice(context.symbol),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### mastra/tools/tools.test.ts
|
|
110
|
+
```typescript
|
|
111
|
+
import { describe, it, expect } from 'vitest';
|
|
112
|
+
|
|
113
|
+
import { getStockPrice } from './stock-price';
|
|
114
|
+
|
|
115
|
+
describe('Test Tools', () => {
|
|
116
|
+
it('should run the stockPrices', async () => {
|
|
117
|
+
const result = await getStockPrice('AAPL');
|
|
118
|
+
|
|
119
|
+
console.log(result);
|
|
120
|
+
expect(result).toBeDefined();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
```
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-weather-agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "npx tsx src/mastra/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ai-sdk/openai": "latest",
|
|
17
|
+
"@mastra/core": "workspace:*",
|
|
18
|
+
"zod": "^3.24.2"
|
|
19
|
+
},
|
|
20
|
+
"version": "0.0.1"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### mastra/agents/index.ts
|
|
26
|
+
```typescript
|
|
27
|
+
import { openai } from '@ai-sdk/openai';
|
|
28
|
+
import { Agent } from '@mastra/core/agent';
|
|
29
|
+
|
|
30
|
+
import { weatherTool } from '../tools';
|
|
31
|
+
|
|
32
|
+
export const weatherAgent = new Agent({
|
|
33
|
+
name: 'Weather Agent',
|
|
34
|
+
instructions: `You are a helpful weather assistant that provides accurate weather information.
|
|
35
|
+
|
|
36
|
+
Your primary function is to help users get weather details for specific locations. When responding:
|
|
37
|
+
- Always ask for a location if none is provided
|
|
38
|
+
- If the location name isn’t in English, please translate it
|
|
39
|
+
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
40
|
+
- Include relevant details like humidity, wind conditions, and precipitation
|
|
41
|
+
- Keep responses concise but informative
|
|
42
|
+
|
|
43
|
+
Use the weatherTool to fetch current weather data.`,
|
|
44
|
+
model: openai('gpt-4o'),
|
|
45
|
+
tools: { weatherTool },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### mastra/index.ts
|
|
51
|
+
```typescript
|
|
52
|
+
import { Mastra } from '@mastra/core';
|
|
53
|
+
|
|
54
|
+
import { weatherAgent } from './agents';
|
|
55
|
+
import { weatherWorkflow } from './workflows';
|
|
56
|
+
|
|
57
|
+
const mastra = new Mastra({
|
|
58
|
+
agents: { weatherAgent },
|
|
59
|
+
workflows: { weatherWorkflow },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
async function agentExample() {
|
|
63
|
+
const agent = await mastra.getAgent('weatherAgent');
|
|
64
|
+
const result = await agent.generate('What is the weather in London?');
|
|
65
|
+
console.log(result.text);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function workflowExample() {
|
|
69
|
+
const { start } = mastra.getWorkflow('weatherWorkflow').createRun();
|
|
70
|
+
|
|
71
|
+
const result = await start({
|
|
72
|
+
triggerData: {
|
|
73
|
+
city: 'London',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log('\n \n');
|
|
78
|
+
console.log(result);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// agentExample();
|
|
82
|
+
workflowExample();
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### mastra/tools/index.ts
|
|
87
|
+
```typescript
|
|
88
|
+
import { createTool } from '@mastra/core/tools';
|
|
89
|
+
import { z } from 'zod';
|
|
90
|
+
|
|
91
|
+
interface WeatherResponse {
|
|
92
|
+
current: {
|
|
93
|
+
time: string;
|
|
94
|
+
temperature_2m: number;
|
|
95
|
+
apparent_temperature: number;
|
|
96
|
+
relative_humidity_2m: number;
|
|
97
|
+
wind_speed_10m: number;
|
|
98
|
+
wind_gusts_10m: number;
|
|
99
|
+
weather_code: number;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const weatherTool = createTool({
|
|
104
|
+
id: 'get-weather',
|
|
105
|
+
description: 'Get current weather for a location',
|
|
106
|
+
inputSchema: z.object({
|
|
107
|
+
location: z.string().describe('City name'),
|
|
108
|
+
}),
|
|
109
|
+
outputSchema: z.object({
|
|
110
|
+
temperature: z.number(),
|
|
111
|
+
feelsLike: z.number(),
|
|
112
|
+
humidity: z.number(),
|
|
113
|
+
windSpeed: z.number(),
|
|
114
|
+
windGust: z.number(),
|
|
115
|
+
conditions: z.string(),
|
|
116
|
+
location: z.string(),
|
|
117
|
+
}),
|
|
118
|
+
execute: async ({ context }) => {
|
|
119
|
+
return await getWeather(context.location);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const getWeather = async (location: string) => {
|
|
124
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
125
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
126
|
+
const geocodingData = await geocodingResponse.json();
|
|
127
|
+
|
|
128
|
+
if (!geocodingData.results?.[0]) {
|
|
129
|
+
throw new Error(`Location '${location}' not found`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
133
|
+
|
|
134
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
|
|
135
|
+
|
|
136
|
+
const response = await fetch(weatherUrl);
|
|
137
|
+
const data: WeatherResponse = await response.json();
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
temperature: data.current.temperature_2m,
|
|
141
|
+
feelsLike: data.current.apparent_temperature,
|
|
142
|
+
humidity: data.current.relative_humidity_2m,
|
|
143
|
+
windSpeed: data.current.wind_speed_10m,
|
|
144
|
+
windGust: data.current.wind_gusts_10m,
|
|
145
|
+
conditions: getWeatherCondition(data.current.weather_code),
|
|
146
|
+
location: name,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
function getWeatherCondition(code: number): string {
|
|
151
|
+
const conditions: Record<number, string> = {
|
|
152
|
+
0: 'Clear sky',
|
|
153
|
+
1: 'Mainly clear',
|
|
154
|
+
2: 'Partly cloudy',
|
|
155
|
+
3: 'Overcast',
|
|
156
|
+
45: 'Foggy',
|
|
157
|
+
48: 'Depositing rime fog',
|
|
158
|
+
51: 'Light drizzle',
|
|
159
|
+
53: 'Moderate drizzle',
|
|
160
|
+
55: 'Dense drizzle',
|
|
161
|
+
56: 'Light freezing drizzle',
|
|
162
|
+
57: 'Dense freezing drizzle',
|
|
163
|
+
61: 'Slight rain',
|
|
164
|
+
63: 'Moderate rain',
|
|
165
|
+
65: 'Heavy rain',
|
|
166
|
+
66: 'Light freezing rain',
|
|
167
|
+
67: 'Heavy freezing rain',
|
|
168
|
+
71: 'Slight snow fall',
|
|
169
|
+
73: 'Moderate snow fall',
|
|
170
|
+
75: 'Heavy snow fall',
|
|
171
|
+
77: 'Snow grains',
|
|
172
|
+
80: 'Slight rain showers',
|
|
173
|
+
81: 'Moderate rain showers',
|
|
174
|
+
82: 'Violent rain showers',
|
|
175
|
+
85: 'Slight snow showers',
|
|
176
|
+
86: 'Heavy snow showers',
|
|
177
|
+
95: 'Thunderstorm',
|
|
178
|
+
96: 'Thunderstorm with slight hail',
|
|
179
|
+
99: 'Thunderstorm with heavy hail',
|
|
180
|
+
};
|
|
181
|
+
return conditions[code] || 'Unknown';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### mastra/workflows/index.ts
|
|
187
|
+
```typescript
|
|
188
|
+
import { openai } from '@ai-sdk/openai';
|
|
189
|
+
import { Agent } from '@mastra/core/agent';
|
|
190
|
+
import { Step, Workflow } from '@mastra/core/workflows';
|
|
191
|
+
import { z } from 'zod';
|
|
192
|
+
|
|
193
|
+
const agent = new Agent({
|
|
194
|
+
name: 'Weather Agent',
|
|
195
|
+
instructions: `
|
|
196
|
+
You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
|
|
197
|
+
For each day in the forecast, structure your response exactly as follows:
|
|
198
|
+
📅 [Day, Month Date, Year]
|
|
199
|
+
═══════════════════════════
|
|
200
|
+
🌡️ WEATHER SUMMARY
|
|
201
|
+
• Conditions: [brief description]
|
|
202
|
+
• Temperature: [X°C/Y°F to A°C/B°F]
|
|
203
|
+
• Precipitation: [X% chance]
|
|
204
|
+
🌅 MORNING ACTIVITIES
|
|
205
|
+
Outdoor:
|
|
206
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
207
|
+
Best timing: [specific time range]
|
|
208
|
+
Note: [relevant weather consideration]
|
|
209
|
+
🌞 AFTERNOON ACTIVITIES
|
|
210
|
+
Outdoor:
|
|
211
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
212
|
+
Best timing: [specific time range]
|
|
213
|
+
Note: [relevant weather consideration]
|
|
214
|
+
🏠 INDOOR ALTERNATIVES
|
|
215
|
+
• [Activity Name] - [Brief description including specific venue]
|
|
216
|
+
Ideal for: [weather condition that would trigger this alternative]
|
|
217
|
+
⚠️ SPECIAL CONSIDERATIONS
|
|
218
|
+
• [Any relevant weather warnings, UV index, wind conditions, etc.]
|
|
219
|
+
Guidelines:
|
|
220
|
+
- Suggest 2-3 time-specific outdoor activities per day
|
|
221
|
+
- Include 1-2 indoor backup options
|
|
222
|
+
- For precipitation >50%, lead with indoor activities
|
|
223
|
+
- All activities must be specific to the location
|
|
224
|
+
- Include specific venues, trails, or locations
|
|
225
|
+
- Consider activity intensity based on temperature
|
|
226
|
+
- Keep descriptions concise but informative
|
|
227
|
+
Maintain this exact formatting for consistency, using the emoji and section headers as shown.
|
|
228
|
+
`,
|
|
229
|
+
model: openai('gpt-4o'),
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const fetchWeather = new Step({
|
|
233
|
+
id: 'fetch-weather',
|
|
234
|
+
description: 'Fetches weather forecast for a given city',
|
|
235
|
+
inputSchema: z.object({
|
|
236
|
+
city: z.string().describe('The city to get the weather for'),
|
|
237
|
+
}),
|
|
238
|
+
execute: async ({ context }) => {
|
|
239
|
+
const triggerData = context?.getStepResult<{ city: string }>('trigger');
|
|
240
|
+
|
|
241
|
+
if (!triggerData) {
|
|
242
|
+
throw new Error('Trigger data not found');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(triggerData.city)}&count=1`;
|
|
246
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
247
|
+
const geocodingData = await geocodingResponse.json();
|
|
248
|
+
|
|
249
|
+
if (!geocodingData.results?.[0]) {
|
|
250
|
+
throw new Error(`Location '${triggerData.city}' not found`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
254
|
+
|
|
255
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_mean,weathercode&timezone=auto`;
|
|
256
|
+
const response = await fetch(weatherUrl);
|
|
257
|
+
const data = await response.json();
|
|
258
|
+
|
|
259
|
+
const forecast = data.daily.time.map((date: string, index: number) => ({
|
|
260
|
+
date,
|
|
261
|
+
maxTemp: data.daily.temperature_2m_max[index],
|
|
262
|
+
minTemp: data.daily.temperature_2m_min[index],
|
|
263
|
+
precipitationChance: data.daily.precipitation_probability_mean[index],
|
|
264
|
+
condition: getWeatherCondition(data.daily.weathercode[index]),
|
|
265
|
+
location: name,
|
|
266
|
+
}));
|
|
267
|
+
|
|
268
|
+
return forecast;
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const forecastSchema = z.array(
|
|
273
|
+
z.object({
|
|
274
|
+
date: z.string(),
|
|
275
|
+
maxTemp: z.number(),
|
|
276
|
+
minTemp: z.number(),
|
|
277
|
+
precipitationChance: z.number(),
|
|
278
|
+
condition: z.string(),
|
|
279
|
+
location: z.string(),
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
const planActivities = new Step({
|
|
284
|
+
id: 'plan-activities',
|
|
285
|
+
description: 'Suggests activities based on weather conditions',
|
|
286
|
+
inputSchema: forecastSchema,
|
|
287
|
+
execute: async ({ context, mastra }) => {
|
|
288
|
+
const forecast = context?.getStepResult<z.infer<typeof forecastSchema>>('fetch-weather');
|
|
289
|
+
|
|
290
|
+
if (!forecast) {
|
|
291
|
+
throw new Error('Forecast data not found');
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const prompt = `Based on the following weather forecast for ${forecast[0].location}, suggest appropriate activities:
|
|
295
|
+
${JSON.stringify(forecast, null, 2)}
|
|
296
|
+
`;
|
|
297
|
+
|
|
298
|
+
const response = await agent.stream([
|
|
299
|
+
{
|
|
300
|
+
role: 'user',
|
|
301
|
+
content: prompt,
|
|
302
|
+
},
|
|
303
|
+
]);
|
|
304
|
+
|
|
305
|
+
let activitiesText = '';
|
|
306
|
+
|
|
307
|
+
for await (const chunk of response.textStream) {
|
|
308
|
+
process.stdout.write(chunk);
|
|
309
|
+
activitiesText += chunk;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
activities: activitiesText,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
function getWeatherCondition(code: number): string {
|
|
319
|
+
const conditions: Record<number, string> = {
|
|
320
|
+
0: 'Clear sky',
|
|
321
|
+
1: 'Mainly clear',
|
|
322
|
+
2: 'Partly cloudy',
|
|
323
|
+
3: 'Overcast',
|
|
324
|
+
45: 'Foggy',
|
|
325
|
+
48: 'Depositing rime fog',
|
|
326
|
+
51: 'Light drizzle',
|
|
327
|
+
53: 'Moderate drizzle',
|
|
328
|
+
55: 'Dense drizzle',
|
|
329
|
+
61: 'Slight rain',
|
|
330
|
+
63: 'Moderate rain',
|
|
331
|
+
65: 'Heavy rain',
|
|
332
|
+
71: 'Slight snow fall',
|
|
333
|
+
73: 'Moderate snow fall',
|
|
334
|
+
75: 'Heavy snow fall',
|
|
335
|
+
95: 'Thunderstorm',
|
|
336
|
+
};
|
|
337
|
+
return conditions[code] || 'Unknown';
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const weatherWorkflow = new Workflow({
|
|
341
|
+
name: 'weather-workflow',
|
|
342
|
+
triggerSchema: z.object({
|
|
343
|
+
city: z.string().describe('The city to get the weather for'),
|
|
344
|
+
}),
|
|
345
|
+
})
|
|
346
|
+
.step(fetchWeather)
|
|
347
|
+
.then(planActivities);
|
|
348
|
+
|
|
349
|
+
weatherWorkflow.commit();
|
|
350
|
+
|
|
351
|
+
export { weatherWorkflow };
|
|
352
|
+
|
|
353
|
+
```
|