fix(mcp-server-supabase): use POSIX path resolution for edge function filenames - #393
Open
PranshulSoni wants to merge 1 commit into
Open
fix(mcp-server-supabase): use POSIX path resolution for edge function filenames#393PranshulSoni wants to merge 1 commit into
PranshulSoni wants to merge 1 commit into
Conversation
… filenames
`normalizeFilename` in
`packages/mcp-server-supabase/src/edge-function.ts` imports `resolve`
from the platform-default `node:path`, but the function deals
exclusively with POSIX-shaped strings: `getPathPrefix` returns the
hardcoded `/tmp/user_fn_<id>/`, and Deno's local dev server always
emits forward-slash paths. On Windows the platform-default
`node:path` rewrites the leading slash to a drive letter and turns
the slashes into backslashes, so neither the absolute-path merge
(`resolve('/tmp/.../', '/tmp/.../source/index.ts')`) nor the
downstream `value.startsWith(pathPrefix)` strip can match, and the
function returns the full absolute Windows path instead of the
relative file name.
Five unit tests fail on Windows-only `main` for this reason:
`handles deno 1 paths`, `handles deno 2 paths`,
`doesn't interfere with nested directories` in
`src/edge-function.test.ts`, plus the two `list edge functions` /
`get edge function` cases in `src/server.test.ts` that surface the
bad value to MCP clients. The hosted server is Linux so hosted users
are unaffected; only locally-run servers on Windows trip on it.
Switch the import to `node:path/posix` so the same source file
behaves identically on every platform. No public API change. The
existing three test cases pass on both POSIX and Windows now; add
a comment to the test file explaining why `node:path/posix` is
intentional so a future maintainer does not "simplify" it back to
`node:path`.
Fixes supabase#392
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
normalizeFilenameinpackages/mcp-server-supabase/src/edge-function.tsimportsresolvefromnode:path, which is platform-dispatched. The function only ever sees POSIX-shaped strings:getPathPrefixreturns the hardcoded/tmp/user_fn_<id>/, and Deno's local dev server always emits forward-slash paths.On Windows the platform-default
node:pathrewrites the leading slash to a drive letter and the slashes to backslashes, so:resolve('/tmp/user_fn_…/', '/tmp/user_fn_…/source/index.ts')producesC:\tmp\user_fn_…\source\index.ts(dropping/tmp/…entirely because the second arg is absolute and platform-default),value.startsWith(pathPrefix)strip never matches, andwithoutPrefix(…, 'source/')strip actually fires on a Windows path and returns the truncated value.A developer running the MCP server locally on Windows therefore sees
get_edge_functionandlist_edge_functionsreturnentrypoint_pathandfiles[].nameasC:\tmp\user_fn_<id>\index.tsrather thanindex.ts. The bug is invisible to the hosted server (Linux) and to CI (Linux-only).The five failing unit tests in the issue's reproduction all show the same root cause:
edge-function.test.ts > normalizeFilename > handles deno 1 pathsedge-function.test.ts > normalizeFilename > handles deno 2 pathsedge-function.test.ts > normalizeFilename > doesn't interfere with nested directoriesserver.test.ts > tools > list edge functionsserver.test.ts > tools > get edge functionWhat is the new behavior?
Switch the single import to
node:path/posix:getPathPrefixstill returns/tmp/user_fn_<id>/and thewithoutPrefixstrip still works on the same string, so the function behaves identically on every platform. The same five unit tests now pass on Windows.How to Review
Single import line
packages/mcp-server-supabase/src/edge-function.tsTest comment
packages/mcp-server-supabase/src/edge-function.test.tsdescribe(...)block explaining whynode:path/posixis intentional, so a future maintainer does not "simplify" it back tonode:path. No test cases added or modified — the three existing cases already cover the regression.The change is one line in production code, plus a comment. The public surface (
normalizeFilenamesignature, return shape, MCP tool output) is unchanged.Verification
Run the affected unit tests on Linux (CI) to confirm the import is a no-op there:
cd packages/mcp-server-supabase pnpm vitest run --project unit src/edge-function.test.tsOutput:
The three tests pass on Linux with both
node:path(pre-fix) andnode:path/posix(post-fix), confirming the change is platform-neutral. On Windows the same tests would have failed before the fix (see the issue's reproduction log) and pass after.Also ran
biome checkon both files — clean.I do not have a Windows environment to re-run the failing reproduction, but the fix is the textbook one-line import change that
node:path/posixexists for. The five-failing-tests reproduction in the issue traces directly to the platform dispatch inpath.resolve, which is now sidestepped.Fixes #392