@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
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 +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -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-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -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 +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -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 +302 -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 +388 -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/client-side-tools.md +69 -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/mcp-registry-registry.md +63 -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 +317 -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 +215 -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 +127 -0
- package/.docs/raw/deployment/server.mdx +282 -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 +442 -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 +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -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 +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -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 +12 -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 +207 -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 +203 -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.md +46 -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,238 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Getting started with Mastra and NextJS | Mastra Guides"
|
|
3
|
+
description: Guide on integrating Mastra with NextJS.
|
|
4
|
+
---
|
|
5
|
+
import { Callout, Steps, Tabs } from "nextra/components";
|
|
6
|
+
|
|
7
|
+
# Integrate Mastra in your Next.js project
|
|
8
|
+
|
|
9
|
+
There are two main ways to integrate Mastra with your Next.js application: as a separate backend service or directly integrated into your Next.js app.
|
|
10
|
+
|
|
11
|
+
## 1. Separate Backend Integration
|
|
12
|
+
|
|
13
|
+
Best for larger projects where you want to:
|
|
14
|
+
- Scale your AI backend independently
|
|
15
|
+
- Keep clear separation of concerns
|
|
16
|
+
- Have more deployment flexibility
|
|
17
|
+
|
|
18
|
+
<Steps>
|
|
19
|
+
### Create Mastra Backend
|
|
20
|
+
|
|
21
|
+
Create a new Mastra project using our CLI:
|
|
22
|
+
|
|
23
|
+
<Tabs items={["npx", "npm", "yarn", "pnpm"]}>
|
|
24
|
+
<Tabs.Tab>
|
|
25
|
+
```bash copy
|
|
26
|
+
npx create-mastra@latest
|
|
27
|
+
```
|
|
28
|
+
</Tabs.Tab>
|
|
29
|
+
<Tabs.Tab>
|
|
30
|
+
```bash copy
|
|
31
|
+
npm create mastra
|
|
32
|
+
```
|
|
33
|
+
</Tabs.Tab>
|
|
34
|
+
<Tabs.Tab>
|
|
35
|
+
```bash copy
|
|
36
|
+
yarn create mastra
|
|
37
|
+
```
|
|
38
|
+
</Tabs.Tab>
|
|
39
|
+
<Tabs.Tab>
|
|
40
|
+
```bash copy
|
|
41
|
+
pnpm create mastra
|
|
42
|
+
```
|
|
43
|
+
</Tabs.Tab>
|
|
44
|
+
</Tabs>
|
|
45
|
+
|
|
46
|
+
For detailed setup instructions, see our [installation guide](/docs/getting-started/installation).
|
|
47
|
+
|
|
48
|
+
### Install MastraClient
|
|
49
|
+
|
|
50
|
+
<Tabs items={["npm", "yarn", "pnpm"]}>
|
|
51
|
+
<Tabs.Tab>
|
|
52
|
+
```bash copy
|
|
53
|
+
npm install @mastra/client-js
|
|
54
|
+
```
|
|
55
|
+
</Tabs.Tab>
|
|
56
|
+
<Tabs.Tab>
|
|
57
|
+
```bash copy
|
|
58
|
+
yarn add @mastra/client-js
|
|
59
|
+
```
|
|
60
|
+
</Tabs.Tab>
|
|
61
|
+
<Tabs.Tab>
|
|
62
|
+
```bash copy
|
|
63
|
+
pnpm add @mastra/client-js
|
|
64
|
+
```
|
|
65
|
+
</Tabs.Tab>
|
|
66
|
+
</Tabs>
|
|
67
|
+
|
|
68
|
+
### Use MastraClient
|
|
69
|
+
|
|
70
|
+
Create a client instance and use it in your Next.js application:
|
|
71
|
+
|
|
72
|
+
```typescript filename="lib/mastra.ts" copy
|
|
73
|
+
import { MastraClient } from '@mastra/client-js';
|
|
74
|
+
|
|
75
|
+
// Initialize the client
|
|
76
|
+
export const mastraClient = new MastraClient({
|
|
77
|
+
baseUrl: process.env.NEXT_PUBLIC_MASTRA_API_URL || 'http://localhost:4111',
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Example usage in your React component:
|
|
82
|
+
|
|
83
|
+
```typescript filename="app/components/SimpleWeather.tsx" copy
|
|
84
|
+
'use client'
|
|
85
|
+
|
|
86
|
+
import { mastraClient } from '@/lib/mastra'
|
|
87
|
+
|
|
88
|
+
export function SimpleWeather() {
|
|
89
|
+
async function handleSubmit(formData: FormData) {
|
|
90
|
+
const city = formData.get('city')
|
|
91
|
+
const agent = mastraClient.getAgent('weatherAgent')
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await agent.generate({
|
|
95
|
+
messages: [{ role: 'user', content: `What's the weather like in ${city}?` }],
|
|
96
|
+
})
|
|
97
|
+
// Handle the response
|
|
98
|
+
console.log(response.text)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error('Error:', error)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<form action={handleSubmit}>
|
|
106
|
+
<input name="city" placeholder="Enter city name" />
|
|
107
|
+
<button type="submit">Get Weather</button>
|
|
108
|
+
</form>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Deployment
|
|
114
|
+
|
|
115
|
+
When you're ready to deploy, you can use any of our platform-specific deployers (Vercel, Netlify, Cloudflare) or deploy to any Node.js hosting platform. Check our [deployment guide](/docs/deployment/deployment) for detailed instructions.
|
|
116
|
+
</Steps>
|
|
117
|
+
|
|
118
|
+
## 2. Direct Integration
|
|
119
|
+
|
|
120
|
+
Better for smaller projects or prototypes. This approach bundles Mastra directly with your Next.js application.
|
|
121
|
+
|
|
122
|
+
<Steps>
|
|
123
|
+
### Initialize Mastra in your Next.js Root
|
|
124
|
+
|
|
125
|
+
First, navigate to your Next.js project root and initialize Mastra:
|
|
126
|
+
|
|
127
|
+
```bash copy
|
|
128
|
+
cd your-nextjs-app
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Then run the initialization command:
|
|
132
|
+
|
|
133
|
+
<Tabs items={["npm", "yarn", "pnpm"]}>
|
|
134
|
+
<Tabs.Tab>
|
|
135
|
+
```bash copy
|
|
136
|
+
npx mastra@latest init
|
|
137
|
+
```
|
|
138
|
+
</Tabs.Tab>
|
|
139
|
+
<Tabs.Tab>
|
|
140
|
+
```bash copy
|
|
141
|
+
yarn dlx mastra@latest init
|
|
142
|
+
```
|
|
143
|
+
</Tabs.Tab>
|
|
144
|
+
<Tabs.Tab>
|
|
145
|
+
```bash copy
|
|
146
|
+
pnpm dlx mastra@latest init
|
|
147
|
+
```
|
|
148
|
+
</Tabs.Tab>
|
|
149
|
+
</Tabs>
|
|
150
|
+
|
|
151
|
+
This will set up Mastra in your Next.js project. For more details about init and other configuration options, see our [mastra init reference](/reference/cli/init).
|
|
152
|
+
|
|
153
|
+
### Configure Next.js
|
|
154
|
+
|
|
155
|
+
Add to your `next.config.js`:
|
|
156
|
+
|
|
157
|
+
```js filename="next.config.js" copy
|
|
158
|
+
/** @type {import('next').NextConfig} */
|
|
159
|
+
const nextConfig = {
|
|
160
|
+
serverExternalPackages: ["@mastra/*"],
|
|
161
|
+
// ... your other Next.js config
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports = nextConfig
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Server Actions Example
|
|
168
|
+
|
|
169
|
+
```typescript filename="app/actions.ts" copy
|
|
170
|
+
'use server'
|
|
171
|
+
|
|
172
|
+
import { mastra } from '@/mastra'
|
|
173
|
+
|
|
174
|
+
export async function getWeatherInfo(city: string) {
|
|
175
|
+
const agent = mastra.getAgent('weatherAgent')
|
|
176
|
+
|
|
177
|
+
const result = await agent.generate(`What's the weather like in ${city}?`)
|
|
178
|
+
|
|
179
|
+
return result
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Use it in your component:
|
|
184
|
+
|
|
185
|
+
```typescript filename="app/components/Weather.tsx" copy
|
|
186
|
+
'use client'
|
|
187
|
+
|
|
188
|
+
import { getWeatherInfo } from '../actions'
|
|
189
|
+
|
|
190
|
+
export function Weather() {
|
|
191
|
+
async function handleSubmit(formData: FormData) {
|
|
192
|
+
const city = formData.get('city') as string
|
|
193
|
+
const result = await getWeatherInfo(city)
|
|
194
|
+
// Handle the result
|
|
195
|
+
console.log(result)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<form action={handleSubmit}>
|
|
200
|
+
<input name="city" placeholder="Enter city name" />
|
|
201
|
+
<button type="submit">Get Weather</button>
|
|
202
|
+
</form>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### API Routes Example
|
|
208
|
+
|
|
209
|
+
```typescript filename="app/api/chat/route.ts" copy
|
|
210
|
+
import { mastra } from '@/mastra'
|
|
211
|
+
import { NextResponse } from 'next/server'
|
|
212
|
+
|
|
213
|
+
export async function POST(req: Request) {
|
|
214
|
+
const { city } = await req.json()
|
|
215
|
+
const agent = mastra.getAgent('weatherAgent')
|
|
216
|
+
|
|
217
|
+
const result = await agent.stream(`What's the weather like in ${city}?`)
|
|
218
|
+
|
|
219
|
+
return result.toDataStreamResponse()
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Deployment
|
|
224
|
+
|
|
225
|
+
When using direct integration, your Mastra instance will be deployed alongside your Next.js application. Ensure you:
|
|
226
|
+
- Set up environment variables for your LLM API keys in your deployment platform
|
|
227
|
+
- Implement proper error handling for production use
|
|
228
|
+
- Monitor your AI agent's performance and costs
|
|
229
|
+
</Steps>
|
|
230
|
+
|
|
231
|
+
## Observability
|
|
232
|
+
|
|
233
|
+
Mastra provides built-in observability features to help you monitor, debug, and optimize your AI operations. This includes:
|
|
234
|
+
- Tracing of AI operations and their performance
|
|
235
|
+
- Logging of prompts, completions, and errors
|
|
236
|
+
- Integration with observability platforms like Langfuse and LangSmith
|
|
237
|
+
|
|
238
|
+
For detailed setup instructions and configuration options specific to Next.js local development, see our [Next.js Observability Configuration Guide](/docs/deployment/logging-and-tracing#nextjs-configuration).
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Installing Mastra Locally | Getting Started | Mastra Docs"
|
|
3
|
+
description: Guide on installing Mastra and setting up the necessary prerequisites for running it with various LLM providers.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Callout, Steps, Tabs } from "nextra/components";
|
|
7
|
+
import YouTube from "../../../components/youtube";
|
|
8
|
+
|
|
9
|
+
# Installing Mastra Locally
|
|
10
|
+
|
|
11
|
+
To run Mastra, you need access to an LLM. Typically, you'll want to get an API key from an LLM provider such as [OpenAI](https://platform.openai.com/), [Anthropic](https://console.anthropic.com/settings/keys), or [Google Gemini](https://ai.google.dev/gemini-api/docs). You can also run Mastra with a local LLM using [Ollama](https://ollama.ai/).
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
- Node.js `v20.0` or higher
|
|
16
|
+
- Access to a [supported large language model (LLM)](/docs/frameworks/ai-sdk)
|
|
17
|
+
|
|
18
|
+
## Automatic Installation
|
|
19
|
+
|
|
20
|
+
<YouTube id="spGlcTEjuXY" />
|
|
21
|
+
|
|
22
|
+
<Steps>
|
|
23
|
+
|
|
24
|
+
### Create a New Project
|
|
25
|
+
|
|
26
|
+
We recommend starting a new Mastra project using `create-mastra`, which will scaffold your project. To create
|
|
27
|
+
a project, run:
|
|
28
|
+
|
|
29
|
+
<Tabs items={["npx", "npm", "yarn", "pnpm"]}>
|
|
30
|
+
<Tabs.Tab>
|
|
31
|
+
```bash copy
|
|
32
|
+
npx create-mastra@latest
|
|
33
|
+
```
|
|
34
|
+
</Tabs.Tab>
|
|
35
|
+
<Tabs.Tab>
|
|
36
|
+
```bash copy
|
|
37
|
+
npm create mastra@latest
|
|
38
|
+
```
|
|
39
|
+
</Tabs.Tab>
|
|
40
|
+
<Tabs.Tab>
|
|
41
|
+
```bash copy
|
|
42
|
+
yarn create mastra@latest
|
|
43
|
+
```
|
|
44
|
+
</Tabs.Tab>
|
|
45
|
+
<Tabs.Tab>
|
|
46
|
+
```bash copy
|
|
47
|
+
pnpm create mastra@latest
|
|
48
|
+
```
|
|
49
|
+
</Tabs.Tab>
|
|
50
|
+
</Tabs>
|
|
51
|
+
|
|
52
|
+
On installation, you'll be guided through the following prompts:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
What do you want to name your project? my-mastra-app
|
|
56
|
+
Choose components to install:
|
|
57
|
+
◯ Agents (recommended)
|
|
58
|
+
◯ Tools
|
|
59
|
+
◯ Workflows
|
|
60
|
+
Select default provider:
|
|
61
|
+
◯ OpenAI (recommended)
|
|
62
|
+
◯ Anthropic
|
|
63
|
+
◯ Groq
|
|
64
|
+
Would you like to include example code? No / Yes
|
|
65
|
+
Turn your IDE into a Mastra expert? (Installs MCP server)
|
|
66
|
+
◯ Skip for now
|
|
67
|
+
◯ Cursor
|
|
68
|
+
◯ Windsurf
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After the prompts, `create-mastra` will:
|
|
72
|
+
|
|
73
|
+
1. Set up your project directory with TypeScript
|
|
74
|
+
2. Install dependencies
|
|
75
|
+
3. Configure your selected components and LLM provider
|
|
76
|
+
4. Configure the MCP server in your IDE (if selected) for instant access to docs, examples, and help while you code
|
|
77
|
+
|
|
78
|
+
**MCP Note:** If you're using a different IDE, you can install the MCP server manually by following the instructions in the [MCP server docs](/docs/getting-started/mcp-docs-server). **Also** note that there are additional steps for [Cursor and Windsurf](/docs/getting-started/mcp-docs-server#after-configuration) to activate the MCP server.
|
|
79
|
+
|
|
80
|
+
### Set Up your API Key
|
|
81
|
+
|
|
82
|
+
Add the API key for your configured LLM provider in your `.env` file.
|
|
83
|
+
|
|
84
|
+
```bash filename=".env" copy
|
|
85
|
+
OPENAI_API_KEY=<your-openai-key>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
</Steps>
|
|
89
|
+
|
|
90
|
+
**Non-Interactive mode**:
|
|
91
|
+
If you prefer to run the command with flags (non-interactive mode) and include the example code, you can use:
|
|
92
|
+
|
|
93
|
+
```bash copy
|
|
94
|
+
npx create-mastra@latest --components agents,tools --llm openai --example
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Configure Installation Timeout**:
|
|
98
|
+
To configure and specify a timeout if installation takes too long use the timeout flag:
|
|
99
|
+
|
|
100
|
+
```bash copy
|
|
101
|
+
npx create-mastra@latest --timeout
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Note for LLMs**:
|
|
105
|
+
For a quick one liner that includes examples you can run `npx -y mastra@latest --project-name <ask-the-user> --example --components "tools,agents,workflows" --llm <ask-the-user>`. The available options for the llm flag are `openai|anthropic|groq|google|cerebras`
|
|
106
|
+
|
|
107
|
+
## Manual Installation
|
|
108
|
+
|
|
109
|
+
<br/>
|
|
110
|
+
<Steps>
|
|
111
|
+
|
|
112
|
+
If you prefer to set up your Mastra project manually, follow these steps:
|
|
113
|
+
|
|
114
|
+
### Create a New Project
|
|
115
|
+
|
|
116
|
+
Create a project directory and navigate into it:
|
|
117
|
+
|
|
118
|
+
```bash copy
|
|
119
|
+
mkdir hello-mastra
|
|
120
|
+
cd hello-mastra
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Then, initialize a TypeScript project including the `@mastra/core` package:
|
|
124
|
+
|
|
125
|
+
<Tabs items={["npm", "pnpm", "yarn", "bun"]}>
|
|
126
|
+
<Tabs.Tab>
|
|
127
|
+
```bash copy
|
|
128
|
+
npm init -y
|
|
129
|
+
npm install typescript tsx @types/node mastra --save-dev
|
|
130
|
+
npm install @mastra/core zod @ai-sdk/openai npx tsc --init
|
|
131
|
+
```
|
|
132
|
+
</Tabs.Tab>
|
|
133
|
+
<Tabs.Tab>
|
|
134
|
+
```bash copy
|
|
135
|
+
pnpm init
|
|
136
|
+
pnpm add typescript tsx @types/node mastra --save-dev
|
|
137
|
+
pnpm add @mastra/core zod @ai-sdk/openai
|
|
138
|
+
pnpm dlx tsc --init
|
|
139
|
+
```
|
|
140
|
+
</Tabs.Tab>
|
|
141
|
+
<Tabs.Tab>
|
|
142
|
+
```bash copy
|
|
143
|
+
yarn init -y
|
|
144
|
+
yarn add typescript tsx @types/node mastra --dev
|
|
145
|
+
yarn add @mastra/core zod @ai-sdk/openai
|
|
146
|
+
yarn dlx tsc --init
|
|
147
|
+
```
|
|
148
|
+
</Tabs.Tab>
|
|
149
|
+
<Tabs.Tab>
|
|
150
|
+
```bash copy
|
|
151
|
+
bun init -y
|
|
152
|
+
bun add typescript tsx @types/node mastra --dev
|
|
153
|
+
bun add @mastra/core zod @ai-sdk/openai
|
|
154
|
+
bunx tsc --init
|
|
155
|
+
```
|
|
156
|
+
</Tabs.Tab>
|
|
157
|
+
</Tabs>
|
|
158
|
+
|
|
159
|
+
### Initialize TypeScript
|
|
160
|
+
|
|
161
|
+
Create a `tsconfig.json` file in your project root with the following configuration:
|
|
162
|
+
|
|
163
|
+
```json copy
|
|
164
|
+
{
|
|
165
|
+
"compilerOptions": {
|
|
166
|
+
"target": "ES2022",
|
|
167
|
+
"module": "ES2022",
|
|
168
|
+
"moduleResolution": "bundler",
|
|
169
|
+
"esModuleInterop": true,
|
|
170
|
+
"forceConsistentCasingInFileNames": true,
|
|
171
|
+
"strict": true,
|
|
172
|
+
"skipLibCheck": true,
|
|
173
|
+
"outDir": "dist"
|
|
174
|
+
},
|
|
175
|
+
"include": ["src/**/*"],
|
|
176
|
+
"exclude": ["node_modules", "dist", ".mastra"]
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This TypeScript configuration is optimized for Mastra projects, using modern module resolution and strict type checking.
|
|
181
|
+
|
|
182
|
+
### Set Up your API Key
|
|
183
|
+
|
|
184
|
+
Create a `.env` file in your project root directory and add your API key:
|
|
185
|
+
|
|
186
|
+
```bash filename=".env" copy
|
|
187
|
+
OPENAI_API_KEY=<your-openai-key>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Replace your_openai_api_key with your actual API key.
|
|
191
|
+
|
|
192
|
+
### Create a Tool
|
|
193
|
+
|
|
194
|
+
Create a `weather-tool` tool file:
|
|
195
|
+
|
|
196
|
+
```bash copy
|
|
197
|
+
mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.ts
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Then, add the following code to `src/mastra/tools/weather-tool.ts`:
|
|
201
|
+
|
|
202
|
+
```ts filename="src/mastra/tools/weather-tool.ts" showLineNumbers copy
|
|
203
|
+
import { createTool } from "@mastra/core/tools";
|
|
204
|
+
import { z } from "zod";
|
|
205
|
+
|
|
206
|
+
interface WeatherResponse {
|
|
207
|
+
current: {
|
|
208
|
+
time: string;
|
|
209
|
+
temperature_2m: number;
|
|
210
|
+
apparent_temperature: number;
|
|
211
|
+
relative_humidity_2m: number;
|
|
212
|
+
wind_speed_10m: number;
|
|
213
|
+
wind_gusts_10m: number;
|
|
214
|
+
weather_code: number;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export const weatherTool = createTool({
|
|
219
|
+
id: "get-weather",
|
|
220
|
+
description: "Get current weather for a location",
|
|
221
|
+
inputSchema: z.object({
|
|
222
|
+
location: z.string().describe("City name"),
|
|
223
|
+
}),
|
|
224
|
+
outputSchema: z.object({
|
|
225
|
+
temperature: z.number(),
|
|
226
|
+
feelsLike: z.number(),
|
|
227
|
+
humidity: z.number(),
|
|
228
|
+
windSpeed: z.number(),
|
|
229
|
+
windGust: z.number(),
|
|
230
|
+
conditions: z.string(),
|
|
231
|
+
location: z.string(),
|
|
232
|
+
}),
|
|
233
|
+
execute: async ({ context }) => {
|
|
234
|
+
return await getWeather(context.location);
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const getWeather = async (location: string) => {
|
|
239
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
240
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
241
|
+
const geocodingData = await geocodingResponse.json();
|
|
242
|
+
|
|
243
|
+
if (!geocodingData.results?.[0]) {
|
|
244
|
+
throw new Error(`Location '${location}' not found`);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
248
|
+
|
|
249
|
+
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`;
|
|
250
|
+
|
|
251
|
+
const response = await fetch(weatherUrl);
|
|
252
|
+
const data: WeatherResponse = await response.json();
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
temperature: data.current.temperature_2m,
|
|
256
|
+
feelsLike: data.current.apparent_temperature,
|
|
257
|
+
humidity: data.current.relative_humidity_2m,
|
|
258
|
+
windSpeed: data.current.wind_speed_10m,
|
|
259
|
+
windGust: data.current.wind_gusts_10m,
|
|
260
|
+
conditions: getWeatherCondition(data.current.weather_code),
|
|
261
|
+
location: name,
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
function getWeatherCondition(code: number): string {
|
|
266
|
+
const conditions: Record<number, string> = {
|
|
267
|
+
0: "Clear sky",
|
|
268
|
+
1: "Mainly clear",
|
|
269
|
+
2: "Partly cloudy",
|
|
270
|
+
3: "Overcast",
|
|
271
|
+
45: "Foggy",
|
|
272
|
+
48: "Depositing rime fog",
|
|
273
|
+
51: "Light drizzle",
|
|
274
|
+
53: "Moderate drizzle",
|
|
275
|
+
55: "Dense drizzle",
|
|
276
|
+
56: "Light freezing drizzle",
|
|
277
|
+
57: "Dense freezing drizzle",
|
|
278
|
+
61: "Slight rain",
|
|
279
|
+
63: "Moderate rain",
|
|
280
|
+
65: "Heavy rain",
|
|
281
|
+
66: "Light freezing rain",
|
|
282
|
+
67: "Heavy freezing rain",
|
|
283
|
+
71: "Slight snow fall",
|
|
284
|
+
73: "Moderate snow fall",
|
|
285
|
+
75: "Heavy snow fall",
|
|
286
|
+
77: "Snow grains",
|
|
287
|
+
80: "Slight rain showers",
|
|
288
|
+
81: "Moderate rain showers",
|
|
289
|
+
82: "Violent rain showers",
|
|
290
|
+
85: "Slight snow showers",
|
|
291
|
+
86: "Heavy snow showers",
|
|
292
|
+
95: "Thunderstorm",
|
|
293
|
+
96: "Thunderstorm with slight hail",
|
|
294
|
+
99: "Thunderstorm with heavy hail",
|
|
295
|
+
};
|
|
296
|
+
return conditions[code] || "Unknown";
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Create an Agent
|
|
301
|
+
|
|
302
|
+
Create a `weather` agent file:
|
|
303
|
+
|
|
304
|
+
```bash copy
|
|
305
|
+
mkdir -p src/mastra/agents && touch src/mastra/agents/weather.ts
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Then, add the following code to `src/mastra/agents/weather.ts`:
|
|
309
|
+
|
|
310
|
+
```ts filename="src/mastra/agents/weather.ts" showLineNumbers copy
|
|
311
|
+
import { openai } from "@ai-sdk/openai";
|
|
312
|
+
import { Agent } from "@mastra/core/agent";
|
|
313
|
+
import { weatherTool } from "../tools/weather-tool";
|
|
314
|
+
|
|
315
|
+
export const weatherAgent = new Agent({
|
|
316
|
+
name: "Weather Agent",
|
|
317
|
+
instructions: `You are a helpful weather assistant that provides accurate weather information.
|
|
318
|
+
|
|
319
|
+
Your primary function is to help users get weather details for specific locations. When responding:
|
|
320
|
+
- Always ask for a location if none is provided
|
|
321
|
+
- If the location name isn’t in English, please translate it
|
|
322
|
+
- Include relevant details like humidity, wind conditions, and precipitation
|
|
323
|
+
- Keep responses concise but informative
|
|
324
|
+
|
|
325
|
+
Use the weatherTool to fetch current weather data.`,
|
|
326
|
+
model: openai("gpt-4o-mini"),
|
|
327
|
+
tools: { weatherTool },
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Register Agent
|
|
332
|
+
|
|
333
|
+
Finally, create the Mastra entry point in `src/mastra/index.ts` and register agent:
|
|
334
|
+
|
|
335
|
+
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
336
|
+
import { Mastra } from "@mastra/core";
|
|
337
|
+
|
|
338
|
+
import { weatherAgent } from "./agents/weather";
|
|
339
|
+
|
|
340
|
+
export const mastra = new Mastra({
|
|
341
|
+
agents: { weatherAgent },
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
This registers your agent with Mastra so that `mastra dev` can discover and serve it.
|
|
346
|
+
|
|
347
|
+
</Steps>
|
|
348
|
+
|
|
349
|
+
## Existing Project Installation
|
|
350
|
+
|
|
351
|
+
To add Mastra to an existing project, see our Local development docs on [adding mastra to an existing project](/docs/local-dev/add-to-existing-project).
|
|
352
|
+
|
|
353
|
+
You can also checkout our framework specific docs e.g [Next.js](/docs/frameworks/next-js)
|
|
354
|
+
|
|
355
|
+
## Start the Mastra Server
|
|
356
|
+
|
|
357
|
+
Mastra provides commands to serve your agents via REST endpoints
|
|
358
|
+
|
|
359
|
+
### Development Server
|
|
360
|
+
|
|
361
|
+
Run the following command to start the Mastra server:
|
|
362
|
+
|
|
363
|
+
```bash copy
|
|
364
|
+
npm run dev
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
If you have the mastra CLI installed, run:
|
|
368
|
+
|
|
369
|
+
```bash copy
|
|
370
|
+
mastra dev
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
This command creates REST API endpoints for your agents.
|
|
374
|
+
|
|
375
|
+
### Test the Endpoint
|
|
376
|
+
|
|
377
|
+
You can test the agent's endpoint using `curl` or `fetch`:
|
|
378
|
+
|
|
379
|
+
<Tabs items={['curl', 'fetch']}>
|
|
380
|
+
<Tabs.Tab>
|
|
381
|
+
```bash copy
|
|
382
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
383
|
+
-H "Content-Type: application/json" \
|
|
384
|
+
-d '{"messages": ["What is the weather in London?"]}'
|
|
385
|
+
```
|
|
386
|
+
</Tabs.Tab>
|
|
387
|
+
<Tabs.Tab>
|
|
388
|
+
```js copy showLineNumbers
|
|
389
|
+
fetch('http://localhost:4111/api/agents/weatherAgent/generate', {
|
|
390
|
+
method: 'POST',
|
|
391
|
+
headers: {
|
|
392
|
+
'Content-Type': 'application/json',
|
|
393
|
+
},
|
|
394
|
+
body: JSON.stringify({
|
|
395
|
+
messages: ['What is the weather in London?'],
|
|
396
|
+
}),
|
|
397
|
+
})
|
|
398
|
+
.then(response => response.json())
|
|
399
|
+
.then(data => {
|
|
400
|
+
console.log('Agent response:', data.text);
|
|
401
|
+
})
|
|
402
|
+
.catch(error => {
|
|
403
|
+
console.error('Error:', error);
|
|
404
|
+
});
|
|
405
|
+
```
|
|
406
|
+
</Tabs.Tab>
|
|
407
|
+
</Tabs>
|
|
408
|
+
|
|
409
|
+
## Use Mastra on the Client
|
|
410
|
+
|
|
411
|
+
To use Mastra in your frontend applications, you can use our type-safe client SDK to
|
|
412
|
+
interact with your Mastra REST APIs.
|
|
413
|
+
|
|
414
|
+
See the [Mastra Client SDK documentation](/docs/deployment/client) for detailed usage instructions.
|
|
415
|
+
|
|
416
|
+
## Run from the command line
|
|
417
|
+
|
|
418
|
+
If you'd like to directly call agents from the command line, you can create a script to get an agent and call it:
|
|
419
|
+
|
|
420
|
+
```ts filename="src/index.ts" showLineNumbers copy
|
|
421
|
+
import { mastra } from "./mastra";
|
|
422
|
+
|
|
423
|
+
async function main() {
|
|
424
|
+
const agent = await mastra.getAgent("weatherAgent");
|
|
425
|
+
|
|
426
|
+
const result = await agent.generate("What is the weather in London?");
|
|
427
|
+
|
|
428
|
+
console.log("Agent response:", result.text);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
main();
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Then, run the script to test that everything is set up correctly:
|
|
435
|
+
|
|
436
|
+
```bash copy
|
|
437
|
+
npx tsx src/index.ts
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
This should output the agent's response to your console.
|
|
441
|
+
|
|
442
|
+
---
|