Skip to content

Commit

Permalink
Merge pull request #1275 from mastra-ai/update-installation-docs
Browse files Browse the repository at this point in the history
Mastra init local dev docs
  • Loading branch information
TheIsrael1 authored Jan 3, 2025
2 parents ce97e55 + eb3d30d commit 26e1d4d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 52 deletions.
59 changes: 7 additions & 52 deletions docs/src/pages/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Then, initialize a TypeScript project including the `@mastra/core` package:
npm init -y
npm install typescript tsx @types/node zod --save-dev
npm install @mastra/core@alpha
npm install -D mastra@alpha
npx tsc --init
```

Expand Down Expand Up @@ -152,56 +153,10 @@ This registers your agent with Mastra so that `mastra dev` can discover and serv

</Steps>

## Add to Existing Project

<Steps>

### Install the CLI

If you have an existing project and want to add Mastra, first install the mastra CLI.

<Tabs items={["npm", "yarn", "pnpm"]}>
<Tabs.Tab>

```bash copy
npm i -g mastra
```

</Tabs.Tab>
<Tabs.Tab>
```bash copy
yarn i -g mastra
```
</Tabs.Tab>
<Tabs.Tab>
```bash copy
pnpm i -g mastra
```
</Tabs.Tab>
</Tabs>

### Initialize Mastra

To then intialize mastra in your project by following out interactive setup, run:

```bash copy
mastra init
```

### Set Up your API Key

Add the API key for your configured LLM provider in your `.env` file.

```env
OPENAI_API_KEY=<your-openai-key>
```

</Steps>
Note: If you prefer to run the command with flags (non-interactive mode) and include the example code, you can use:
```bash copy
mastra init --dir src/mastra --components agents,tools --llm openai --example
```
This allows you to specify your preferences upfront without being prompted.
<Callout type="info">
To add Mastra to an existing project, see our Local dev docs on [mastra
init](/docs/local-dev/mastra-init).
</Callout>

## Start the Mastra Server

Expand All @@ -212,10 +167,10 @@ Mastra provides commands to serve your agents via REST endpoints
Run the following command to start the Mastra server:

```bash copy
npx mastra dev
npm run dev
```

If you have the mastra CLI installed globally, run:
If you have the mastra CLI installed, run:

```bash copy
mastra dev
Expand Down
1 change: 1 addition & 0 deletions docs/src/pages/docs/local-dev/_meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const meta = {
"mastra-init": "Mastra Init",
"mastra-dev": "Mastra Dev",
engine: "Mastra Engine",
syncs: "Syncs",
Expand Down
59 changes: 59 additions & 0 deletions docs/src/pages/docs/local-dev/mastra-init.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Tabs } from "nextra/components";

# Mastra Init

The `mastra init` command helps you add Mastra to an existing project. This command provides an interactive setup process to configure Mastra in your project.

## Using the CLI

### Install the CLI

First, install the mastra CLI.

<Tabs items={["npm", "yarn", "pnpm"]}>
<Tabs.Tab>

```bash copy
npm i -g mastra
```

</Tabs.Tab>
<Tabs.Tab>
```bash copy
yarn i -g mastra
```
</Tabs.Tab>
<Tabs.Tab>
```bash copy
pnpm i -g mastra
```
</Tabs.Tab>
</Tabs>

### Initialize Mastra

To initialize mastra in your project by following the interactive setup, run:

```bash copy
mastra init
```

### Set Up your API Key

Add the API key for your configured LLM provider in your `.env` file.

```env
OPENAI_API_KEY=<your-openai-key>
```

## Non-Interactive Mode

If you prefer to run the command with flags (non-interactive mode) and include the example code, you can use:

```bash copy
mastra init --dir src/mastra --components agents,tools --llm openai --example
```

This allows you to specify your preferences upfront without being prompted.

- [Mastra Init reference](../reference/cli/init.mdx)

0 comments on commit 26e1d4d

Please sign in to comment.