Unified server configuration supporting both HTTP and STDIO transports. Exactly one of (url, command) must be provided.
| 72 | |
| 73 | |
| 74 | class UnifiedServerConfig(BaseModel): |
| 75 | """Unified server configuration supporting both HTTP and STDIO transports. |
| 76 | |
| 77 | Exactly one of (url, command) must be provided. |
| 78 | """ |
| 79 | |
| 80 | name: str |
| 81 | |
| 82 | # HTTP/SSE transport |
| 83 | url: str | None = None |
| 84 | headers: dict[str, str] | None = None |
| 85 | oauth: OAuthConfig | None = None |
| 86 | |
| 87 | # STDIO transport |
| 88 | command: str | None = None |
| 89 | args: list[str] = Field(default_factory=list) |
| 90 | env: dict[str, str] = Field(default_factory=dict) |
| 91 | |
| 92 | # Common |
| 93 | disabled: bool = False |
| 94 | tool_timeout: float | None = Field( |
| 95 | default=None, description="Per-server tool timeout" |
| 96 | ) |
| 97 | init_timeout: float | None = Field( |
| 98 | default=None, description="Per-server init timeout" |
| 99 | ) |
| 100 | |
| 101 | model_config = {"frozen": True} |
| 102 | |
| 103 | @field_validator("name") |
| 104 | @classmethod |
| 105 | def validate_name(cls, v: str) -> str: |
| 106 | """Validate server name.""" |
| 107 | if not v or not v.strip(): |
| 108 | raise ValueError("Server name cannot be empty") |
| 109 | return v.strip() |
| 110 | |
| 111 | @field_validator("url") |
| 112 | @classmethod |
| 113 | def validate_url_format(cls, v: str | None) -> str | None: |
| 114 | """Validate URL format if provided.""" |
| 115 | if v and not v.startswith(("http://", "https://")): |
| 116 | raise ValueError("URL must start with http:// or https://") |
| 117 | return v |
| 118 | |
| 119 | @field_validator("command") |
| 120 | @classmethod |
| 121 | def validate_command_not_empty(cls, v: str | None) -> str | None: |
| 122 | """Validate command is not empty string if provided.""" |
| 123 | if v is not None and not v.strip(): |
| 124 | raise ValueError("Command cannot be empty string") |
| 125 | return v.strip() if v else None |
| 126 | |
| 127 | def model_post_init(self, __context) -> None: |
| 128 | """Validate that exactly one of (url, command) is provided.""" |
| 129 | has_url = self.url is not None |
| 130 | has_command = self.command is not None |
| 131 |
no outgoing calls