MCP: windowed get_message body reading#421
Conversation
roborev: Combined Review (
|
f25f1d1 to
c1805ce
Compare
roborev: Combined Review (
|
|
Written by Codex on Wes's behalf: I’m worried this improves MCP response size but may hurt the actual “read this email” workflow.
That makes the current defaults feel too small:
Those are good context-budget limits, but not good read-performance defaults unless body windowing happens at the storage/API layer. I’d suggest one of these before merging:
Two smaller concerns:
|
I'll change it if you really want me to, but the size is already sufficient for most emails, no? I checked my latest 32 work emails and the biggest is 4232 characters. The rest are all under 4k and most are under 2k. (This is considering only the plain text main body of the email, and ignoring HTML and the dozens of previous emails that are quoted at the bottom.) In practice, these are some typical sizes the agent requests when I'm using it:
Well the whole point of this PR is to make it impossible for the agent to load the full body at once, since even when I told it not to do so in the system message, it still ended up doing it and destroying its context window very quickly. In one case it couldn't even finish writing its first response to my first question and had an API error because it used up the entire (1M token!) context window in one response. (Good thing I'm using a cheap model.) In most cases, the agent is looking for facts within the email, not needing to read through the complete email sequentially, and in most cases the complete email fits within the first response anyway, and in the rare cases that these aren't true, it can page through it in multiple calls.
Well, the performance or implementation details aren't a problem for me, but if you want me to have Cursor work on a better implementation, or have your bots work on it, I am fine with either. But I've been using this for a few weeks and it works fine; the LLM is the speed bottleneck anyway. Could that be a separate Issue/PR though?
Well keyword search only looks in the plain text part anyway, right? In the case that an email has HTML but body text is empty, that email won't be returned from a search unless it happens to contain the keyword in the subject line or other metadata?
Yes that will be the next PR. The changes I've been using in my fork are all lined up here: endolith#15 |
Return body_text as a paginated slice instead of the full message body. Adds offset, center_at, max_chars (default 2000, max 4000), body_length, body_returned, and has_more so agents can page through long messages or jump to a match via center_at (byte offset from search_in_message). Values above maxBodyChars clamp to 4000; zero or negative max_chars use the default. Guard against Engine.GetMessage returning (nil, nil) for not-found. Return UTF-8-adjusted offset, body_returned, and has_more so sequential paging (offset += body_returned) does not skip multibyte characters. Co-authored-by: endolith <endolith@gmail.com>
c1805ce to
4f5da6a
Compare
roborev: Combined Review (
|
|
I looked at my own msgvault and I have a lot of large emails, but I think this change makes sense. I'm working on a couple small refinements and then i'll try to get this merged |
Windowed get_message responses are meant to protect MCP context, but blanking HTML made messages without a plain-text body appear unreadable. Preserve the context guard while falling back to a windowed body_html slice for HTML-only messages and advertise the selected body format so clients can interpret the response correctly. The get_message tool description also referred to a follow-up search_in_message tool that is not part of this branch, so keep the current schema self-contained until that tool lands. Generated with Codex (GPT-5) Co-authored-by: Codex <codex@openai.com>
roborev: Combined Review (
|
Windowed get_message should default to plain text for context safety, but mixed text/html messages still need a discoverable way to read the HTML representation. Add an explicit body_format selector so clients can page either representation without restoring unbounded full-body responses. Generated with Codex (GPT-5) Co-authored-by: Codex <codex@openai.com>
roborev: Combined Review (
|
Windowed get_message defaults protect MCP context, but reading a whole long message through repeated pages reloads the same hydrated body each time. Add an explicit full_body escape hatch so clients can intentionally trade context budget for one full selected-body response until backend-side body slicing exists. Generated with Codex (GPT-5) Co-authored-by: Codex <codex@openai.com>
roborev: Combined Review (
|
Return
body_textas a paginated slice instead of the full message body. Addsoffset,center_at,max_chars(default 2000, max 4000),body_length,body_returned, andhas_moreso agents can page through long messages or jump to a match viacenter_at(byte offset fromsearch_in_message, which doesn't exist yet, see endolith@d819d71).Values above maxBodyChars clamp to 4000; zero or negative max_chars use the default.
Followup to #388
(Many of my emails are very long and contain entire conversations, so the LLM retrieving a bunch of them can kill the 1M token context window in a single response. These changes are meant to make the MCP tools return more narrowly-focused content to avoid wasting money and tokens and overwhelming the LLM.)