{"record":{"id":"7a930e3a6546db53","repo":"Mintplex-Labs/anything-llm","slug":"error-message-7a930e","errorCode":null,"errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/mcpServers.js","lineNumber":26,"sourceCode":"\nfunction mcpServersEndpoints(app) {\n  if (!app) return;\n\n  app.get(\n    \"/mcp-servers/force-reload\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (_request, response) => {\n      try {\n        const mcp = new MCPCompatibilityLayer();\n        await mcp.reloadMCPServers();\n        return response.status(200).json({\n          success: true,\n          error: null,\n          servers: await mcp.servers(),\n        });\n      } catch (error) {\n        console.error(\"Error force reloading MCP servers:\", error);\n        return response.status(500).json({\n          success: false,\n          error: error.message,\n          servers: [],\n        });\n      }\n    }\n  );\n\n  app.get(\n    \"/mcp-servers/list\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (_request, response) => {\n      try {\n        const servers = await new MCPCompatibilityLayer().servers();\n        return response.status(200).json({\n          success: true,\n          servers,\n        });","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/mcpServers.js#L8-L44","documentation":"Catch-all 500 for POST /mcp-servers/reload (admin only). MCPCompatibilityLayer.reloadMCPServers() restarts every configured MCP server; failure means at least one entry could not be spawned or connected — bad command/binary, missing env vars/API keys, invalid config, stdio spawn failure, or SSE/WebSocket handshake timeout. error.message names the underlying cause.","triggerScenarios":"POST /mcp-servers/reload as admin when any configured MCP server fails to (re)launch: command not found on PATH, npx package download failure, missing env credentials for remote servers, unreachable SSE endpoint.","commonSituations":"Editing the MCP config and leaving a typo in command/args; the host lacks node/npx for stdio servers; a remote MCP server rotated its auth credentials.","solutions":["Read error.message — MCP client errors usually name the server and the failing phase (spawn/connect/handshake)","Inspect the MCP servers config entry cited by the error (command path, args, env)","Run the server's command manually from the app's shell to confirm it starts","Fix or remove the broken entry and POST reload again — it is idempotent"],"exampleFix":"// before\nawait new MCPCompatibilityLayer().reloadMCPServers();\n// after — validate each stdio command exists before reloading\nconst { execSync } = require('child_process');\nfor (const s of configuredServers.filter((s) => s.type === 'stdio'))\n  execSync(`command -v ${s.command}`); // throws early with a clear message\nawait new MCPCompatibilityLayer().reloadMCPServers();","handlingStrategy":"retry","validationCode":"// Confirm servers enumerate cleanly before forcing a reload\nconst list = await fetch('/mcp-servers/list');\nif (!list.ok) throw new Error('MCP layer unhealthy — fix config before reload');","typeGuard":null,"tryCatchPattern":"for (const delay of [0, 2000, 8000]) {\n  await sleep(delay);\n  try { return await fetch('/mcp-servers/reload', { method: 'POST' }); }\n  catch (e) { last = e; } // transient npx download / spawn races often clear on retry\n}\nthrow last;","preventionTips":["Smoke-test each stdio server command from the app shell before adding it to config","Pin npx package versions so spawns are deterministic","Treat reload as idempotent — safe to re-issue after fixing the cited server"],"tags":["mcp","admin-only","process-spawn","http-500"],"backgroundTag":"mcp-server-connection-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}