@mastra/mcp-docs-server 0.0.1-alpha.1
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%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +302 -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 +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -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%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%2Fstabilityai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +59 -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-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 +24 -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 +12 -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.md +385 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +377 -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/integrations.md +184 -0
- package/.docs/organized/code-examples/mcp-configuration.md +341 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +161 -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-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +127 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +352 -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/00-overview.mdx +185 -0
- package/.docs/raw/agents/01-agent-memory.mdx +610 -0
- package/.docs/raw/agents/02-adding-tools.mdx +224 -0
- package/.docs/raw/agents/03-adding-voice.mdx +170 -0
- package/.docs/raw/deployment/deployment.mdx +156 -0
- package/.docs/raw/deployment/logging-and-tracing.mdx +242 -0
- package/.docs/raw/deployment/server.mdx +114 -0
- package/.docs/raw/evals/00-overview.mdx +106 -0
- package/.docs/raw/evals/01-supported-evals.mdx +31 -0
- package/.docs/raw/evals/02-custom-eval.mdx +187 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/01-next-js.mdx +238 -0
- package/.docs/raw/frameworks/02-ai-sdk.mdx +218 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/guides/01-chef-michel.mdx +242 -0
- package/.docs/raw/guides/02-stock-agent.mdx +182 -0
- package/.docs/raw/guides/03-recruiter.mdx +187 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/local-dev/creating-projects.mdx +74 -0
- package/.docs/raw/local-dev/integrations.mdx +127 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +65 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +128 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +362 -0
- package/.docs/raw/rag/vector-databases.mdx +271 -0
- package/.docs/raw/reference/agents/createTool.mdx +190 -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 +361 -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 +97 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +90 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/index.mdx +127 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +94 -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 +137 -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 +186 -0
- package/.docs/raw/reference/memory/createThread.mdx +93 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +43 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +45 -0
- package/.docs/raw/reference/memory/query.mdx +164 -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/index.mdx +15 -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 +46 -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 +237 -0
- package/.docs/raw/reference/rag/document.mdx +129 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +72 -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 +249 -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 +198 -0
- package/.docs/raw/reference/rag/vectorize.mdx +253 -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 +180 -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/speechify.mdx +145 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -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/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/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/suspend.mdx +80 -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/workflows/00-overview.mdx +168 -0
- package/.docs/raw/workflows/control-flow.mdx +712 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +232 -0
- package/.docs/raw/workflows/steps.mdx +98 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +196 -0
- package/.docs/raw/workflows/variables.mdx +248 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/prepare-docs/code-examples.d.ts +4 -0
- package/dist/prepare-docs/code-examples.js +91 -0
- package/dist/prepare-docs/copy-raw.d.ts +1 -0
- package/dist/prepare-docs/copy-raw.js +41 -0
- package/dist/prepare-docs/index.d.ts +1 -0
- package/dist/prepare-docs/index.js +8 -0
- package/dist/prepare-docs/package-changes.d.ts +4 -0
- package/dist/prepare-docs/package-changes.js +92 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +13 -0
- package/dist/sse.d.ts +1 -0
- package/dist/sse.js +9 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +8 -0
- package/dist/tools/__tests__/blog.test.d.ts +1 -0
- package/dist/tools/__tests__/blog.test.js +48 -0
- package/dist/tools/__tests__/changes.test.d.ts +1 -0
- package/dist/tools/__tests__/changes.test.js +36 -0
- package/dist/tools/__tests__/docs.test.d.ts +1 -0
- package/dist/tools/__tests__/docs.test.js +46 -0
- package/dist/tools/__tests__/examples.test.d.ts +1 -0
- package/dist/tools/__tests__/examples.test.js +52 -0
- package/dist/tools/blog.d.ts +15 -0
- package/dist/tools/blog.js +73 -0
- package/dist/tools/changes.d.ts +11 -0
- package/dist/tools/changes.js +69 -0
- package/dist/tools/docs.d.ts +11 -0
- package/dist/tools/docs.js +176 -0
- package/dist/tools/examples.d.ts +11 -0
- package/dist/tools/examples.js +61 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +9 -0
- package/package.json +66 -0
|
@@ -0,0 +1,436 @@
|
|
|
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/reference/llm/providers-and-models)
|
|
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
|
+
|
|
32
|
+
```bash copy
|
|
33
|
+
npx create-mastra@latest
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
</Tabs.Tab>
|
|
37
|
+
<Tabs.Tab>
|
|
38
|
+
```bash copy
|
|
39
|
+
npm create mastra
|
|
40
|
+
```
|
|
41
|
+
</Tabs.Tab>
|
|
42
|
+
<Tabs.Tab>
|
|
43
|
+
```bash copy
|
|
44
|
+
yarn create mastra
|
|
45
|
+
```
|
|
46
|
+
</Tabs.Tab>
|
|
47
|
+
<Tabs.Tab>
|
|
48
|
+
```bash copy
|
|
49
|
+
pnpm create mastra
|
|
50
|
+
```
|
|
51
|
+
</Tabs.Tab>
|
|
52
|
+
</Tabs>
|
|
53
|
+
|
|
54
|
+
On installation, you'll be guided through the following prompts:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
What do you want to name your project? my-mastra-app
|
|
58
|
+
Choose components to install:
|
|
59
|
+
◯ Agents (recommended)
|
|
60
|
+
◯ Tools
|
|
61
|
+
◯ Workflows
|
|
62
|
+
Select default provider:
|
|
63
|
+
◯ OpenAI (recommended)
|
|
64
|
+
◯ Anthropic
|
|
65
|
+
◯ Groq
|
|
66
|
+
Would you like to include example code? No / Yes
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
After the prompts, `create-mastra` will set up your project directory with TypeScript, install dependencies, and configure your selected components and LLM provider.
|
|
70
|
+
|
|
71
|
+
### Set Up your API Key
|
|
72
|
+
|
|
73
|
+
Add the API key for your configured LLM provider in your `.env` file.
|
|
74
|
+
|
|
75
|
+
```bash filename=".env" copy
|
|
76
|
+
OPENAI_API_KEY=<your-openai-key>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
</Steps>
|
|
80
|
+
Extra Notes:
|
|
81
|
+
|
|
82
|
+
If you prefer to run the command with flags (non-interactive mode) and include the example code, you can use:
|
|
83
|
+
```bash copy
|
|
84
|
+
npx create-mastra@latest --components agents,tools --llm openai --example
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
To configure and specify a timeout if installation takes too long use the timeout flag:
|
|
88
|
+
```bash copy
|
|
89
|
+
npx create-mastra@latest --timeout
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Note for LLMs**: 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`
|
|
93
|
+
|
|
94
|
+
## Manual Installation
|
|
95
|
+
|
|
96
|
+
<br/>
|
|
97
|
+
<Steps>
|
|
98
|
+
|
|
99
|
+
If you prefer to set up your Mastra project manually, follow these steps:
|
|
100
|
+
|
|
101
|
+
### Create a New Project
|
|
102
|
+
|
|
103
|
+
Create a project directory and navigate into it:
|
|
104
|
+
|
|
105
|
+
```bash copy
|
|
106
|
+
mkdir hello-mastra
|
|
107
|
+
cd hello-mastra
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Then, initialize a TypeScript project including the `@mastra/core` package:
|
|
111
|
+
|
|
112
|
+
<Tabs items={["npm", "pnpm", "yarn", "bun"]}>
|
|
113
|
+
<Tabs.Tab>
|
|
114
|
+
```bash copy
|
|
115
|
+
npm init -y
|
|
116
|
+
npm install typescript tsx @types/node mastra --save-dev
|
|
117
|
+
npm install @mastra/core zod @ai-sdk/openai
|
|
118
|
+
npx tsc --init
|
|
119
|
+
```
|
|
120
|
+
</Tabs.Tab>
|
|
121
|
+
<Tabs.Tab>
|
|
122
|
+
```bash copy
|
|
123
|
+
pnpm init
|
|
124
|
+
pnpm add typescript tsx @types/node mastra --save-dev
|
|
125
|
+
pnpm add @mastra/core zod
|
|
126
|
+
pnpm dlx tsc --init
|
|
127
|
+
```
|
|
128
|
+
</Tabs.Tab>
|
|
129
|
+
<Tabs.Tab>
|
|
130
|
+
```bash copy
|
|
131
|
+
yarn init -y
|
|
132
|
+
yarn add typescript tsx @types/node mastra --dev
|
|
133
|
+
yarn add @mastra/core zod
|
|
134
|
+
yarn dlx tsc --init
|
|
135
|
+
```
|
|
136
|
+
</Tabs.Tab>
|
|
137
|
+
<Tabs.Tab>
|
|
138
|
+
```bash copy
|
|
139
|
+
bun init -y
|
|
140
|
+
bun add typescript tsx @types/node mastra --dev
|
|
141
|
+
bun add @mastra/core zod
|
|
142
|
+
bunx tsc --init
|
|
143
|
+
```
|
|
144
|
+
</Tabs.Tab>
|
|
145
|
+
</Tabs>
|
|
146
|
+
|
|
147
|
+
### Initialize TypeScript
|
|
148
|
+
|
|
149
|
+
Create a `tsconfig.json` file in your project root with the following configuration:
|
|
150
|
+
|
|
151
|
+
```json copy
|
|
152
|
+
{
|
|
153
|
+
"compilerOptions": {
|
|
154
|
+
"target": "ES2022",
|
|
155
|
+
"module": "ES2022",
|
|
156
|
+
"moduleResolution": "bundler",
|
|
157
|
+
"esModuleInterop": true,
|
|
158
|
+
"forceConsistentCasingInFileNames": true,
|
|
159
|
+
"strict": true,
|
|
160
|
+
"skipLibCheck": true,
|
|
161
|
+
"outDir": "dist"
|
|
162
|
+
},
|
|
163
|
+
"include": [
|
|
164
|
+
"src/**/*"
|
|
165
|
+
],
|
|
166
|
+
"exclude": [
|
|
167
|
+
"node_modules",
|
|
168
|
+
"dist",
|
|
169
|
+
".mastra"
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This TypeScript configuration is optimized for Mastra projects, using modern module resolution and strict type checking.
|
|
175
|
+
|
|
176
|
+
### Set Up your API Key
|
|
177
|
+
|
|
178
|
+
Create a `.env` file in your project root directory and add your API key:
|
|
179
|
+
|
|
180
|
+
```bash filename=".env" copy
|
|
181
|
+
OPENAI_API_KEY=<your-openai-key>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Replace your_openai_api_key with your actual API key.
|
|
185
|
+
|
|
186
|
+
### Create a Tool
|
|
187
|
+
|
|
188
|
+
Create a `weather-tool` tool file:
|
|
189
|
+
|
|
190
|
+
```bash copy
|
|
191
|
+
mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.ts
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Then, add the following code to `src/mastra/tools/weather-tool.ts`:
|
|
195
|
+
|
|
196
|
+
```ts filename="src/mastra/tools/weather-tool.ts" showLineNumbers copy
|
|
197
|
+
import { createTool } from "@mastra/core/tools";
|
|
198
|
+
import { z } from "zod";
|
|
199
|
+
|
|
200
|
+
interface WeatherResponse {
|
|
201
|
+
current: {
|
|
202
|
+
time: string;
|
|
203
|
+
temperature_2m: number;
|
|
204
|
+
apparent_temperature: number;
|
|
205
|
+
relative_humidity_2m: number;
|
|
206
|
+
wind_speed_10m: number;
|
|
207
|
+
wind_gusts_10m: number;
|
|
208
|
+
weather_code: number;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export const weatherTool = createTool({
|
|
213
|
+
id: "get-weather",
|
|
214
|
+
description: "Get current weather for a location",
|
|
215
|
+
inputSchema: z.object({
|
|
216
|
+
location: z.string().describe("City name"),
|
|
217
|
+
}),
|
|
218
|
+
outputSchema: z.object({
|
|
219
|
+
temperature: z.number(),
|
|
220
|
+
feelsLike: z.number(),
|
|
221
|
+
humidity: z.number(),
|
|
222
|
+
windSpeed: z.number(),
|
|
223
|
+
windGust: z.number(),
|
|
224
|
+
conditions: z.string(),
|
|
225
|
+
location: z.string(),
|
|
226
|
+
}),
|
|
227
|
+
execute: async ({ context }) => {
|
|
228
|
+
return await getWeather(context.location);
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const getWeather = async (location: string) => {
|
|
233
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
234
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
235
|
+
const geocodingData = await geocodingResponse.json();
|
|
236
|
+
|
|
237
|
+
if (!geocodingData.results?.[0]) {
|
|
238
|
+
throw new Error(`Location '${location}' not found`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
242
|
+
|
|
243
|
+
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`;
|
|
244
|
+
|
|
245
|
+
const response = await fetch(weatherUrl);
|
|
246
|
+
const data: WeatherResponse = await response.json();
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
temperature: data.current.temperature_2m,
|
|
250
|
+
feelsLike: data.current.apparent_temperature,
|
|
251
|
+
humidity: data.current.relative_humidity_2m,
|
|
252
|
+
windSpeed: data.current.wind_speed_10m,
|
|
253
|
+
windGust: data.current.wind_gusts_10m,
|
|
254
|
+
conditions: getWeatherCondition(data.current.weather_code),
|
|
255
|
+
location: name,
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
function getWeatherCondition(code: number): string {
|
|
260
|
+
const conditions: Record<number, string> = {
|
|
261
|
+
0: "Clear sky",
|
|
262
|
+
1: "Mainly clear",
|
|
263
|
+
2: "Partly cloudy",
|
|
264
|
+
3: "Overcast",
|
|
265
|
+
45: "Foggy",
|
|
266
|
+
48: "Depositing rime fog",
|
|
267
|
+
51: "Light drizzle",
|
|
268
|
+
53: "Moderate drizzle",
|
|
269
|
+
55: "Dense drizzle",
|
|
270
|
+
56: "Light freezing drizzle",
|
|
271
|
+
57: "Dense freezing drizzle",
|
|
272
|
+
61: "Slight rain",
|
|
273
|
+
63: "Moderate rain",
|
|
274
|
+
65: "Heavy rain",
|
|
275
|
+
66: "Light freezing rain",
|
|
276
|
+
67: "Heavy freezing rain",
|
|
277
|
+
71: "Slight snow fall",
|
|
278
|
+
73: "Moderate snow fall",
|
|
279
|
+
75: "Heavy snow fall",
|
|
280
|
+
77: "Snow grains",
|
|
281
|
+
80: "Slight rain showers",
|
|
282
|
+
81: "Moderate rain showers",
|
|
283
|
+
82: "Violent rain showers",
|
|
284
|
+
85: "Slight snow showers",
|
|
285
|
+
86: "Heavy snow showers",
|
|
286
|
+
95: "Thunderstorm",
|
|
287
|
+
96: "Thunderstorm with slight hail",
|
|
288
|
+
99: "Thunderstorm with heavy hail",
|
|
289
|
+
};
|
|
290
|
+
return conditions[code] || "Unknown";
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Create an Agent
|
|
295
|
+
|
|
296
|
+
Create a `weather` agent file:
|
|
297
|
+
|
|
298
|
+
```bash copy
|
|
299
|
+
mkdir -p src/mastra/agents && touch src/mastra/agents/weather.ts
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Then, add the following code to `src/mastra/agents/weather.ts`:
|
|
303
|
+
|
|
304
|
+
```ts filename="src/mastra/agents/weather.ts" showLineNumbers copy
|
|
305
|
+
import { openai } from "@ai-sdk/openai";
|
|
306
|
+
import { Agent } from "@mastra/core/agent";
|
|
307
|
+
import { weatherTool } from "../tools/weather-tool";
|
|
308
|
+
|
|
309
|
+
export const weatherAgent = new Agent({
|
|
310
|
+
name: "Weather Agent",
|
|
311
|
+
instructions: `You are a helpful weather assistant that provides accurate weather information.
|
|
312
|
+
|
|
313
|
+
Your primary function is to help users get weather details for specific locations. When responding:
|
|
314
|
+
- Always ask for a location if none is provided
|
|
315
|
+
- Include relevant details like humidity, wind conditions, and precipitation
|
|
316
|
+
- Keep responses concise but informative
|
|
317
|
+
|
|
318
|
+
Use the weatherTool to fetch current weather data.`,
|
|
319
|
+
model: openai("gpt-4o-mini"),
|
|
320
|
+
tools: { weatherTool },
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Register Agent
|
|
325
|
+
|
|
326
|
+
Finally, create the Mastra entry point in `src/mastra/index.ts` and register agent:
|
|
327
|
+
|
|
328
|
+
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
329
|
+
import { Mastra } from "@mastra/core";
|
|
330
|
+
|
|
331
|
+
import { weatherAgent } from "./agents/weather";
|
|
332
|
+
|
|
333
|
+
export const mastra = new Mastra({
|
|
334
|
+
agents: { weatherAgent },
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
This registers your agent with Mastra so that `mastra dev` can discover and serve it.
|
|
339
|
+
|
|
340
|
+
</Steps>
|
|
341
|
+
|
|
342
|
+
## Existing Project Installation
|
|
343
|
+
|
|
344
|
+
To add Mastra to an existing project, see our Local dev docs on [mastra
|
|
345
|
+
init](/docs/local-dev/creating-projects#adding-to-an-existing-project).
|
|
346
|
+
|
|
347
|
+
You can also checkout our framework specific docs e.g [Next.js](/docs/frameworks/01-next-js)
|
|
348
|
+
|
|
349
|
+
## Start the Mastra Server
|
|
350
|
+
|
|
351
|
+
Mastra provides commands to serve your agents via REST endpoints
|
|
352
|
+
|
|
353
|
+
### Development Server
|
|
354
|
+
|
|
355
|
+
Run the following command to start the Mastra server:
|
|
356
|
+
|
|
357
|
+
```bash copy
|
|
358
|
+
npm run dev
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
If you have the mastra CLI installed, run:
|
|
362
|
+
|
|
363
|
+
```bash copy
|
|
364
|
+
mastra dev
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
This command creates REST API endpoints for your agents.
|
|
368
|
+
|
|
369
|
+
### Test the Endpoint
|
|
370
|
+
|
|
371
|
+
You can test the agent's endpoint using `curl` or `fetch`:
|
|
372
|
+
|
|
373
|
+
<Tabs items={['curl', 'fetch']}>
|
|
374
|
+
<Tabs.Tab>
|
|
375
|
+
```bash copy
|
|
376
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
377
|
+
-H "Content-Type: application/json" \
|
|
378
|
+
-d '{"messages": ["What is the weather in London?"]}'
|
|
379
|
+
```
|
|
380
|
+
</Tabs.Tab>
|
|
381
|
+
<Tabs.Tab>
|
|
382
|
+
```js copy showLineNumbers
|
|
383
|
+
fetch('http://localhost:4111/api/agents/weatherAgent/generate', {
|
|
384
|
+
method: 'POST',
|
|
385
|
+
headers: {
|
|
386
|
+
'Content-Type': 'application/json',
|
|
387
|
+
},
|
|
388
|
+
body: JSON.stringify({
|
|
389
|
+
messages: ['What is the weather in London?'],
|
|
390
|
+
}),
|
|
391
|
+
})
|
|
392
|
+
.then(response => response.json())
|
|
393
|
+
.then(data => {
|
|
394
|
+
console.log('Agent response:', data.text);
|
|
395
|
+
})
|
|
396
|
+
.catch(error => {
|
|
397
|
+
console.error('Error:', error);
|
|
398
|
+
});
|
|
399
|
+
```
|
|
400
|
+
</Tabs.Tab>
|
|
401
|
+
</Tabs>
|
|
402
|
+
|
|
403
|
+
## Use Mastra on the Client
|
|
404
|
+
|
|
405
|
+
To use Mastra in your frontend applications, you can use our type-safe client SDK to
|
|
406
|
+
interact with your Mastra REST APIs.
|
|
407
|
+
|
|
408
|
+
See our [Client SDK documentation](/docs/reference/client-js) for detailed usage instructions.
|
|
409
|
+
|
|
410
|
+
## Run from the command line
|
|
411
|
+
|
|
412
|
+
If you'd like to directly call agents from the command line, you can create a script to get an agent and call it:
|
|
413
|
+
|
|
414
|
+
```ts filename="src/index.ts" showLineNumbers copy
|
|
415
|
+
import { mastra } from "./mastra";
|
|
416
|
+
|
|
417
|
+
async function main() {
|
|
418
|
+
const agent = await mastra.getAgent("weatherAgent");
|
|
419
|
+
|
|
420
|
+
const result = await agent.generate("What is the weather in London?");
|
|
421
|
+
|
|
422
|
+
console.log("Agent response:", result.text);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
main();
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Then, run the script to test that everything is set up correctly:
|
|
429
|
+
|
|
430
|
+
```bash copy
|
|
431
|
+
npx tsx src/index.ts
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
This should output the agent's response to your console.
|
|
435
|
+
|
|
436
|
+
---
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Local Project Structure | Getting Started | Mastra Docs"
|
|
3
|
+
description: Guide on organizing folders and files in Mastra, including best practices and recommended structures.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { FileTree } from 'nextra/components';
|
|
7
|
+
|
|
8
|
+
# Project Structure
|
|
9
|
+
|
|
10
|
+
This page provides a guide for organizing folders and files in Mastra. Mastra is a modular framework, and you can use any of the modules separately or together.
|
|
11
|
+
|
|
12
|
+
You could write everything in a single file (as we showed in the quick start), or separate each agent, tool, and workflow into their own files.
|
|
13
|
+
|
|
14
|
+
We don't enforce a specific folder structure, but we do recommend some best practices, and the CLI will scaffold a project with a sensible structure.
|
|
15
|
+
|
|
16
|
+
## Using the CLI
|
|
17
|
+
|
|
18
|
+
`mastra init` is an interactive CLI that allows you to:
|
|
19
|
+
|
|
20
|
+
- **Choose a directory for Mastra files**: Specify where you want the Mastra files to be placed (default is `src/mastra`).
|
|
21
|
+
- **Select components to install**: Choose which components you want to include in your project:
|
|
22
|
+
- Agents
|
|
23
|
+
- Tools
|
|
24
|
+
- Workflows
|
|
25
|
+
- **Select a default LLM provider**: Choose from supported providers like OpenAI, Anthropic, or Groq.
|
|
26
|
+
- **Include example code**: Decide whether to include example code to help you get started.
|
|
27
|
+
|
|
28
|
+
### Example Project Structure
|
|
29
|
+
|
|
30
|
+
Assuming you select all components and include example code, your project structure will look like this:
|
|
31
|
+
|
|
32
|
+
<FileTree>
|
|
33
|
+
<FileTree.Folder name="root" defaultOpen>
|
|
34
|
+
<FileTree.Folder name="src" defaultOpen>
|
|
35
|
+
<FileTree.Folder name="mastra" defaultOpen>
|
|
36
|
+
<FileTree.Folder name="agents" defaultOpen>
|
|
37
|
+
<FileTree.File name="index.ts" />
|
|
38
|
+
</FileTree.Folder>
|
|
39
|
+
<FileTree.Folder name="tools" defaultOpen>
|
|
40
|
+
<FileTree.File name="index.ts" />
|
|
41
|
+
</FileTree.Folder>
|
|
42
|
+
<FileTree.Folder name="workflows" defaultOpen>
|
|
43
|
+
<FileTree.File name="index.ts" />
|
|
44
|
+
</FileTree.Folder>
|
|
45
|
+
<FileTree.File name="index.ts" />
|
|
46
|
+
</FileTree.Folder>
|
|
47
|
+
</FileTree.Folder>
|
|
48
|
+
<FileTree.File name=".env" />
|
|
49
|
+
</FileTree.Folder>
|
|
50
|
+
</FileTree>
|
|
51
|
+
{/*
|
|
52
|
+
```
|
|
53
|
+
root/
|
|
54
|
+
├── src/
|
|
55
|
+
│ └── mastra/
|
|
56
|
+
│ ├── agents/
|
|
57
|
+
│ │ └── index.ts
|
|
58
|
+
│ ├── tools/
|
|
59
|
+
│ │ └── index.ts
|
|
60
|
+
│ ├── workflows/
|
|
61
|
+
│ │ └── index.ts
|
|
62
|
+
│ ├── index.ts
|
|
63
|
+
├── .env
|
|
64
|
+
``` */}
|
|
65
|
+
|
|
66
|
+
### Top-level Folders
|
|
67
|
+
|
|
68
|
+
| Folder | Description |
|
|
69
|
+
| ---------------------- | ------------------------------------ |
|
|
70
|
+
| `src/mastra` | Core application folder |
|
|
71
|
+
| `src/mastra/agents` | Agent configurations and definitions |
|
|
72
|
+
| `src/mastra/tools` | Custom tool definitions |
|
|
73
|
+
| `src/mastra/workflows` | Workflow definitions |
|
|
74
|
+
|
|
75
|
+
### Top-level Files
|
|
76
|
+
|
|
77
|
+
| File | Description |
|
|
78
|
+
| --------------------- | ---------------------------------- |
|
|
79
|
+
| `src/mastra/index.ts` | Main configuration file for Mastra |
|
|
80
|
+
| `.env` | Environment variables |
|