어댑터 고정
그만큼@mastra/fastify패키지는 Mastra를 실행하기 위한 서버 어댑터를 제공합니다.고정하다. 일반적인 어댑터 개념(생성자 옵션, 초기화 흐름 등)은 다음을 참조하세요.서버 어댑터.
설치설치에 대한 직접 링크
Fastify 어댑터 및 Fastify 프레임워크를 설치합니다.
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/fastify@latest fastify
pnpm add @mastra/fastify@latest fastify
yarn add @mastra/fastify@latest fastify
bun add @mastra/fastify@latest fastify
사용예사용예에 대한 직접 링크
server.ts
import Fastify from 'fastify'
import { MastraServer } from '@mastra/fastify'
import { mastra } from './mastra'
const app = Fastify({ logger: true })
const server = new MastraServer({ app, mastra })
await server.init()
app.listen({ port: 3000 }, (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Server running on ${address}`)
})
생성자 매개변수생성자 매개변수에 대한 직접 링크
app:
FastifyInstance
Fastify 앱 인스턴스
mastra:
Mastra
Mastra 인스턴스
prefix?:
string
= ''
경로 경로 접두사(예:
/api/v2)openapiPath?:
string
= ''
OpenAPI 명세를 제공할 경로(예:
/openapi.json)bodyLimitOptions?:
BodyLimitOptions
요청 본문 크기 제한
streamOptions?:
StreamOptions
= { redact: true }
스트림 마스킹 구성입니다. true(기본값)이면 클라이언트로 보내기 전에 스트림 청크에서 민감한 데이터(시스템 Prompt, Tool 정의, API 키)를 마스킹합니다.
customRouteAuthConfig?:
Map<string, boolean>
경로별 인증 재정의입니다. 키는
METHOD:PATH 형식입니다(예: GET:/api/health). 값이 false이면 경로가 공개되고, true이면 인증이 필요합니다.tools?:
ToolsInput
서버에서 사용할 수 있는 Tool
taskStore?:
InMemoryTaskStore
A2A(Agent-to-Agent) 작업을 위한 작업 저장소
mcpOptions?:
MCPOptions
MCP 전송 옵션입니다. Cloudflare Workers 또는 Vercel Edge 같은 상태 비저장 환경에서는
serverless: true로 설정하세요.원시 경로 보호원시 경로 보호에 대한 직접 링크
requiresAuth 같은 Mastra 관리 인증 및 경로 메타데이터가 필요하다면 registerApiRoute()를 사용하는 것이 좋습니다. 앱에 직접 마운트된 원시 Fastify 경로에는 createAuthMiddleware()를 사용하세요.
server.ts
import Fastify from 'fastify'
import { createAuthMiddleware, MastraServer } from '@mastra/fastify'
import { mastra } from './mastra'
const app = Fastify()
const server = new MastraServer({ app, mastra })
await server.init()
app.get('/custom/protected', { preHandler: createAuthMiddleware({ mastra }) }, async request => {
const user = request.requestContext.get('user')
return { user }
})
app.get(
'/custom/public',
{ preHandler: createAuthMiddleware({ mastra, requiresAuth: false }) },
async () => {
return { ok: true }
},
)
수동 초기화수동 초기화에 대한 직접 링크
사용자 정의 미들웨어 순서가 필요하다면 init() 대신 각 메서드를 개별적으로 호출하세요. 자세한 내용은 수동 초기화를 참조하세요.
예예에 대한 직접 링크
- 고정 어댑터: 기본 Fastify 서버 설정
관련된관련된에 대한 직접 링크
- 서버 어댑터: 공유 어댑터 개념
- Mastra서버 참조: 전체 API 참조
- createRoute() 참조: 유형이 안전한 사용자 지정 경로 만들기