Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# introspection checks. Installs the published package and launches the stdio server.
FROM node:22-slim
RUN npm install -g @espanol/mcp
ENTRYPOINT ["espanol-mcp"]
ENTRYPOINT ["node", "/usr/local/lib/node_modules/@espanol/mcp/dist/index.js"]
19 changes: 17 additions & 2 deletions packages/mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* - Bilingual document creation (create_bilingual_doc)
*/

import { readFileSync } from "node:fs";
import { readFileSync, realpathSync } from "node:fs";
import { pathToFileURL } from "node:url";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { registerDocsTools } from "./tools/docs.js";
Expand Down Expand Up @@ -76,8 +77,22 @@ async function main(): Promise<void> {
// No need to log anything as stdout/stderr are used for the protocol
}

function isCurrentFileEntrypoint(): boolean {
const entrypoint = process.argv[1];

if (!entrypoint) {
return false;
}

try {
return import.meta.url === pathToFileURL(realpathSync(entrypoint)).href;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle preserve-symlinks-main bin launches

When users launch the package bin symlink with NODE_OPTIONS=--preserve-symlinks-main or node --preserve-symlinks-main, Node keeps import.meta.url as the symlink URL while this check compares it only to the realpath target, so isCurrentFileEntrypoint() returns false and main() never starts, leaving MCP clients without a handshake. The old guard succeeded in that mode; compare against both the realpath URL and the original entrypoint URL.

Useful? React with 👍 / 👎.

} catch {
return import.meta.url === pathToFileURL(entrypoint).href;
}
}

// Start the server if this file is run directly
if (import.meta.url === `file://${process.argv[1]}`) {
if (isCurrentFileEntrypoint()) {
main().catch((error) => {
const message = error instanceof Error ? error.message : String(error);
console.error(JSON.stringify({ level: "fatal", error: "MCP_STARTUP_FAILED", message }));
Expand Down
Loading