Skip to content

Sanitize AgentMail message read arguments - #13

Open
toanminhbui wants to merge 1 commit into
mainfrom
vee/sanitized-agentmail-read-tools
Open

toanminhbui wants to merge 1 commit into
mainfrom
vee/sanitized-agentmail-read-tools

Conversation

@toanminhbui

Copy link
Copy Markdown
Contributor

Problem

list_messages and search_messages from the AgentMail connection fail whenever Vee reads email:

  • MCP error -32602: Invalid arguments for tool list_messages: expected: "date" received: "Invalid Date" path: ["before"] / ["after"]
  • With explicit RFC 3339 dates, a generic upstream HTTP 400: Request validation failed.

get_inbox works, so auth/transport are healthy. Prompt-level fixes (PR #12) did not help because the empty strings originate from the model filling optional fields of the raw tool schema, and Eve/@ai-sdk/mcp pass model-emitted arguments to the MCP server verbatim — AgentMail then parses "" as a datetime.

Fix

Follow the established list_agentmail_inboxes pattern (authored tools calling the authenticated MCP connection directly), with argument sanitization at the boundary we control:

  • Add sanitizeAgentMailArguments (agent/lib/agentmail-sanitize.ts) — recursively strips empty strings, empty arrays, and null/undefined while preserving meaningful falsy values (false, 0).
  • Add authored wrapper tools list_agentmail_messages and search_agentmail_messages with clean typed input schemas (RFC 3339 datetimes, non-empty query) that sanitize arguments before callTool.
  • Instructions now route reads/searches through the wrappers and ban the raw list_messages/search_messages; raw tools remain exposed but unused. get_thread stays as-is for full threads.
  • Extract shared agentMailAuthOptions; update connection description and changelog.

Argument names/types were verified against AgentMail's canonical mcp-manifest.json.

Verification

  • pnpm typecheck — pass
  • pnpm test — 10/10 pass (6 new sanitizer tests + 4 existing)
  • pnpm build — pass
  • Live Slack test pending deployment; upstream report to AgentMail recommended regardless.

@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vee Ready Ready Preview Aug 24, 2026 3:09pm

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