{"record":{"id":"87505821c7e8117c","repo":"agentscope-ai/agentscope","slug":"name-required","errorCode":null,"errorMessage":"name required","messagePattern":"name required","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/agentscope/workspace/_mcp_gateway/_mcp_gateway_app.py","lineNumber":125,"sourceCode":"    async def _list_mcps(\n        agent_id: str = \"\",\n        session_id: str = \"\",\n    ) -> list[dict[str, Any]]:\n        return [\n            c.model_dump(mode=\"json\")\n            for c in state.clients.get((agent_id, session_id), {}).values()\n        ]\n\n    @app.post(\"/mcps\")\n    async def _add_mcp(\n        request: Request,\n        agent_id: str = \"\",\n        session_id: str = \"\",\n    ) -> dict[str, Any]:\n        body = await request.json()\n        name = body.get(\"name\", \"\")\n        if not name:\n            raise HTTPException(400, \"name required\")\n        async with state.lock:\n            by_name = state.clients.setdefault((agent_id, session_id), {})\n            if name in by_name:\n                raise HTTPException(\n                    409,\n                    f\"{name!r} already exists for agent={agent_id!r} \"\n                    f\"session={session_id!r}\",\n                )\n            try:\n                by_name[name] = await _build_client(body)\n            except HTTPException:\n                raise\n            except Exception as e:  # noqa: BLE001\n                raise HTTPException(500, f\"connect failed: {e}\") from e\n        return {\"ok\": True}\n\n    @app.delete(\"/mcps/{name}\")\n    async def _remove_mcp(","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/workspace/_mcp_gateway/_mcp_gateway_app.py#L107-L143","documentation":"Raised as HTTP 400 by the gateway's _add_mcp when the JSON body of POST /mcps lacks a non-empty 'name' field. Every registered MCP client must be named so it can be addressed later by /mcps/{name}. It is a simple request-validation error.","triggerScenarios":"POST /mcps with body {} , {\"name\": \"\"}, {\"name\": null}, or a body where the key is misspelled (e.g. 'server' instead of 'name').","commonSituations":"Client sends the connection config (url/command) but forgets the name field, or serializes the name as null/empty string; also sending form-encoded instead of JSON so body.get('name') yields nothing.","solutions":["Include a non-empty \"name\" string in the JSON body of POST /mcps.","Ensure Content-Type: application/json so await request.json() parses.","Check for typos like \"Name\" or \"server_name\" in the payload key."],"exampleFix":"# before\nawait client.post(\"/mcps\", json={\"url\": \"http://localhost:8080/mcp\"})\n\n# after\nawait client.post(\"/mcps\", json={\"name\": \"my-server\", \"url\": \"http://localhost:8080/mcp\"})","handlingStrategy":"validation","validationCode":"def mcp_add_body_ok(body: dict) -> bool:\n    return isinstance(body.get(\"name\"), str) and body[\"name\"].strip() != \"\"","typeGuard":null,"tryCatchPattern":"r = await client.post(\"/mcps\", json=body)\nif r.status_code == 400 and \"name required\" in r.text:\n    body.setdefault(\"name\", \"my-server\")\n    r = await client.post(\"/mcps\", json=body)","preventionTips":["Always include a non-empty 'name' key in the POST /mcps JSON body.","Send Content-Type: application/json.","Build payloads from a dataclass/TypedDict with name required so it can't be omitted."],"tags":["agentscope","mcp","gateway","http-400","validation"],"backgroundTag":"missing-required-field","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}