{"record":{"id":"00f2202f025efa59","repo":"langchain-ai/deepagents","slug":"invalid-server-name-server-name-r-server-names","errorCode":null,"errorMessage":"Invalid server name {server_name!r}: server names must contain only alphanumerics, hyphens, and underscores.","messagePattern":"Invalid server name (.+?): server names must contain only alphanumerics, hyphens, and underscores\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_tools.py","lineNumber":871,"sourceCode":"\n    Performs only shape checks — `${VAR}` config interpolation is deferred\n    to activation time so one unset env var only fails its own server\n    rather than hiding every other MCP entry in the same file.\n\n    Args:\n        server_name: Name of the server.\n        server_config: Server configuration dictionary.\n\n    Raises:\n        TypeError: If config fields have wrong types.\n        ValueError: If required fields are missing or server type is unsupported.\n    \"\"\"\n    if not _SERVER_NAME_RE.fullmatch(server_name):\n        error_msg = (\n            f\"Invalid server name {server_name!r}: server names must contain \"\n            \"only alphanumerics, hyphens, and underscores.\"\n        )\n        raise ValueError(error_msg)\n\n    if not isinstance(server_config, dict):\n        error_msg = f\"Server '{server_name}' config must be a dictionary\"\n        raise TypeError(error_msg)\n\n    server_type = _resolve_server_type(server_config)\n\n    if server_type in _SUPPORTED_REMOTE_TYPES:\n        if \"url\" not in server_config:\n            error_msg = (\n                f\"Server '{server_name}' with type '{server_type}' \"\n                \"missing required 'url' field\"\n            )\n            raise ValueError(error_msg)\n\n        if \"command\" in server_config:\n            error_msg = (\n                f\"Server '{server_name}' has type '{server_type}' (remote) \"","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_tools.py#L853-L889","documentation":"_validate_server_config enforces a naming convention: server names must match _SERVER_NAME_RE (alphanumerics, hyphens, underscores only). This keeps names safe for lookup, display, and tool-name composition.","triggerScenarios":"Declaring an MCP server key containing dots, slashes, spaces, or unicode characters in the config; passing such a name to select_server or resolve_and_load_mcp_tools.","commonSituations":"Copying server keys from other tools that allow dots (e.g. 'my.server'); names derived from URLs or file paths; internationalized names.","solutions":["Rename the server key to use only [A-Za-z0-9_-]","Replace dots/spaces with hyphens or underscores","Sanitize names programmatically before passing configs to the library"],"exampleFix":"// before\n{\"mcpServers\": {\"my.server\": {\"type\": \"stdio\", ...}}}\n// after\n{\"mcpServers\": {\"my-server\": {\"type\": \"stdio\", ...}}}","handlingStrategy":"validation","validationCode":"import re\n_SERVER_NAME_RE = re.compile(r'[A-Za-z0-9_-]+')\ndef valid_server_name(name: str) -> bool:\n    return bool(_SERVER_NAME_RE.fullmatch(name))","typeGuard":"def is_valid_server_name(name: object) -> bool:\n    return isinstance(name, str) and bool(re.fullmatch(r'[A-Za-z0-9_-]+', name))","tryCatchPattern":"try:\n    tools = await resolve_and_load_mcp_tools(config)\nexcept ValueError as e:\n    if 'server names must contain' in str(e):\n        config = {re.sub(r'[^A-Za-z0-9_-]', '-', k): v for k, v in config.items()}\n        tools = await resolve_and_load_mcp_tools(config)\n    else:\n        raise","preventionTips":["Sanitize server keys when importing configs from other tools","Use kebab-case names in MCP config files","Run config validation in CI for checked-in MCP configs"],"tags":["mcp","validation","naming"],"backgroundTag":"invalid-server-name","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}