{"record":{"id":"054186f42ffb8958","repo":"n8n-io/n8n","slug":"failed-to-read-mcp-servers-from-endpoint-respon","errorCode":null,"errorMessage":"Failed to read MCP servers from endpoint: ${response.status}","messagePattern":"Failed to read MCP servers from endpoint: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/vendors/Microsoft/microsoft-utils.ts","lineNumber":240,"sourceCode":"\nasync function getMcpServerConfigsWithoutAudienceTokens(\n\tturnContext: TurnContext,\n\tmcpAuthToken: string,\n) {\n\tMicrosoftToolingUtility.ValidateAuthToken(mcpAuthToken);\n\n\tconst agenticAppId = MicrosoftRuntimeUtility.ResolveAgentIdentity(turnContext, mcpAuthToken);\n\tconst endpoint = getToolingGatewayUrl(agenticAppId);\n\tconst response = await proxyFetch(endpoint, {\n\t\theaders: MicrosoftToolingUtility.GetToolRequestHeaders(\n\t\t\tmcpAuthToken,\n\t\t\tturnContext,\n\t\t\tMICROSOFT_TOOL_OPTIONS,\n\t\t),\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to read MCP servers from endpoint: ${response.status}`);\n\t}\n\n\tconst payload: unknown = await response.json();\n\tconst rawServers = getRawMcpServers(payload);\n\tif (!rawServers) {\n\t\t// Log only the payload type, never the raw body: it's an untrusted external\n\t\t// response that may carry sensitive values.\n\t\tconsole.error('Microsoft MCP server discovery returned an unsupported payload shape', {\n\t\t\tpayloadType: Array.isArray(payload) ? 'array' : typeof payload,\n\t\t});\n\t\tthrow new Error('Failed to read MCP servers from endpoint: response is not a server list');\n\t}\n\n\tconst servers = rawServers\n\t\t.map((rawServer) => normalizeMcpServerConfig(rawServer))\n\t\t.filter((server): server is MCPServerConfig => server !== undefined);\n\n\tconsole.warn(`Microsoft MCP server discovery completed: ${servers.length} servers found`);","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/vendors/Microsoft/microsoft-utils.ts#L222-L258","documentation":"HTTP-status branch of Microsoft MCP server discovery in microsoft-utils. After proxyFetch(endpoint) with the Bot Framework auth headers, if response.ok is false the code throws a bare Error with the HTTP status code. This is a transport-level failure talking to the Microsoft Tooling Gateway.","triggerScenarios":"The Tooling Gateway returns 4xx/5xx: 401/403 if the MCP auth token is expired or lacks scope, 404 if the agentic app id resolved wrong, 5xx for gateway outage, or a network-layer non-2xx from the proxy.","commonSituations":"MCP auth token expired between turns; the agent's app id doesn't resolve to a registered gateway; Tooling Gateway regional outage; tenant not provisioned for MCP.","solutions":["Decode the status: 401/403 → refresh/verify the MCP auth token and scopes; 404 → verify ResolveAgentIdentity returns the right agentic app id; 5xx → transient, retry.","Confirm the Microsoft 365 agent / app registration is granted the MCP/Tooling permissions in the tenant.","Check getToolingGatewayUrl() returns the expected regional endpoint for the tenant.","Retry with backoff for 5xx; surface to admin for 4xx permission errors."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isHttpStatusError(e: unknown): e is Error {\n  return e instanceof Error && /^Failed to read MCP servers from endpoint: \\d{3}$/.test(e.message);\n}","tryCatchPattern":"for (let attempt = 1; attempt <= 3; attempt++) {\n  try { return await getMcpServerConfigsWithoutAudienceTokens(turnContext, token); }\n  catch (e) {\n    const status = parseInt((/^.*?(\\d{3})$/.exec((e as Error).message) ?? [])[1] ?? '', 10);\n    if (attempt === 3 || (status >= 400 && status < 500 && status !== 429)) throw e; // don't retry most 4xx\n    await new Promise(r => setTimeout(r, 1000 * attempt));\n  }\n}","preventionTips":["Refresh the MCP auth token before it expires; surface 401/403 to the admin rather than retrying blindly.","Confirm ResolveAgentIdentity returns the right agentic app id and the Tooling Gateway URL is regionally correct.","Retry 5xx and 429 with backoff; do not retry other 4xx."],"tags":["microsoft","mcp","tooling-gateway","http-error","network","authentication"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}