Skip to content

Fix Windows path handling in StructuredLogger#28

Merged
AJITHMELVIN merged 2 commits intocommerce-operations-foundation:developfrom
VirtoCommerce:fix/windows-path-compatibility
Mar 18, 2026
Merged

Fix Windows path handling in StructuredLogger#28
AJITHMELVIN merged 2 commits intocommerce-operations-foundation:developfrom
VirtoCommerce:fix/windows-path-compatibility

Conversation

@basilkot
Copy link
Copy Markdown
Contributor

@basilkot basilkot commented Feb 26, 2026

Summary

Two Windows path compatibility fixes in the server package:

  1. StructuredLoggernew URL(import.meta.url).pathname returns /C:/Users/... on Windows, causing path.resolve to produce invalid doubled drive letters (C:\C:\Users\...\logs). Replaced with fileURLToPath(import.meta.url) and path.sep for cross-platform compatibility.

  2. AdapterFactoryimport(absolutePath) fails on Windows because Node.js ESM loader interprets the drive letter (e.g. E:) as a URL scheme (ERR_UNSUPPORTED_ESM_URL_SCHEME). Added pathToFileURL() to convert native paths to file:// URLs before dynamic import.

Problem

When running @cof-org/mcp on Windows (e.g., via Claude Desktop), the server crashes on startup:

Logger issue:

ENOENT: no such file or directory, mkdir 'C:\C:\Users\...\node_modules\@cof-org\mcp\logs'

Adapter loading issue:

ERR_UNSUPPORTED_ESM_URL_SCHEME: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'e:'

Fix

  • server/src/logging/structured-logger.ts — use fileURLToPath() + path.sep
  • server/src/adapters/adapter-factory.ts — use pathToFileURL().href for dynamic imports

Test plan

  • Verify server starts on Windows without log directory errors
  • Verify local adapter loading works on Windows
  • Verify server still works on macOS/Linux (no regression)

basilkot and others added 2 commits February 26, 2026 21:07
`new URL(import.meta.url).pathname` returns `/C:/Users/...` on Windows,
causing `path.resolve` to produce invalid doubled drive letters like
`C:\C:\Users\...` when resolving the log directory.

Replace with `fileURLToPath(import.meta.url)` from the `url` module,
which correctly handles Windows file URLs. Also use `path.sep` instead
of hardcoded `/` for splitting the dist path, ensuring cross-platform
compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`import(absolutePath)` fails on Windows because Node.js ESM loader
interprets the drive letter (e.g. `E:`) as a URL scheme. Convert the
path to a file:// URL before importing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AJITHMELVIN
Copy link
Copy Markdown
Contributor

I ended up doing the same change without realizing this PR was already raised. I am good with merging this change.

@AJITHMELVIN AJITHMELVIN merged commit f47cdf6 into commerce-operations-foundation:develop Mar 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants