Skip to content

Commit 1d8efaa

Browse files
authored
Merge pull request #24 from navapbc/fg/store-playwright-artifacts
feat: enable playwright artifacts and screenshot protocol
2 parents 605c3e9 + 2f13246 commit 1d8efaa

File tree

4 files changed

+40
-35
lines changed

4 files changed

+40
-35
lines changed

mastra-test-app/docs/DEPLOYMENT_NOTES.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This guide provides an exact, copy‑pasteable sequence to deploy `mastra-test-a
66
- Google Cloud project with billing enabled
77
- `gcloud` CLI installed and authenticated
88
- API keys: OpenAI, Anthropic, Exa
9-
- PostgreSQL connection URL (Neon or other)
9+
- PostgreSQL connection URL (currently Neon)
1010

1111
---
1212

@@ -72,7 +72,7 @@ NODE_ENV=production
7272
EOF
7373
```
7474

75-
### 6) Build and (optionally) apply migrations
75+
### 7) Build and (optionally) apply migrations
7676
```bash
7777
# Build the app and prepare Prisma client in the output
7878
pnpm build
@@ -81,9 +81,9 @@ pnpm build
8181
npx prisma migrate deploy
8282
```
8383

84-
### 7) Start the application
84+
### 8) Start the application
8585
```bash
86-
pnpm start
86+
pnpm dev
8787
```
8888

8989
The server listens on `0.0.0.0:4111`. In another terminal:
@@ -94,13 +94,6 @@ EXTERNAL_IP=$(gcloud compute instances describe mastra-app \
9494
echo "http://$EXTERNAL_IP:4111/auth/login"
9595
```
9696

97-
Optional: keep it running with PM2
98-
```bash
99-
sudo npm install -g pm2
100-
pm2 start "pnpm start" --name mastra-app
101-
pm2 startup && pm2 save
102-
```
103-
10497
---
10598

10699
### Notes
@@ -111,4 +104,4 @@ pm2 startup && pm2 save
111104
### Troubleshooting
112105
- Prisma client errors: ensure you ran `pnpm build`. If needed, run `npx prisma generate` once, then `pnpm build` again.
113106
- Firewall: verify with `gcloud compute firewall-rules list --filter="name~allow-mastra-app"`.
114-
- Logs: if using PM2, run `pm2 logs mastra-app`; otherwise, observe terminal output from `pnpm start`.
107+
- Logs: if using PM2, run `pm2 logs mastra-app`; otherwise, observe terminal output from `pnpm dev`.

mastra-test-app/src/mastra/agents/web-automation-agent.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { databaseTools } from '../tools/database-tools';
88
import { google } from '@ai-sdk/google';
99
import { openai } from '@ai-sdk/openai';
1010

11-
const base = process.env.DB_BASE || "../";
1211
// Path is relative to .mastra/output/ when bundled
1312
const storage = new LibSQLStore({
1413
url: "file:../mastra.db",
@@ -27,7 +26,7 @@ const memory = new Memory({
2726
lastMessages: 10,
2827
workingMemory: {
2928
enabled: true,
30-
scope: 'resource',
29+
scope: 'thread',
3130
template: `
3231
- **Name**
3332
- **Description**
@@ -98,6 +97,17 @@ export const webAutomationAgent = new Agent({
9897
- Do not fill optional fields unless specified
9998
- Submit only when all required fields are complete
10099
100+
**Screenshot Protocol:**
101+
- Take a screenshot after completing all fields on a page
102+
- Use fullPage: true to capture the complete viewport including off-screen content
103+
- Do NOT take screenshots for individual form interactions
104+
- NEVER specify a filename parameter - let the system auto-generate timestamps
105+
106+
Example screenshot tool call:
107+
browser_take_screenshot({
108+
fullPage: true
109+
})
110+
101111
**Autonomous Progression:**
102112
PROCEED AUTOMATICALLY for:
103113
- Navigation buttons (Next, Continue, Get Started, Proceed, Begin)

mastra-test-app/src/mastra/mcp.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import 'dotenv/config';
22
import { MCPClient } from "@mastra/mcp";
33

4-
// Create separate clients for different tool sets
4+
const buildPlaywrightArgs = () => {
5+
6+
const args = [
7+
"@playwright/mcp@latest",
8+
"--isolated",
9+
"--browser=chromium",
10+
"--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
11+
"--viewport-size=1920,1080",
12+
"--no-sandbox",
13+
"--output-dir=artifacts",
14+
"--save-session",
15+
"--save-trace"
16+
];
17+
18+
return args;
19+
};
20+
521
export const playwrightMCP = new MCPClient({
622
servers: {
723
playwright: {
824
command: "npx",
9-
args: ["@playwright/mcp@latest", "--isolated"],
25+
args: buildPlaywrightArgs(),
26+
env: {
27+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
28+
}
1029
},
1130
},
1231
});
@@ -22,20 +41,3 @@ export const exaMCP = new MCPClient({
2241
},
2342
},
2443
});
25-
26-
// Combined client for agents that need all tools
27-
export const mcp = new MCPClient({
28-
servers: {
29-
playwright: {
30-
command: "npx",
31-
args: ["@playwright/mcp@latest", "--isolated"],
32-
},
33-
exa: {
34-
command: "npx",
35-
args: ["-y", "exa-mcp-server"],
36-
env: {
37-
EXA_API_KEY: process.env.EXA_API_KEY!
38-
},
39-
},
40-
},
41-
});

mastra-test-app/src/mastra/tools/research-tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createTool } from '@mastra/core/tools';
22
import { z } from 'zod';
3-
import { mcp } from '../mcp';
3+
import { exaMCP } from '../mcp';
44

55
// Get EXA tools from MCP
6-
const exaTools = await mcp.getTools();
6+
const exaTools = await exaMCP.getTools();
77

88
// Service/Program Research Tool - for finding government services, programs, applications
99
export const serviceResearchTool = createTool({

0 commit comments

Comments
 (0)