Repository navigation
fix(codemode): Give scripts the result of MCP tool calls - #2669
Conversation
Co-Authored-By: Lorenzo Cian <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
6 screenshot changes — 6 changed · 0 added · 0 removed Review screenshots in Frameshift |
dcramer
left a comment
There was a problem hiding this comment.
jr can you take one more review pass on this with an agent
There was a problem hiding this comment.
Here is the extra review pass. I checked it against the script path (callFromScript → scriptValue), the direct-call path (Pi tool_result history), pending cards (readMessageCardRefs still reads details.objectCards), normalizeToolResult (it reads only root fields, so a nested result cannot spoof continuation, timed_out, or permission_denied), and the rendered script declaration (result: unknown, required). The fix is correct. The new bridge test fails on main (value: {}) and passes with this change.
One finding is worth deciding before merge:
On direct calls, details.result stores a second copy of the MCP payload in history, and that copy has no size limit. content is already that payload as JSON, capped at 32 KB by boundMcpContent. A direct call now also saves the full structuredContent in its tool_result event. Other tools bound their details (bash 60k chars, webFetch 12k). The gap shows up on large payloads, such as the GoCD pipeline list that motivated this fix. Two ways to fix it:
- Add
resultonly for script calls.callFromScriptwould pass a flag in the execute options, andcallMcpToolwould read it. Nested results are never saved, so history stays as it is today. Scripts keep the full payload, which is the reason for this fix. This costs about 10 lines acrossToolExecuteOptions,executeReviewed, andcallMcpTool. - Cap
resultfor every call. This is smaller, but scripts that read large structured results lose the data again.
I recommend option 1. I can push it to this PR. Otherwise this can merge as is, and the size limit can be a follow-up.
Not changed here, and already true before this PR: cards from MCP calls in a script do not reach the reply, because the codemode result does not forward nested objectCards.
|
defer to @thomasjiangcy on this one as i still havent familiarized myself w/ codemode |
236701d to
cfe0505
Compare
|
I pushed commit I force-pushed the branch back to |
In a Code Mode script, every
callMcpToolcall returned{ objectCards: [] }with no MCP data. In this thread, a GoCDpipelineslookup from a script came back empty. A direct call to the same tool returned the full list.The bridge from #2539 gives a script the
detailsof a call. It uses the text content only whendetailsis{}. ThedetailsofcallMcpToolheld onlyobjectCards, so the MCP data never reached the script. #2544 madecallMcpToola script tool, and #2578 told the model to call MCP tools from scripts. Since #2578, many MCP calls go through this path.The
detailsofcallMcpToolnow includeresult. It holds the MCPstructuredContent, or the text content when the tool returns none.resultis nested, so an MCP server cannot set root fields that the runtime reads, such asobjectCards,continuation, orpermission_denied.objectCardsdoes not change, so reply cards work as before. The Code Mode tool description tells scripts to readresult.Open question: duplicate data on direct calls
Pi keeps
detailsin thetoolResultmessage, and Junior stores the full message in the conversation event log. The model reads onlycontent. So on a direct call,details.resultis a second stored copy of the data incontent. Script calls store no copy. The bridge gives the inner result to the script, and thecodemoderow keeps only the script value and the call status.Most Junior tools already store two copies, because
normalizeToolResultbuildscontentfromdetails. Those tools limit their data at the source, so both copies stay small. MCP is different:contentstops at 32 KB, butdetails.resulthas no limit. For the GoCDpipelinescall above, the stored row is 16.8 KB today, andresultadds about 10 KB. A large MCP response is stored in full.A smaller alternative is to add
resultonly for script calls.callFromScriptwould pass a flag in theexecuteoptions, andcallMcpToolwould addresultonly when the flag is set. Direct calls would then store no copy, and scripts would still get the full data. This PR does not include that change. The reviewer decides between the two.Known gap: cards from MCP calls in a script do not reach the reply, because the
codemoderesult does not forward nestedobjectCards. This was true before this change.via @lcian.
--
View Session [Sentry]