Repository navigation
[Prototype, do not merge] feat(samples): add the inbox decisions MCP server and e2e harness - #4384
josemontespg wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an end-to-end test harness, unit tests, and the core MCP server implementation for the inbox assistant app, along with updated documentation. The review feedback focuses on improving robustness and cross-platform compatibility: replacing the platform-dependent 'grep' command in the E2E script with native Node.js file operations, handling potential promise rejections in 'tools.warm()' to prevent server crashes on startup, and avoiding unsafe non-null assertions on array lookup results in 'inbox_tools.ts'.
| import {spawnSync} from 'node:child_process'; | ||
| import {mkdirSync, writeFileSync} from 'node:fs'; |
| const result = spawnSync('grep', ['-Eq', '^GEMINI_API_KEY=.+', join(packageRoot, '.env')]); | ||
| return result.status === 0; |
There was a problem hiding this comment.
Replace the platform-dependent grep command with a native Node.js file read and regex test. This ensures the script runs successfully on Windows and other platforms without grep installed.
try {
const content = readFileSync(join(packageRoot, '.env'), 'utf8');
return /^GEMINI_API_KEY=.+/m.test(content);
} catch {
return false;
}| warm(): Promise<unknown> { | ||
| const view = this.store.view(); | ||
| return this.recommender.recommend(view, selectDecisions(view)); | ||
| } |
There was a problem hiding this comment.
Since tools.warm() is called with void during server startup in app.ts, any promise rejection from recommender.recommend (e.g., due to network issues or API errors) will result in an unhandled promise rejection, which can crash the Node.js process. Catch and handle or discard the error inside warm() to ensure server stability.
| warm(): Promise<unknown> { | |
| const view = this.store.view(); | |
| return this.recommender.recommend(view, selectDecisions(view)); | |
| } | |
| warm(): Promise<unknown> { | |
| const view = this.store.view(); | |
| return this.recommender.recommend(view, selectDecisions(view)).catch(() => { | |
| // Discard warming errors to prevent unhandled rejections on startup | |
| }); | |
| } |
| const decision = pending.find(entry => entry.key === item.key)!; | ||
| const applied = this.store.apply(decision, item); |
There was a problem hiding this comment.
Avoid using the non-null assertion operator (!) on lookup results (such as Array.prototype.find) that may fail. Instead, allow the variable to be nullable and handle the undefined case downstream.
| const decision = pending.find(entry => entry.key === item.key)!; | |
| const applied = this.store.apply(decision, item); | |
| const decision = pending.find(entry => entry.key === item.key); | |
| if (!decision) { | |
| continue; | |
| } | |
| const applied = this.store.apply(decision, item); |
References
- Avoid using the non-null assertion operator (
!) on lookup results (such asArray.prototype.find) that may fail. Instead, allow the variable to be nullable and handle theundefinedcase downstream using optional chaining (?.) or nullish coalescing (??).
Internal M1 proof-of-concept sample for @a2ui/embed (A2UI in MCP Apps), not meant to merge. Builds on #4334.
Summary
Last of four PRs for the inbox decisions sample. This one wires everything into an MCP server: one model-facing tool,
inbox_decisions(focus?), plus app-only actions to confirm, apply, undo, refresh and rewrite drafts, and two follow-ups ("Why do you recommend…", "Rewrite my reply…").It also adds an end-to-end harness that renders the card in a minimal MCP Apps host under the default CSP, and the full README.
Changes
src/app.ts,src/server.ts,src/tools.ts: the stdio server, its instructions and the tool. The tool name carries the intent, since hosts may show only names.src/inbox_tools.ts: per-card state, the confirm and apply flow, undo, refresh, and text summaries that say what was applied, scheduled and is still pending.scripts/e2e.mjsandscripts/e2e/host.js: Playwright with anAppBridgehost, a cross-origin sandboxed frame and the default MCP Apps CSP, in light and dark themes.README.md: what the card shows, how it works, safety and how to run it.Verification
yarn install --immutableinsamples/community, thenyarn buildandyarn lintpass.yarn test: 59 tests pass.yarn e2e: 8 of 8 checks pass with Gemini and with rule-based picks. They cover the card with 5 tabs, the dark theme, a row that follows a changed choice, an edited and rewritten draft, follow-ups asui/message, the confirm summary, applying in place with Undo, the model context refresh after Apply, an empty group, and 0 CSP violations. Heights are 104 to 671 px; the largest model context is 10.1 KB.inbox_decisionsunprompted in every fresh conversation, and the phishing email's planted instruction to the AI was ignored.