Manual install
Use this guide to manually build a standalone Mastra server step by step. In most cases, it's quicker to follow the quickstart guide, which achieves the same result using the mastra create command. For existing projects, you can also use mastra init.
Read https://mastra.ai/docs/getting-started/manual-install.md and then help me create my Mastra project. Ask me what I want to call my project and use this as the folder name.
InstructionsDirect link to Instructions
If you prefer not to use our automatic CLI tool, you can set up your project yourself by following the guide below.
Create a new project and change directory:
mkdir my-first-agent && cd my-first-agentGenerate a new
package.jsonfile:- npm
- pnpm
- Yarn
- Bun
npm initpnpm inityarn initbun initInstall the following dependencies:
- npm
- pnpm
- Yarn
- Bun
npm install -D typescript @types/node mastra@latestnpm install @mastra/core@latest zod@^4pnpm add -D typescript @types/node mastra@latestpnpm add @mastra/core@latest zod@^4yarn add --dev typescript @types/node mastra@latestyarn add @mastra/core@latest zod@^4bun add --dev typescript @types/node mastra@latestbun add @mastra/core@latest zod@^4Add
devandbuildscripts to yourpackage.jsonfile:package.json{"scripts": {"dev": "mastra dev","build": "mastra build"}}Create a
tsconfig.jsonfile:touch tsconfig.jsonAdd the following configuration:
tsconfig.json{"compilerOptions": {"target": "ES2022","module": "ES2022","moduleResolution": "bundler","esModuleInterop": true,"forceConsistentCasingInFileNames": true,"strict": true,"skipLibCheck": true,"noEmit": true,"outDir": "dist"},"include": ["src/**/*"]}infoMastra requires modern
moduleandmoduleResolutionsettings. UsingCommonJSornodewill cause resolution errors.Create an
.envfile:touch .envAdd your API key:
.envGOOGLE_API_KEY=<your-api-key>noteThis guide uses Google Gemini, but you can use any supported model provider, including OpenAI, Anthropic, and more.
Create a
weather-tool.tsfile:mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.tsAdd the following code:
src/mastra/tools/weather-tool.tsimport { createTool } from '@mastra/core/tools'import { z } from 'zod'export const weatherTool = createTool({id: 'get-weather',description: 'Get current weather for a location',inputSchema: z.object({location: z.string().describe('City name'),}),outputSchema: z.object({output: z.string(),}),execute: async ({ location }) => {return {output: `The weather in ${location} is sunny`,}},})infoWe've shortened and simplified the
weatherToolexample here. You can see the complete weather tool under Giving an Agent a Tool.Create a
weather-agent.tsfile:mkdir -p src/mastra/agents && touch src/mastra/agents/weather-agent.tsAdd the following code:
src/mastra/agents/weather-agent.tsimport { Agent } from '@mastra/core/agent'import { weatherTool } from '../tools/weather-tool.ts'export const weatherAgent = new Agent({id: 'weather-agent',name: 'Weather Agent',instructions: `You are a helpful weather assistant that provides accurate weather information.Your primary function is to help users get weather details for specific locations. When responding:- Always ask for a location if none is provided- If the location name isn't in English, please translate it- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")- Include relevant details like humidity, wind conditions, and precipitation- Keep responses concise but informativeUse the weatherTool to fetch current weather data.`,model: 'google/gemini-2.5-pro',tools: { weatherTool },})Create the Mastra entry point and register your agent:
touch src/mastra/index.tsAdd the following code:
src/mastra/index.tsimport { Mastra } from '@mastra/core'import { weatherAgent } from './agents/weather-agent.ts'export const mastra = new Mastra({agents: { weatherAgent },})You can now launch Studio and test your agent.
- npm
- pnpm
- Yarn
- Bun
npm run devpnpm run devyarn devbun run dev
Next stepsDirect link to Next steps
- Review the project structure: Understand how
src/mastra/files map to agents, tools, workflows, storage, and configuration. - Test your agent in Studio: Open the local Studio UI and run the weather agent.
- Use tools with agents: Replace the example weather tool with a real tool that calls an API or service.
- Add memory: Persist conversation history and user-specific context.
- Configure storage: Add a persistent storage adapter for memory, workflows, observability, and other runtime state.
- Build and deploy: Build the Mastra server and deploy it to a hosting platform.