examples/server-koa-adapter/README.md
This example demonstrates how to use the @mastra/koa server adapter to run Mastra with Koa.
MastraServerkoa-bodyparser middleware for JSON body parsinginit() with access to Mastra contextctx.state.mastrapnpm install
.env.example to .env and add your OpenAI API key:cp .env.example .env
pnpm start
List agents:
curl http://localhost:4111/api/agents
Health check (custom route):
curl http://localhost:4111/health
Generate a response:
curl -X POST http://localhost:4111/api/agents/assistantAgent/generate \
-H "Content-Type: application/json" \
-d '{"messages": "What is 2+2?"}'
koa-bodyparser middleware for JSON body parsingctx.state.mastra (Koa state pattern)