:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mcp): pin antigravity clients to the legacy dialect (#85513)
Christiaan Hendriksen46646ef4c45f
diff --git a/services/mcp/src/hono/dispatcher.ts b/services/mcp/src/hono/dispatcher.tsindex 065fafb05064..d7dc3f50a2ef 100644--- a/services/mcp/src/hono/dispatcher.ts+++ b/services/mcp/src/hono/dispatcher.ts@@ -21,6 +21,7 @@ import GUIDELINES from '@shared/guidelines.md'import { randomUUID } from 'node:crypto'import { mapErrorToAuthResponse } from '@/lib/auth-errors'+import { isLegacyDialectOnlyClient } from '@/lib/client-detection'import { MCP_SERVER_NAME, MCP_SERVER_VERSION } from '@/lib/constants'import type { RequestProperties } from '@/lib/request-properties'import {@@ -197,8 +198,15 @@ class McpDispatcher {}} else {const message = messages[0]! as { id?: number | string; method?: unknown; params?: unknown }- singleModern = isModernRequest(protocolHeaders, parseRequestProtocolMeta(message.params))+ const protocolMeta = parseRequestProtocolMeta(message.params)+ singleModern = isModernRequest(protocolHeaders, protocolMeta)if (singleModern) {+ // Before header validation, so header-dropping bridges fall back to+ // `initialize` instead of dying on HeaderMismatch. HTTP 200, not the+ // spec's 404: mcp-remote's transport treats any non-2xx as fatal.+ if (message.method === Method.Discover && isLegacyDialectOnlyClient(protocolMeta.clientName)) {+ return jsonRpcErrorResponse(message.id ?? null, ErrorCode.MethodNotFound, 'Method not found')+ }const validationError = validateModernRequest(protocolHeaders, message)if (validationError) {return jsonRpcErrorResponse(diff --git a/services/mcp/src/lib/client-detection.ts b/services/mcp/src/lib/client-detection.tsindex 3f0d5b4f057d..a20328ff748e 100644--- a/services/mcp/src/lib/client-detection.ts+++ b/services/mcp/src/lib/client-detection.ts@@ -103,6 +103,11 @@ export const CODING_AGENT_CLIENT_NAME_FRAGMENTS = ['ando-mcp-gateway',] as const+// Clients that wedge after a stateless `server/discover` but complete the legacy+// handshake, so discover answers method-not-found to push them back to `initialize`.+// Remove an entry once the client completes the stateless dialect.+export const LEGACY_DIALECT_ONLY_CLIENT_NAME_FRAGMENTS = ['antigravity'] as const+// Clients that keep the full per-tool roster ("tools" mode) instead of the// single-exec CLI default.// - Cursor self-reports `clientInfo.name` (`cursor-vscode`, `Cursor`); it sends@@ -301,6 +306,10 @@ export class MCPClientProfile {)}+ isLegacyDialectOnly(): boolean {+ return matchesAnyFragment(this.clientName, LEGACY_DIALECT_ONLY_CLIENT_NAME_FRAGMENTS)+ }+isPostHogCodeConsumer(): boolean {return this.consumer === POSTHOG_CODE_CONSUMER}@@ -368,6 +377,10 @@ export function isCliModeEnabledClient(clientName: string | undefined): booleanreturn new MCPClientProfile({ clientName }).isCliModeEnabled()}+export function isLegacyDialectOnlyClient(clientName: string | undefined): boolean {+ return new MCPClientProfile({ clientName }).isLegacyDialectOnly()+}+export function isPostHogCodeConsumer(mcpConsumer: string | undefined): boolean {return new MCPClientProfile({ consumer: mcpConsumer }).isPostHogCodeConsumer()}diff --git a/services/mcp/tests/integration/mcp-protocol-suite.ts b/services/mcp/tests/integration/mcp-protocol-suite.tsindex ee0e0581062d..13c2b2f4a21d 100644--- a/services/mcp/tests/integration/mcp-protocol-suite.ts+++ b/services/mcp/tests/integration/mcp-protocol-suite.ts@@ -1693,12 +1693,15 @@ export function defineStatelessProtocolTests(const METHOD_HEADER = 'Mcp-Method'const NAME_HEADER = 'Mcp-Name'- function statelessParams(params: Record<string, unknown> = {}): Record<string, unknown> {+ function statelessParams(+ params: Record<string, unknown> = {},+ clientName = 'stateless-suite'+ ): Record<string, unknown> {return {...params,_meta: {[META_VERSION_KEY]: STATELESS_VERSION,- [META_CLIENT_INFO_KEY]: { name: 'stateless-suite', version: '0.0.1' },+ [META_CLIENT_INFO_KEY]: { name: clientName, version: '0.0.1' },[META_CLIENT_CAPABILITIES_KEY]: {},},}@@ -1987,6 +1990,49 @@ export function defineStatelessProtocolTests(expect(response.headers.get('mcp-session-id')).toBeNull()})+ // The headerless variant is how stdio bridges (mcp-remote) forward the+ // probe. HTTP 200 in both, not the spec's 404: mcp-remote's transport+ // treats any non-2xx as fatal instead of falling back.+ it.each([+ ['with SEP-2243 headers', {}],+ ['without SEP-2243 headers', { [VERSION_HEADER]: null, [METHOD_HEADER]: null }],+ ] as Array<[string, Record<string, string | null>]>)(+ 'answers server/discover with method-not-found for a legacy-dialect-only client %s',+ async (_label, extraHeaders) => {+ const harness = await getHarness()+ const { response, json } = await postSingle(+ harness,+ 'server/discover',+ statelessParams({}, 'antigravity-client'),+ 'legacy-only',+ extraHeaders+ )++ expect(response.status).toBe(200)+ expect(json.error?.code).toBe(-32601)+ expect(response.headers.get('mcp-session-id')).toBeNull()+ }+ )++ it('keeps legacy initialize working for a legacy-dialect-only client', async () => {+ const harness = await getHarness()+ const { response, json } = await postSingle(+ harness,+ 'initialize',+ {+ protocolVersion: '2025-06-18',+ capabilities: {},+ clientInfo: { name: 'antigravity-client', version: 'v1.0.0' },+ },+ 'legacy-only-init',+ { [VERSION_HEADER]: '2025-06-18' }+ )++ expect(response.status).toBe(200)+ expect(json.error).toBeUndefined()+ expect(json.result?.protocolVersion).toBe('2025-06-18')+ })+it('leaves legacy initialize untouched when it carries a legacy MCP-Protocol-Version header', async () => {const harness = await getHarness()const { response, json } = await postSingle(diff --git a/services/mcp/tests/unit/client-detection.test.ts b/services/mcp/tests/unit/client-detection.test.tsindex a28c87ef4b48..2f33bd43db74 100644--- a/services/mcp/tests/unit/client-detection.test.ts+++ b/services/mcp/tests/unit/client-detection.test.ts@@ -12,6 +12,7 @@ import {TOOLS_MODE_USER_AGENT_FRAGMENTS,isClaudeUiHostClient,isCliModeEnabledClient,+ isLegacyDialectOnlyClient,isPostHogCodeConsumer,isToolsModeClient,resolveEffectiveClientName,@@ -182,6 +183,27 @@ describe('isPostHogCodeConsumer', () => {})})+describe('isLegacyDialectOnlyClient', () => {+ it.each([+ ['antigravity-client'],+ ['antigravity'],+ ['Antigravity'],+ ['antigravity-client/1.2.3'],+ // Bridge variants are gated too: their fallback lands on the legacy+ // handshake, which works, while their stateless support varies by version.+ ['antigravity-client (via mcp-remote 0.1.37)'],+ ])('returns true for %s', (clientName) => {+ expect(isLegacyDialectOnlyClient(clientName)).toBe(true)+ })++ it.each([['claude-code'], ['cursor'], ['mcp-remote-fallback-test'], [''], [undefined]])(+ 'returns false for %s',+ (clientName) => {+ expect(isLegacyDialectOnlyClient(clientName)).toBe(false)+ }+ )+})+describe('isToolsModeClient', () => {it.each([['cursor'], ['Cursor'], ['cursor-vscode'], ['cursor/1.2.3'], ['cursor-editor']])('returns true for client name %s',