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

Method verifyProtocolVersion

nodejs/src/client.ts:1816–1859  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

1814 * that don't implement `connect`.
1815 */
1816 private async verifyProtocolVersion(): Promise<void> {
1817 if (!this.connection) {
1818 throw new Error("Client not connected");
1819 }
1820 const maxVersion = getSdkProtocolVersion();
1821 const raceAgainstExit = <T>(p: Promise<T>): Promise<T> =>
1822 this.processExitPromise ? Promise.race([p, this.processExitPromise]) : p;
1823
1824 let serverVersion: number | undefined;
1825 try {
1826 const result = await raceAgainstExit(
1827 this.internalRpc.connect({ token: this.effectiveConnectionToken })
1828 );
1829 serverVersion = result.protocolVersion;
1830 } catch (err) {
1831 if (
1832 err instanceof ResponseError &&
1833 (err.code === ErrorCodes.MethodNotFound ||
1834 err.message === "Unhandled method connect")
1835 ) {
1836 // Legacy server without `connect`; fall back to `ping`. A token, if any,
1837 // is silently dropped — the legacy server can't enforce one.
1838 serverVersion = (await raceAgainstExit(this.ping())).protocolVersion;
1839 } else {
1840 throw err;
1841 }
1842 }
1843
1844 if (serverVersion === undefined) {
1845 throw new Error(
1846 `SDK protocol version mismatch: SDK supports versions ${MIN_PROTOCOL_VERSION}-${maxVersion}, but server does not report a protocol version. ` +
1847 `Please update your server to ensure compatibility.`
1848 );
1849 }
1850
1851 if (serverVersion < MIN_PROTOCOL_VERSION || serverVersion > maxVersion) {
1852 throw new Error(
1853 `SDK protocol version mismatch: SDK supports versions ${MIN_PROTOCOL_VERSION}-${maxVersion}, but server reports version ${serverVersion}. ` +
1854 `Please update your SDK or server to ensure compatibility.`
1855 );
1856 }
1857
1858 this.negotiatedProtocolVersion = serverVersion;
1859 }
1860
1861 /**
1862 * Gets the ID of the most recently updated session.

Callers 1

startMethod · 0.95

Calls 3

pingMethod · 0.95
getSdkProtocolVersionFunction · 0.90
connectMethod · 0.45

Tested by

no test coverage detected