Skip to content

[Prototype, do not merge] feat(samples): add the inbox decisions MCP server and e2e harness - #4384

Closed
josemontespg wants to merge 1 commit into
inbox/3-cardfrom
inbox/4-server
Closed

josemontespg wants to merge 1 commit into
inbox/3-cardfrom
inbox/4-server

Conversation

@josemontespg

Copy link
Copy Markdown
Collaborator

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.mjs and scripts/e2e/host.js: Playwright with an AppBridge host, 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 --immutable in samples/community, then yarn build and yarn lint pass. 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 as ui/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.
  • Antigravity, Gemini 4 Hydrogen: the first run passed 7 of 8 checks, and all 4 rechecks passed after the fixes. The model called inbox_decisions unprompted in every fresh conversation, and the phishing email's planted instruction to the AI was ignored.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Comment on lines +32 to +33
import {spawnSync} from 'node:child_process';
import {mkdirSync, writeFileSync} from 'node:fs';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the unused spawnSync import and add readFileSync to the node:fs imports to support a cross-platform check of the .env file.

import {mkdirSync, writeFileSync, readFileSync} from 'node:fs';

Comment on lines +97 to +98
const result = spawnSync('grep', ['-Eq', '^GEMINI_API_KEY=.+', join(packageRoot, '.env')]);
return result.status === 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
  }

Comment on lines +90 to +93
warm(): Promise<unknown> {
const view = this.store.view();
return this.recommender.recommend(view, selectDecisions(view));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
});
}

Comment on lines +238 to +239
const decision = pending.find(entry => entry.key === item.key)!;
const applied = this.store.apply(decision, item);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
  1. 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 using optional chaining (?.) or nullish coalescing (??).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant