I’m getting the following error after installing the n8n mcp community node.
The mcp nodes work for a bit, then the connection closes and give me the following error: Failed to execute operation: Failed to connect to MCP server: MCP error -32000: Connection closed
I’m self hosting using Railway.
Does anyone have a solution for getting this to work consistently?
this helped me fix the issue for gitlab, maybe help you fix for this
const nodeExecutablePath = process.execPath; // Path to the currently running node
const nodeDir = path.dirname(nodeExecutablePath);
const currentPath = process.env.PATH || ‘’;
// Prepend node’s directory to PATH (safer than replacing)
const effectivePath = ${nodeDir}${path.delimiter}${currentPath};
const childEnv = {
...process.env, // Inherit parent environment
...(serverConfig.env || {}), // Add environment vars from config
PATH: effectivePath, // Override PATH to include node dir
}
const params: StdioServerParameters = {
command: serverConfig.command, // Should still be the absolute path to npx here
args: serverConfig.args,
// --- Use the constructed environment ---
env: childEnv,
// cwd: serverConfig.cwd || undefined // Optional: Set working directory
};
const transport = new StdioClientTransport(params);
const client = new McpClient({ name: `mcp-gemini-backend-${serverKey}`, version: "1.0.0" });