MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / __post_init__

Method __post_init__

src/mcp/client/client.py:207–226  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

205 _connect: _Connector = field(init=False, repr=False, compare=False)
206
207 def __post_init__(self) -> None:
208 if self.mode not in ("legacy", "auto") and self.mode not in MODERN_PROTOCOL_VERSIONS:
209 hint = (
210 f" ({self.mode!r} is a handshake-era version — use mode='legacy')"
211 if self.mode in HANDSHAKE_PROTOCOL_VERSIONS
212 else ""
213 )
214 raise ValueError(
215 f"mode must be 'legacy', 'auto', or one of {list(MODERN_PROTOCOL_VERSIONS)}; got {self.mode!r}{hint}"
216 )
217
218 srv = self.server
219 if isinstance(srv, MCPServer):
220 srv = srv._lowlevel_server # pyright: ignore[reportPrivateUsage]
221 if isinstance(srv, Server):
222 self._connect = _connect_inproc(srv)
223 elif isinstance(srv, str):
224 self._connect = _connect_transport(streamable_http_client(srv))
225 else:
226 self._connect = _connect_transport(srv)
227
228 async def _build_session(self, exit_stack: AsyncExitStack) -> ClientSession:
229 """Enter the resolved connector and return an un-entered ClientSession."""

Callers

nothing calls this directly

Calls 3

streamable_http_clientFunction · 0.90
_connect_inprocFunction · 0.85
_connect_transportFunction · 0.85

Tested by

no test coverage detected