{"record":{"id":"91604638523be9d9","repo":"agentscope-ai/agentscope","slug":"mcp-card-name-r-produced-an-invalid-client-e","errorCode":null,"errorMessage":"MCP {card.name!r} produced an invalid client: {e}","messagePattern":"MCP (.+?) produced an invalid client: (.+?)","errorType":"exception","errorClass":"MCPRenderError","httpStatus":null,"severity":"error","filePath":"src/agentscope/app/_service/_mcp_render.py","lineNumber":166,"sourceCode":"        values,\n        declared,\n        missing,\n    )\n\n    if missing:\n        raise MCPRenderError(\n            f\"MCP {card.name!r} needs a value for: \"\n            f\"{', '.join(sorted(missing))}\",\n        )\n\n    try:\n        return MCPClient(\n            name=name or card.name,\n            is_stateful=card.is_stateful,\n            mcp_config=config,\n        )\n    except ValueError as e:\n        raise MCPRenderError(\n            f\"MCP {card.name!r} produced an invalid client: {e}\",\n        ) from e\n","sourceCodeStart":148,"sourceCodeEnd":169,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/_service/_mcp_render.py#L148-L169","documentation":"If the values pass schema and required checks but MCPClient(...) construction raises ValueError, render_mcp wraps it as MCPRenderError with the client's message. The rendered config itself is structurally invalid for the MCP client (bad URL, unsupported transport fields, malformed headers, etc.).","triggerScenarios":"Values that type-check but produce an invalid mcp_config — e.g. a malformed URL, invalid transport type string, or header/env entries the MCPClient constructor rejects via ValueError.","commonSituations":"URLs missing a scheme (example.com instead of https://example.com), trailing whitespace in endpoints, unsupported transport names after a library upgrade, or templated env values that render to empty strings.","solutions":["Read the wrapped ValueError message — it names the invalid config field","Normalize inputs (strip whitespace, add URL scheme) before rendering","Check MCPClient's accepted transport/field names for your agentscope version","Add a unit test that renders the card with representative values to catch config drift"],"exampleFix":"# before\nclient = render_mcp(card, values={\"url\": \"example.com/mcp\"})\n# after\nclient = render_mcp(card, values={\"url\": \"https://example.com/mcp\"})","handlingStrategy":"try-catch","validationCode":"from yarl import URL\nu = URL(values[\"url\"])\nif not u.is_absolute():\n    raise ValueError(\"MCP url must include scheme, e.g. https://...\")","typeGuard":"def is_valid_mcp_url(url: str) -> bool:\n    from yarl import URL\n    u = URL(url.strip())\n    return u.is_absolute() and u.scheme in {\"http\", \"https\"}","tryCatchPattern":"try:\n    client = render_mcp(card, values)\nexcept MCPRenderError as e:\n    if \"invalid client\" in e.args[0]:\n        # log values (redact secrets), fix config per inner message\n        ...","preventionTips":["Normalize and strip URL inputs before rendering","Keep MCPClient field names in sync with your agentscope version","Smoke-test render_mcp in CI with representative card values"],"tags":["mcp","client-construction","validation","config"],"backgroundTag":"invalid-client-config","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}