MCPcopy Index your code
hub / github.com/github/copilot-sdk / _verify_protocol_version

Method _verify_protocol_version

python/copilot/client.py:3252–3302  ·  view source on GitHub ↗

Send the ``connect`` handshake (with the optional token) and verify the server's protocol version. Falls back to ``ping`` for legacy servers that don't implement ``connect``.

(self)

Source from the content-addressed store, hash-verified

3250 pass # Ignore handler errors
3251
3252 async def _verify_protocol_version(self) -> None:
3253 """Send the ``connect`` handshake (with the optional token) and verify
3254 the server's protocol version. Falls back to ``ping`` for legacy servers
3255 that don't implement ``connect``."""
3256 if not self._client:
3257 raise RuntimeError("Client not connected")
3258 handshake_start = time.perf_counter()
3259 used_fallback_ping = False
3260 max_version = get_sdk_protocol_version()
3261
3262 server_version: int | None
3263 try:
3264 connect_result = await _InternalServerRpc(self._client)._connect(
3265 _ConnectRequest(token=self._effective_connection_token)
3266 )
3267 server_version = connect_result.protocol_version
3268 except JsonRpcError as err:
3269 if err.code == -32601 or err.message == "Unhandled method connect":
3270 # Legacy server without `connect`; fall back to `ping`. A token, if any,
3271 # is silently dropped — the legacy server can't enforce one.
3272 used_fallback_ping = True
3273 ping_result = await self.ping()
3274 server_version = ping_result.protocol_version
3275 else:
3276 raise
3277
3278 if server_version is None:
3279 raise RuntimeError(
3280 "SDK protocol version mismatch: "
3281 f"SDK supports versions {_MIN_PROTOCOL_VERSION}-{max_version}"
3282 ", but server does not report a protocol version. "
3283 "Please update your server to ensure compatibility."
3284 )
3285
3286 if server_version < _MIN_PROTOCOL_VERSION or server_version > max_version:
3287 raise RuntimeError(
3288 "SDK protocol version mismatch: "
3289 f"SDK supports versions {_MIN_PROTOCOL_VERSION}-{max_version}"
3290 f", but server reports version {server_version}. "
3291 "Please update your SDK or server to ensure compatibility."
3292 )
3293
3294 self._negotiated_protocol_version = server_version
3295 log_timing(
3296 logger,
3297 logging.DEBUG,
3298 "CopilotClient._verify_protocol_version protocol handshake complete",
3299 handshake_start,
3300 protocol_version=server_version,
3301 used_fallback_ping=used_fallback_ping,
3302 )
3303
3304 def _convert_provider_to_wire_format(
3305 self, provider: ProviderConfig | dict[str, Any]

Callers 1

startMethod · 0.95

Calls 6

pingMethod · 0.95
get_sdk_protocol_versionFunction · 0.85
_InternalServerRpcClass · 0.85
_ConnectRequestClass · 0.85
log_timingFunction · 0.85
_connectMethod · 0.80

Tested by

no test coverage detected