Skip to content

Commit 94f332d

Browse files
committed
chore: enhance project root validation in middleware and improve POST request handling with dynamic MCP resolution
1 parent ff61335 commit 94f332d

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

.browser-echo-mcp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"url":"http://127.0.0.1:60503","routeLogs":"/__client-logs","timestamp":1755881715965,"pid":47645,"projectRoot":"/Users/kregenrek/projects/vite-browser-logs"}

packages/vite/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ function attachMiddleware(server: any, options: ResolvedOptions) {
191191
const tmpPath = joinPath(tmpdir(), 'browser-echo-mcp.json');
192192
const fromTmp = disc.sourcePath === tmpPath;
193193
const currentCwd = process.cwd();
194-
const matchesProject = isInsideProject(disc.projectRoot, currentCwd);
194+
let matchesProject = isInsideProject(disc.projectRoot, currentCwd);
195+
if (fromTmp) {
196+
try {
197+
matchesProject = !!disc.projectRoot && realpathSync(String(disc.projectRoot)) === realpathSync(currentCwd);
198+
} catch {
199+
matchesProject = false;
200+
}
201+
}
195202
if (!matchesProject && fromTmp) {
196203
announce(`${options.tag} ignoring tmp discovery due to project mismatch`);
197204
} else {
@@ -245,7 +252,9 @@ function attachMiddleware(server: any, options: ResolvedOptions) {
245252

246253
server.middlewares.use(options.route, (req, res, next) => {
247254
if (req.method !== 'POST') return next();
248-
collectBody(req).then((raw) => {
255+
collectBody(req).then(async (raw) => {
256+
// Re-resolve discovery on each POST to avoid sticky routing during startup races
257+
try { await resolveMcp(); } catch {}
249258
let payload: ClientPayload | null = null;
250259
try { payload = JSON.parse(raw.toString('utf-8')); }
251260
catch { res.statusCode = 400; res.end('invalid JSON'); return; }

0 commit comments

Comments
 (0)