An AI-powered agent that processes food orders from emails automatically. The agent monitors an email inbox, uses LLM-based intent detection and data extraction, and submits orders via MCP (Model Context Protocol) tools.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ Email Inbox │────▶│ Agent │────▶│ MCP Server │
│ (IMAP) │ │ (LangChain) │ │ (Products/DB) │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ │
│ LangSmith │
│ (Observability)│
│ │
└─────────────────┘
email-order-intake/
├── apps/
│ ├── agent/ # AI Agent (to be built in workshop)
│ │ └── src/
│ │ ├── agent/ # Pipeline nodes and orchestration
│ │ ├── mcp/ # MCP client connection
│ │ ├── services/ # Email listener
│ │ └── utils/ # PII redaction utilities
│ ├── dashboard/ # Next.js dashboard to view orders
│ └── mcp/ # MCP server with product/order tools
├── packages/
│ ├── config/ # Shared TypeScript config
│ └── logger/ # Shared logging utilities
The agent processes emails through a sequential pipeline:
- Intent Detection - Determines if the email is a food order
- Data Extraction - Extracts customer name and order items
- Product Lookup - Enriches items with product details via MCP
- Order Submission - Submits the finalized order to the database
- Node.js 24+
- pnpm 9+
- OpenAI API key (or compatible provider)
- Neon Database (for orders and products)
- Email account with IMAP access (Gmail recommended)
- LangSmith account (for observability - optional but recommended)
pnpm installCopy the example files and fill in your credentials:
# MCP Server
cp apps/mcp/.env.example apps/mcp/.env
# Agent (if present)
cp apps/agent/.env.example apps/agent/.env
# Dashboard
cp apps/dashboard/.env.example apps/dashboard/.envIMAP requires an app password (not your regular account password). To generate one:
- Gmail: Go to App Passwords and create a new app password
- Other providers: Check your email provider's documentation for app-specific passwords
Add your email credentials to apps/agent/.env:
EMAIL_ID=your-email@gmail.com
EMAIL_HOST=imap.gmail.com
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-passwordTest the connection to your email account:
pnpm agent:test:emailNote: This step is only required if you're using your own Neon database. If you're using a pre-configured workshop database, skip to step 4.
- Go to neon.com and create an account
- Create a new project and copy your connection string (starts with
postgresql://) - Add the connection string to
apps/mcp/.envandapps/dashboard/.envasORDER_DATABASE_URL - Run the migrations and seed:
# Run migrations
pnpm --filter mcp migrate
# Seed products data
pnpm --filter mcp seed:products# Start MCP server (required)
pnpm mcp:dev
# Start the Agent (in a separate terminal)
pnpm agent:dev
# Or start the MCP server and Agent simultaneously
pnpm dev
# Start the dashboard (optional, in a separate terminal)
pnpm dashboard:dev| Command | Description |
|---|---|
pnpm dev |
Start MCP server and agent in development |
pnpm build |
Build all packages |
pnpm check-types |
Type-check all packages |
| Command | Description |
|---|---|
pnpm mcp:dev |
Start MCP server in dev mode |
pnpm mcp:test:db |
Test database connection |
pnpm mcp:test:inspector |
Open MCP Inspector UI |
| Command | Description |
|---|---|
pnpm agent:dev |
Start agent in dev mode |
pnpm agent:dev:debug |
Start agent with debug logging |
pnpm agent:test:nodes |
Test the pipeline with sample emails |
pnpm agent:test:email |
Test email connection |
| Command | Description |
|---|---|
pnpm dashboard:dev |
Start dashboard in dev mode |
If you're here for the workshop, see WORKSHOP.md for step-by-step instructions to build the agent from scratch.
- Runtime: Node.js with TypeScript
- AI/LLM: LangChain with OpenAI
- Protocol: Model Context Protocol (MCP)
- Email: IMAP via imapflow
- Database: Neon PostgreSQL
- Observability: LangSmith
- Logging: Pino
MIT