Skip to content

Commit 1881c57

Browse files
committed
fix(pdf-server): support computer:// URL scheme for local files
Some clients (e.g. Claude Code) use computer:// instead of file:// for local file references. Handle both schemes in isFileUrl and fileUrlToPath.
1 parent d1ea22b commit 1881c57

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

examples/pdf-server/server.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ describe("validateUrl with MCP roots (allowedLocalDirs)", () => {
292292
const result = validateUrl(pathToFileUrl(filePath));
293293
expect(result.valid).toBe(true);
294294
});
295+
296+
it("should accept computer:// URLs as local files", () => {
297+
const dir = path.resolve(import.meta.dirname);
298+
allowedLocalDirs.add(dir);
299+
300+
const filePath = path.join(dir, "server.ts");
301+
const encoded = encodeURIComponent(filePath).replace(/%2F/g, "/");
302+
const result = validateUrl(`computer://${encoded}`);
303+
expect(result.valid).toBe(true);
304+
});
295305
});
296306

297307
describe("isAncestorDir", () => {

examples/pdf-server/server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const DIST_DIR = import.meta.filename.endsWith(".ts")
6060
// =============================================================================
6161

6262
export function isFileUrl(url: string): boolean {
63-
return url.startsWith("file://");
63+
return url.startsWith("file://") || url.startsWith("computer://");
6464
}
6565

6666
export function isArxivUrl(url: string): boolean {
@@ -81,7 +81,10 @@ export function normalizeArxivUrl(url: string): string {
8181
}
8282

8383
export function fileUrlToPath(fileUrl: string): string {
84-
return decodeURIComponent(fileUrl.replace("file://", ""));
84+
// Support both file:// and computer:// (used by some clients for local files)
85+
return decodeURIComponent(
86+
fileUrl.replace(/^(?:file|computer):\/\//, ""),
87+
);
8588
}
8689

8790
export function pathToFileUrl(filePath: string): string {
@@ -365,7 +368,7 @@ async function refreshRoots(server: Server): Promise<void> {
365368
const { roots } = await server.listRoots();
366369
allowedLocalDirs.clear();
367370
for (const root of roots) {
368-
if (root.uri.startsWith("file://")) {
371+
if (isFileUrl(root.uri)) {
369372
const dir = fileUrlToPath(root.uri);
370373
const resolved = path.resolve(dir);
371374
try {

0 commit comments

Comments
 (0)