fix(agent): authenticate platform MCP tools with the run invocation credential - #4487
Conversation
…redential Hosted agent runs could read project files but every create_file failed with authorization-denied: the platform MCP tool source authenticated with the stream credential (runsStream scopes, no files:write) instead of the run invocation credential minted for platform tool callbacks (runsExecute, which carries files:write). Route the verified request credential to the framework-owned platform MCP source while project-code-visible surfaces (agent environment, sandbox) keep the runtime's project credential, preserving the isolation contract of veryfront-issue-inbox#4214. Fixes veryfront-issue-inbox#1327. Claude-Session: https://claude.ai/code/session_019B9SYdGjpN6sQ4424NLv91
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe agent stream now passes the verified run invocation credential to the platform MCP source. Tests now expect platform MCP requests to use the request-scoped user token. ChangesPlatform MCP authentication
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The credential-routing change is consistent with the tested platform and Studio authentication contracts and is mergeable. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Client bundle boundary
A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in |
Automated Code ReviewScore: 88/100 — Good: a tight, well-reasoned fix for a real authz bug, with the isolation boundary it depends on independently verified by tests. Strengths
Minor concerns (non-blocking)
Overall: sound, narrowly-scoped security fix with the right test backing its central claim. Generated by Claude Code |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|



Problem
Hosted agent runs can read project files but cannot write them: every
create_file/update_file/delete_filefrom a schedule-fired or control-plane-verified run fails with[authorization-denied] Access denied, whileget_file/list_filessucceed. This silently breaks every template that persists records from agents (verified live onagentic-inbox-processing-outlook;agentic-job-submission-processinglast wrote successfully on 2026-09-02, before the current runtime rollout).Full analysis: veryfront/veryfront-issue-inbox#1327
Root cause
Since #4214 the hosted agent-stream path hands
withVeryfrontPlatformRemoteToolstheprojectRuntimeToken(ctx.proxyToken) — the stream credential signed withRUNTIME_SCOPES.runsStream, which carriesfiles:readbut nofiles:write. The run invocation credential minted expressly for platform tool callbacks (mintRuntimeInvocationAuthToken→runsExecute, which does carryfiles:write) arrives aspayload.credentials.authTokenbut only reached framework API calls, never the MCP tool source. veryfront-api's scope ladder then correctly denies the write.Fix
Pass the verified request credential (
apiAuthToken) to the framework-owned platform MCP tool source. Project-code-visible surfaces are unchanged and keep the runtime's project credential: the agent environment (VERYFRONT_API_TOKENenv var), the sandbox (projectAgentSandbox.authToken), and Studio remote tools. This preserves #4214's isolation intent — project code and sandbox never see the run credential — while restoring the authority the invocation credential exists to provide ("The runtime calls integration tools back through the platform with this token").apiAuthTokenalready falls back toctx.proxyTokenwhen the payload carries no credential, so behavior for token-less requests is unchanged.Red/green
The existing tests pinned the regressed routing. Red: flipping the platform-MCP authorization assertions to expect the request credential fails on main (3 tests: control-plane stream config, legacy stream policy identities, credential isolation). Green: the one-line token routing change. The isolation test's environment assertion (
VERYFRONT_API_TOKEN: "run-scoped-token") still passes untouched, demonstrating the env boundary holds.deno task test:file src/server/handlers/request/agent-stream.handler.test.ts— 3 passed (67 steps), 0 failed.deno check+deno lint+deno fmt --checkclean on touched files.https://claude.ai/code/session_019B9SYdGjpN6sQ4424NLv91
Summary by CodeRabbit