Notify opted-in stdio MCP servers of auth changes (#43428)

## What changed

Advertise the experimental `codex/auth-change` capability for stdio MCP connections with an auth manager. When the server opts in, send `notifications/codex/authChanged` after initialization and on subsequent auth changes, with credential and owner generation counters and no credentials.

Track owner changes separately from credential refreshes so consumers can detect login, logout, or user, workspace, and auth-mode changes even when notifications coalesce. Treat credential changes with incomplete owner identity as owner changes as well.

Tie the notification watcher to the managed client's lifetime, limit each send to five seconds, and close the connection if a subsequent notification fails.

## Testing

Add tests for credential refreshes versus owner changes, coalesced logout and account switches, capability opt-in, notification payloads, and watcher cleanup.

GitOrigin-RevId: 35a99f5252bd48ca60a71fbdd1f708a8158e812c
This commit is contained in:
jif
2026-09-07 10:37:46 +00:00
committed by copyberry
parent 0b263a3331
commit 0df39752cb
12 changed files with 345 additions and 1 deletions
+1
View File
@@ -79,6 +79,7 @@ async fn test_step(
);
let tool_catalog = Arc::new(ClientToolCatalog::new(vec![tool.clone()]));
let managed_client = Arc::new(ManagedClient {
_auth_change_notifications: None,
client: Arc::clone(&client),
server_info: McpServerInfo {
name: label.to_string(),