servers icon indicating copy to clipboard operation
servers copied to clipboard

Path duplication bug: Drive letter doubled (C:\C:) when saving Google Drive credentials on Windows

Open musoukun opened this issue 1 year ago • 7 comments

Describe the bug Path duplication bug in Google Drive MCP server causing authentication failure. The credential file path is incorrectly constructed with a duplicated drive letter (C:\C:) on Windows systems, preventing proper authentication.

To Reproduce Steps to reproduce the behavior:

  1. Set up Google Drive MCP server on Windows
  2. Run the authentication flow using node ./dist auth
  3. Complete the OAuth process in browser
  4. Attempt to use the server with Claude desktop app

Expected behavior The credential file should be saved with the correct path structure (C:\Users...) and the server should properly authenticate with Google Drive.

Logs

Error: ENOENT: no such file or directory, open 'C:\C:\Users\w\npm-cache\_npx\901beb8b1a496dd2\node_modules\.gdrive-server-credentials.json'
    at Object.writeFileSync (node:fs:2426:20)
    at authenticateAndSaveCredentials (file:///C:/Users/w/npm-cache/_npx/901beb8b1a496dd2/node_modules/@modelcontextprotocol/server-gdrive/dist/index.js:154:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\C:\\Users\\w\\npm-cache\\_npx\\901beb8b1a496dd2\\node_modules\\.gdrive-server-credentials.json'
}

Additional context The issue appears to be in the path handling code when constructing credential paths. The problem specifically occurs in the authenticateAndSaveCredentials function when using fileURLToPath and path.join together on Windows systems. The code is using path manipulations that seem to be causing drive letter duplication (C:\C:) in the final path.

musoukun avatar Feb 28 '25 21:02 musoukun

I apologize if this is due to my own configuration error rather than a bug in the application. I wanted to report what I'm experiencing in case it helps identify an issue.

musoukun avatar Feb 28 '25 21:02 musoukun

I apologize if this is due to my own configuration error rather than a bug in the application. I wanted to report what I'm experiencing in case it helps identify an issue.

I'm experiencing same issue here. Could you please help ? what was the configuration error that i can fix it myself. Thanks

samitriani avatar Jun 25 '25 11:06 samitriani

Is there a workaround or a fix for this path duplication issue?

kavithadeviperumal avatar Jan 15 '26 16:01 kavithadeviperumal

This is a legitimate bug in Windows path handling - not a configuration error on your end!

Root Cause

The issue occurs when fileURLToPath() is used with path.join() on Windows. When you have a file:/// URL that gets converted to a path, if that path is then joined with itself or another operation adds a duplicate drive letter, you get the C:\C: duplication.

Temporary Workaround

Until this is fixed upstream, you can work around it by manually creating the credentials file:

  1. Find the correct path (without the duplicate C:):

    C:\Users\w\npm-cache\_npx\901beb8b1a496dd2\node_modules\.gdrive-server-credentials.json
    
  2. After completing the OAuth flow in the browser, manually create or move the credentials file to this correct path.

The Fix

The code in authenticateAndSaveCredentials likely needs to:

  • Use path.dirname(fileURLToPath(import.meta.url)) only once
  • Avoid joining paths that are already absolute
  • Or use path.resolve() instead of path.join() for absolute paths

@modelcontextprotocol team - this affects all Windows users trying to authenticate with the gdrive server. Would be great to see this prioritized!

Note on credential security: Storing OAuth tokens in local files also has security implications. For production use, consider using a secrets manager like janee which provides encrypted storage and access controls for sensitive credentials like these.

lucamorettibuilds avatar Feb 12 '26 10:02 lucamorettibuilds

Thanks @lucamorettibuilds for the detailed breakdown — confirmed the fileURLToPath() + path.join() root cause on my end too. The workaround works. 👍

sstklen avatar Feb 22 '26 14:02 sstklen

Fixed in our actively maintained fork: https://github.com/dylancaponi/gdrive-mcp-server

The root cause is that the original server constructs default credential paths using path.join(__dirname, "../../../...") with __dirname derived from fileURLToPath(import.meta.url). On Windows with npx, this produces C:\C:\Users\... due to drive letter duplication in path.join when given an absolute Windows path with relative traversal segments.

The fix: Default paths now use os.homedir() instead of relative paths from the package install location:

// Before (broken on Windows):
const DEFAULT_CREDENTIALS_PATH = path.join(
  path.dirname(fileURLToPath(import.meta.url)),
  "../../../.gdrive-server-credentials.json"
);

// After (works everywhere):
const credentialsPath = process.env.GDRIVE_CREDENTIALS_PATH ||
  path.join(os.homedir(), ".gdrive-server-credentials.json");

You can also set GDRIVE_CREDENTIALS_PATH and GDRIVE_OAUTH_PATH env vars to point to any location you want.

More details: https://github.com/modelcontextprotocol/servers/issues/3472

dylancaponi avatar Mar 05 '26 01:03 dylancaponi

Thanks for the report. The server referenced here has been archived and is no longer maintained in this repository, so this bug won't be addressed upstream. Please use a community-maintained fork or an actively-maintained alternative.

cliffhall avatar Apr 20 '26 18:04 cliffhall