수동 설치
이 가이드를 사용하여 독립형 Mastra 서버를 단계별로 수동으로 구축하세요. 대부분의 경우 다음을 따르는 것이 더 빠릅니다.quickstart guide, which achieves the same result using the create-mastra명령. 기존 프로젝트의 경우 다음을 사용할 수도 있습니다.mastra init.
읽다https://mastra.ai/guides/getting-started/manual-install.md 을 설치한 다음 Mastra 프로젝트를 만들 수 있도록 도와주세요. 프로젝트 이름을 무엇으로 할지 물어보고 그 이름을 폴더 이름으로 사용하세요.
지침지침에 대한 직접 링크
자동 CLI Tool을 사용하지 않으려면 아래 가이드에 따라 프로젝트를 직접 설정할 수 있습니다.
새 프로젝트를 만들고 디렉터리를 변경합니다.
mkdir my-first-agent && cd my-first-agent새로운 생성
package.jsonfile:- npm
- pnpm
- Yarn
- Bun
npm initpnpm inityarn initbun init다음 종속성을 설치합니다.
- 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@^4추가하다
devandbuildscripts to yourpackage.jsonfile:package.json{"scripts": {"dev": "mastra dev","build": "mastra build"}}만들기
tsconfig.jsonfile:touch tsconfig.json다음 구성을 추가합니다.
tsconfig.json{"compilerOptions": {"target": "ES2022","module": "ES2022","moduleResolution": "bundler","esModuleInterop": true,"forceConsistentCasingInFileNames": true,"strict": true,"skipLibCheck": true,"noEmit": true,"outDir": "dist"},"include": ["src/**/*"]}정보마스트라에는 현대가 필요합니다
moduleandmoduleResolutionsettings. UsingCommonJSornodewill cause resolution errors.만들기
.envfile:touch .envAPI 키를 추가하세요.
.envGOOGLE_API_KEY=<your-api-key>노트이 가이드에서는 Google Gemini를 사용하지만 지원되는 모든 제품을 사용할 수 있습니다.model provider, including OpenAI, Anthropic, and more.
만들기
weather-tool.tsfile:mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.ts다음 코드를 추가하세요.
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`,}},})정보우리는 단축하고 단순화했습니다
weatherTool예시를 참조하세요. 완성된 날씨 Tool은 다음에서 확인할 수 있습니다: Giving an Agent a Tool.만들기
weather-agent.tsfile:mkdir -p src/mastra/agents && touch src/mastra/agents/weather-agent.ts다음 코드를 추가하세요.
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 },})Mastra 진입점을 만들고 Agent를 등록합니다.
touch src/mastra/index.ts다음 코드를 추가하세요.
src/mastra/index.tsimport { Mastra } from '@mastra/core'import { weatherAgent } from './agents/weather-agent.ts'export const mastra = new Mastra({agents: { weatherAgent },})이제 시작할 수 있습니다Studio and test your agent.
- npm
- pnpm
- Yarn
- Bun
npm run devpnpm run devyarn devbun run dev
다음 단계다음 단계에 대한 직접 링크
- 프로젝트 구조 검토: 방법을 이해하다
src/mastra/파일은 Agent, Tool, Workflow, 스토리지 및 구성에 각각 대응합니다. - Studio에서 Agent 테스트: 로컬 Studio UI를 열고 날씨 Agent를 실행합니다.
- Agent과 함께 Tool 사용: 예제 날씨 Tool을 API 또는 서비스를 호출하는 실제 Tool로 대체합니다.
- Memory 추가: 대화 기록 및 사용자별 컨텍스트를 유지합니다.
- 스토리지 구성: Memory, Workflow, Observability 및 기타 런타임 상태를 위한 영구 스토리지 어댑터를 추가합니다.
- 빌드 및 배포: Mastra 서버를 구축하고 호스팅 플랫폼에 배포합니다.