Skip to content

Commit dcf65a6

Browse files
authored
fix: detect bin wrapper entry point in isMainModule check (#179)
Fixes isMainModule detection when MCP server is invoked via bin/mcp-wordpress.js wrapper (e.g. Cursor IDE, npx). process.argv[1] points to the bin wrapper rather than dist/index.js, causing main() to never be called. - Add mcp-wordpress.js to the isMainModule check (POSIX + Windows paths) - Refactor to named variables for clarity Co-authored-by: Thorsten <tw-360vier@users.noreply.github.com>
1 parent 725bc45 commit dcf65a6

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ async function main() {
140140
}
141141
}
142142

143-
// Check if running as main module - handle both direct execution and DXT entry point
143+
// Check if running as main module - handle direct execution, DXT, and bin wrapper entry points
144+
const currentFile = fileURLToPath(import.meta.url);
145+
const callerFile = process.argv[1];
146+
144147
const isMainModule =
145-
process.argv[1] === fileURLToPath(import.meta.url) ||
146-
process.argv[1]?.endsWith("/index.js") ||
147-
process.argv[1]?.endsWith("\\index.js") ||
148-
!process.argv[1]; // When run through DXT, process.argv[1] might be undefined
148+
callerFile === currentFile ||
149+
callerFile?.endsWith("/index.js") ||
150+
callerFile?.endsWith("\\index.js") ||
151+
callerFile?.endsWith("/mcp-wordpress.js") || // invoked via bin/mcp-wordpress.js wrapper
152+
callerFile?.endsWith("\\mcp-wordpress.js") ||
153+
!callerFile; // When run through DXT, process.argv[1] might be undefined
149154

150155
if (isMainModule) {
151156
main();

0 commit comments

Comments
 (0)