iflytek/astron-agent · error · CustomException

MCP_REQUEST_ERROR

MCP_REQUEST_ERROR

Error message

Status code: {resp.status}, Response content: {await resp.text()}

What it means

The MCP node POSTs a JSON-RPC-ish request body to the MCP server; if the HTTP response status is not 200, it builds a cause_error string containing the status code and the raw response text and raises CustomException with MCP_REQUEST_ERROR. The err_msg is not set, so the useful detail is in cause_error.

Solutions

  1. Inspect cause_error in the node run logs for the status code and response body
  2. Verify the MCP server URL and that the service is up (curl the endpoint directly)
  3. Fix authentication/headers if the status is 401/403; if 5xx, check MCP server logs and retry after recovery
Defensive patterns

Strategy: try-catch

Validate before calling

import aiohttp
async def mcp_reachable(url: str) -> bool:
    try:
        async with aiohttp.ClientSession() as s:
            async with s.get(url, timeout=aiohttp.ClientTimeout(total=5)) as r:
                return r.status < 500
    except aiohttp.ClientError:
        return False

Try / catch

try:
    result = await node.async_execute(variable_pool, span)
except CustomException as e:
    if e.err_code == CodeEnum.MCP_REQUEST_ERROR:
        log.error("MCP HTTP failure: %s", e.cause_error)  # status + response text
        # 5xx: retry with backoff; 4xx: fix URL/auth

Prevention

When it happens

Trigger: The HTTP call to the MCP server (mcpServerUrl or resolved from mcpServerId) returns 404 (wrong URL/path), 401/403 (auth), 500 (server crash), or 502 (gateway) instead of 200.

Common situations: MCP server URL mistyped or pointing at a retired endpoint; server not deployed/reachable in the cluster; missing auth headers rejected by the server; MCP service overloaded behind a gateway.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/05d4bf7857097ebe. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/engine/nodes/mcp/mcp_node.py:96

            # Prepare MCP tool call request
            url = f"{os.getenv('MCP_BASE_URL')}/api/v1/mcp/call_tool"
            req_body = {
                "mcp_server_id": self.mcpServerId,
                "mcp_server_url": self.mcpServerUrl,
                "tool_name": self.toolName,
                "tool_args": inputs,
            }
            # Execute MCP tool call
            async with aiohttp.ClientSession(
                timeout=ClientTimeout(total=5 * 60, sock_connect=30)
            ) as session:
                async with session.post(url, json=req_body) as resp:
                    if resp.status != httpx.codes.OK:
                        cause_error = (
                            f"Status code: {resp.status}, "
                            f"Response content: {await resp.text()}"
                        )
                        raise CustomException(
                            err_code=CodeEnum.MCP_REQUEST_ERROR,
                            cause_error=cause_error,
                        )

                    res_json = json.loads(await resp.text())
                    await span.add_info_events_async(
                        {"mcp_response": json.dumps(res_json, ensure_ascii=False)}
                    )

                    # Check for errors in response
                    if res_json.get("code") != 0:
                        msg = f"reason {res_json.get('message')}"
                        span.add_error_event(msg)
                        raise CustomException(
                            err_code=CodeEnum.MCP_REQUEST_ERROR,
                            err_msg=msg,
                            cause_error=msg,
                        )

View on GitHub (pinned to 5e758547a8)