Repository navigation
fix(basic-host): serve sandbox.html when the checkout is under a dotted directory - #812
Open
kristian-presso wants to merge 1 commit into
Conversation
…ed directory `res.sendFile` with an absolute path and no `root` makes `send` check every segment of the path for dotfiles, and it ignores dotfiles by default. So when any directory above examples/basic-host starts with a dot (`.cache/`, `.runs/`, a `.worktrees/` checkout), the sandbox server answers 404 for sandbox.html while the host page, served through `express.static` with a root, loads fine. The View then never renders. Pass the file name with `root: DIRECTORY` so only the relative path is checked, as `express.static` already does for the host page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DyfRBGJuWRersRLswfqPwd
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
basic-hostanswers 404 forsandbox.htmlwhen the checkout sits anywhere under a directory whose name starts with a dot. The host page still loads, so the View silently never renders. This passesroottores.sendFileso only the file name is checked.Motivation and Context
I test MCP App Views against
basic-hostfrom automated evaluation runs, which keep their working copies under a.runs/directory. There the host page loaded, but every View stayed blank and the browser showed a 404 for the sandbox iframe, which pointed at my app rather than at the host.The cause is in
examples/basic-host/serve.ts:Express passes this to
send, whosedotfilesoption defaults to"ignore". With an absolute path and noroot,sendchecks every segment of the full path, so any dotted directory above the example (.runs/,.cache/, a.worktrees/checkout) makes it return 404. The host page is not affected becauseexpress.static(DIRECTORY)passes a root, and then only the path below the root is checked. The fix does the same for the sandbox:The
/sandbox.html-only routing and the CSP and cache headers are unchanged.How Has This Been Tested?
basic-host, copied it under<tmp>/.runs/basic-host/and ranbun serve.tsthere withHOST_PORT=18080 SANDBOX_PORT=18081:GET :18080/index.html200,GET :18081/sandbox.html404;Content-Security-Policyheader.sendFile(join(dir, f))returns 404 under.runs/distand 200 underplain/dist;sendFile(f, { root: dir })returns 200 in both.tsc --noEmitinexamples/basic-hostandnpx prettier --checkon the file pass.There is no test harness for
serve.ts(it starts both servers on import), so I have not added one. Happy to add one if you would likeserve.tsto export its apps for testing.Breaking Changes
None.
Types of changes
Checklist
Additional context
The open basic-host PRs (#718, #632) leave this line as it is, so this should not conflict with them.
AI disclosure: traced, prototyped and drafted with Claude Code, which I use as my coding agent.