mcp_local_config.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from collections.abc import Mapping
  2. from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, cast
  3. from attrs import define as _attrs_define
  4. from ..types import UNSET, Unset
  5. if TYPE_CHECKING:
  6. from ..models.mcp_local_config_environment import McpLocalConfigEnvironment
  7. T = TypeVar("T", bound="McpLocalConfig")
  8. @_attrs_define
  9. class McpLocalConfig:
  10. """
  11. Attributes:
  12. type_ (Literal['local']): Type of MCP server connection
  13. command (list[str]): Command and arguments to run the MCP server
  14. environment (Union[Unset, McpLocalConfigEnvironment]): Environment variables to set when running the MCP server
  15. enabled (Union[Unset, bool]): Enable or disable the MCP server on startup
  16. """
  17. type_: Literal["local"]
  18. command: list[str]
  19. environment: Union[Unset, "McpLocalConfigEnvironment"] = UNSET
  20. enabled: Union[Unset, bool] = UNSET
  21. def to_dict(self) -> dict[str, Any]:
  22. type_ = self.type_
  23. command = self.command
  24. environment: Union[Unset, dict[str, Any]] = UNSET
  25. if not isinstance(self.environment, Unset):
  26. environment = self.environment.to_dict()
  27. enabled = self.enabled
  28. field_dict: dict[str, Any] = {}
  29. field_dict.update(
  30. {
  31. "type": type_,
  32. "command": command,
  33. }
  34. )
  35. if environment is not UNSET:
  36. field_dict["environment"] = environment
  37. if enabled is not UNSET:
  38. field_dict["enabled"] = enabled
  39. return field_dict
  40. @classmethod
  41. def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
  42. from ..models.mcp_local_config_environment import McpLocalConfigEnvironment
  43. d = dict(src_dict)
  44. type_ = cast(Literal["local"], d.pop("type"))
  45. if type_ != "local":
  46. raise ValueError(f"type must match const 'local', got '{type_}'")
  47. command = cast(list[str], d.pop("command"))
  48. _environment = d.pop("environment", UNSET)
  49. environment: Union[Unset, McpLocalConfigEnvironment]
  50. if isinstance(_environment, Unset):
  51. environment = UNSET
  52. else:
  53. environment = McpLocalConfigEnvironment.from_dict(_environment)
  54. enabled = d.pop("enabled", UNSET)
  55. mcp_local_config = cls(
  56. type_=type_,
  57. command=command,
  58. environment=environment,
  59. enabled=enabled,
  60. )
  61. return mcp_local_config