{"record":{"id":"023fdc6800f53dbb","repo":"iflytek/astron-agent","slug":"40026-failed-to-get-mcp-server-protocol","errorCode":"40026","errorMessage":"Failed to get MCP server protocol","messagePattern":"Failed to get MCP server protocol","errorType":"exception","errorClass":"PluginExc","httpStatus":null,"severity":"error","filePath":"core/agent/service/plugin/mcp.py","lineNumber":183,"sourceCode":"                        response.raise_for_status()\n                        if response.status == 200:\n                            resp = await response.json()\n                            sp.add_info_events(\n                                attributes={\n                                    \"mcp-plugin-list-outputs\": json.dumps(\n                                        resp, ensure_ascii=False\n                                    )\n                                }\n                            )\n                        else:\n                            sp.add_info_events(\n                                attributes={\n                                    \"mcp-plugin-list-outputs\": (\n                                        f\"response code is {response.status}\"\n                                    )\n                                }\n                            )\n                            raise GetMcpPluginExc\n            except asyncio.TimeoutError as e:\n                raise GetMcpPluginExc from e\n\n            code = resp.get(\"code\")\n            if code != 0:\n                raise GetMcpPluginExc\n\n            servers_list = resp.get(\"data\", {}).get(\"servers\", [])\n\n            # Type cast to ensure return type matches annotation\n            return cast(\n                list[dict[Any, Any]],\n                servers_list if isinstance(servers_list, list) else [],\n            )\n\n    @staticmethod\n    async def convert_tool(tool: dict) -> str:\n        property_template = json.dumps(","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/agent/service/plugin/mcp.py#L165-L201","documentation":"GetMcpPluginExc raised in McpPlugin.query_servers (mcp.py:183). When the MCP list-servers HTTP response is not 200 (raise_for_status throws), the exception handler records the status in a span event and re-raises the generic 40026 'Failed to get MCP server protocol'.","triggerScenarios":"POST to LIST_MCP_PLUGIN_URL returning 4xx/5xx during build_tools: plugin service down, bad URL, auth rejected, gateway error (502/503/504).","commonSituations":"MCP plugin service crashed or being redeployed, wrong LIST_MCP_PLUGIN_URL host/port, network policy or DNS failure between agent and plugin, ingress misconfiguration.","solutions":["Read span event 'mcp-plugin-list-outputs' for the HTTP status and inspect MCP plugin service logs.","Verify the plugin service is up and reachable: curl LIST_MCP_PLUGIN_URL from inside the agent container.","Fix the URL/auth configuration if 4xx; restart or scale the plugin service if 5xx.","Wrap build_tools so a transient list failure degrades gracefully instead of failing the whole agent run."],"exampleFix":"// before\nservers = await mcp_plugin.query_servers(span)\n// after\ntry:\n    servers = await mcp_plugin.query_servers(span)\nexcept GetMcpPluginExc:\n    logger.warning(\"MCP server list unavailable; continuing without MCP tools\")\n    servers = []","handlingStrategy":"fallback","validationCode":"import aiohttp\nasync def mcp_list_reachable(url: str) -> bool:\n    try:\n        async with aiohttp.ClientSession() as s:\n            async with s.post(url, json={}, timeout=aiohttp.ClientTimeout(total=5)) as r:\n                return r.status < 500\n    except Exception:\n        return False","typeGuard":"def is_http_ok(response: aiohttp.ClientResponse) -> bool:\n    return response.status == 200","tryCatchPattern":"try:\n    servers = await mcp_plugin.query_servers(span)\nexcept GetMcpPluginExc:\n    logger.warning(\"MCP server list failed; continuing without MCP tools\")\n    servers = []","preventionTips":["Health-check the MCP plugin before build_tools and degrade gracefully","Alert on repeated non-200 responses from the list endpoint","Verify LIST_MCP_PLUGIN_URL host/port and network policies between services","Retry transient 502/503/504 with backoff"],"tags":["mcp","plugin","http","http-status","aiohttp"],"backgroundTag":"http-error-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}