
nextjs mastra mcp with lwa
使用 AWS CDK 和 Lambda 架构运行 Mastra Agent 和 Next.js 应用,并结合 Amazon Bedrock 和 Playwright MCP。
Repository Info
About This Server
使用 AWS CDK 和 Lambda 架构运行 Mastra Agent 和 Next.js 应用,并结合 Amazon Bedrock 和 Playwright MCP。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Next.js Mastra MCP with Lambda Web Adapter
AWS CDK project for running Mastra Agent and Next.js application with Lambdalish Architecture and Amazon Bedrock to interact with MCP Server.
As an example, this project uses Playwright MCP server.
Prerequisites
- Node.js: v20 or higher
- AWS CDK: v2 or higher
- Docker: v20 or higher
- AWS Credentials: Access Key / Secret Key / Session Token
Architecture
!Architecture
Project Structure
.
├── web/ # Next.js application
│ ├── Dockerfile # Container image definition
│ ├── package.json # App dependencies
│ ├── tsconfig.json # TypeScript config for app
│ ├── parameter.ts # App configuration
│ ├── public/ # Static files
│ ├── run.sh # Startup script
│ ├── src/ # Application source code
│ │ ├── app/ # Next.js App Router
│ │ ├── lib/ # Library code (e.g., bedrock-client.ts)
│ │ └── mastra/ # Mastra application root
│ │ ├── index.ts # Mastra instance configuration
│ │ ├── agents/ # Agent definitions
│ │ └── mcp/ # MCP configuration
│ └── ... # Other config/build files
├── infra/ # Infrastructure as Code (AWS CDK)
│ ├── bin/ # CDK entry point
│ │ └── mastra-mcp-on-lwa.ts
│ ├── lib/ # CDK stack definitions
│ │ └── mastra-mcp-on-lwa-stack.ts
│ ├── test/ # Infrastructure tests
│ │ └── mastra-mcp-on-ecs.test.ts
│ ├── cdk.json # CDK configuration
│ ├── package.json # Infra dependencies
│ ├── tsconfig.json # TypeScript config for infra
│ └── parameter.ts # Infra configuration
├── image/ # Architecture diagrams and images
├── package.json # Root project dependencies
├── tsconfig.json # Root TypeScript configuration
└── README.md # This file
Getting Started
Install Dependencies
All commands should be executed at the repository root.
First, install dependencies for the root project.
npm install:all
Next, set up environment variables by creating .env.development file which contains the aws credentials.
cat << EOF > web/.env.development
ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXX
SESSION_TOKEN=XXXXXXXXXXXXXXXXXXXX
EOF
Local Development
If you want to change the application configuration, you can modify the app/parameter.ts.
To start local mastra http server only, run the following command.
npm run mastra:dev
To start local Next.js server with mastra, run the following command.
npm run next:dev
Production Deployment
If you want to change the infrastructure configuration, you can modify the infra/parameter.ts.
If you've never used CDK before, you need to Bootstrap for the first time only. The following command is unnecessary if your environment is already bootstrapped.
npx -w infra cdk bootstrap
To deploy the application to AWS, run the following command.
npm run cdk:deploy
To remove the application from AWS, run the following command.
npm run cdk:destroy
Quick Start
Clone the repository
git clone https://github.com/tsukuboshi/nextjs-mastra-mcp-with-lwaInstall dependencies
cd nextjs-mastra-mcp-with-lwa
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.