codex icon indicating copy to clipboard operation
codex copied to clipboard

Codex does not subscribe to MCP tool-list changes over Streamable HTTP with protocol 2026-07-28

Open jadchene opened this issue 2 weeks ago • 3 comments

What version of Codex CLI is running?

codex-cli 0.170.0

What subscription do you have?

ChatGPT Pro

Which model were you using?

No response

What platform is your computer?

Microsoft Windows NT 10.0.26300.0 x64

What terminal emulator and version are you using (if applicable)?

Windows Terminal PowerShell

Codex doctor report


What issue are you seeing?

With mcp_tool_list_changed = true, a running Codex thread keeps a stale tool list when connected to a Streamable HTTP server using MCP 2026-07-28. Initial discovery works. The server-side HTTP trace shows server/discover and tools/list, but no subscriptions/listen request. After a tool was added, the server's catalog contained it while the same thread's mcpServerStatus/list still omitted it across 10 checks, 350 ms apart.

Both runs used the same Codex version, server, and tool change. Counts below are for the period after the change.

mcp_2026_07_28 Tool-list notifications observed on the connection Subsequent tools/list requests New tool visible in the same thread
true 0 0 No
false 1 1 Yes

What steps can reproduce the bug?

  1. Connect Codex to a Streamable HTTP MCP server that supports tool-list change subscriptions and can add a tool while the client remains connected. Enable both flags in config.toml:

    [features]
    mcp_tool_list_changed = true
    mcp_2026_07_28 = true
    
  2. Start codex app-server, create a thread with thread/start, and save its returned ID. In this reproduction the configured MCP server was named gateway. Call mcpServerStatus/list with the following parameters, substituting that thread ID:

    {"threadId": "<thread ID from thread/start>", "serverName": "gateway"}
    

    Confirm that the initial tools are visible and database__echo is absent. Capture the MCP HTTP traffic from connection startup so the trace includes any subscription request.

  3. Add a tool on the server without reconnecting Codex. In this reproduction, database was the ID of a test echo service. Enabling it added database__echo to the gateway's published catalog. The test requires no database.

  4. Query mcpServerStatus/list again with the same threadId and serverName. Check whether the new tool appears and whether the HTTP trace contains subscriptions/listen and a subsequent tools/list.

  5. Repeat with a fresh connection and only mcp_2026_07_28 changed to false for the control run.

What is the expected behavior?

When tool-list change support is enabled and the server supports it, Codex should subscribe via subscriptions/listen with params.notifications.toolsListChanged set to true. After a notifications/tools/list_changed notification, it should request tools/list again and expose the updated catalog in the existing thread without a reconnect.

Additional information

Why the legacy control works and 2026-07-28 stays stale

Codex selects different handshake policies. The modern policy can fall back to legacy, so the negotiated protocol matters. In the failing run, discovery succeeded with 2026-07-28. Codex protocol selection

Self::Legacy => ClientLifecycleMode::Initialize,
Self::V20260728 | Self::DiscoverLocalStdio => ClientLifecycleMode::Auto {
    preferred_versions: vec![ProtocolVersion::V_2026_07_28],
    legacy_version: Some(ProtocolVersion::V_2025_06_18),
},
  • Legacy, stateful HTTP: when the server provides a session ID, rmcp opens a standalone GET/SSE stream. The gateway can send a tool-list change on that stream. Stream startup
  • 2026-07-28 HTTP: rmcp sets the session ID to None, so it skips that GET stream. Tool-list changes use an explicit subscriptions/listen request with params.notifications.toolsListChanged = true. The failing trace contains no such request. Modern HTTP branch · Subscription contract

Where the subscription is missing in Codex 0.170.0

  • In RmcpClient::connect_pending_transport, the Streamable HTTP branch wraps the transport with track_tool_list_changes. After the handshake, it configures the response cache and returns the service. I could not find a call opening a tool-list subscription on this path.

    client_service()
        .serve_with_lifecycle(
            track_tool_list_changes(
                capture_event_notifications(transport),
                Arc::clone(&self.tool_list_revision),
            ),
            lifecycle,
        )
        .boxed()
    
  • ToolListChanges::receive increments the catalog revision only when an incoming ToolListChangedNotification reaches the transport. refresh_notified_catalog uses that revision to decide when to re-list.

    let message = self.inner.receive().await?;
    if let JsonRpcMessage::Notification(notification) = &message
        && matches!(
            notification.notification,
            ServerNotification::ToolListChangedNotification(_)
        )
    {
        self.revision.fetch_add(1, Ordering::AcqRel);
    }
    
  • In the rmcp revision pinned by Codex, Peer::listen is the explicit API that sends subscriptions/listen. This matches the missing request in the HTTP trace.

    let request = ClientRequest::SubscriptionsListenRequest(SubscriptionsListenRequest::new(
        SubscriptionsListenRequestParams::new(notifications.clone()),
    ));
    let (handle, mut subscription_notifications) = self
        .send_subscription_request(request, PeerRequestOptions::no_options(), channel_capacity)
        .await?;
    

jadchene avatar Nov 20 '26 06:11 jadchene

The flag you are toggling is not the subscription knob, and your control column may be measuring the handshake instead. At HEAD cf3ff15 mcp_tool_list_changed is read only as a refresh gate: connection_manager.rs 756 into the cache context, 823 and 899 and 1055 into refresh_tool_list, and 291 returns early when refresh_tool_list is false. The transport wrapper in tool_list_changes.rs 57 to 67 only increments a revision counter when a ToolListChangedNotification arrives. Nothing on that path can make a server send one.

So in the control run, refresh_notified_catalog returned before re-listing, and the variable that changed was the lifecycle: mcp_2026_07_28 false selects ClientLifecycleMode::Initialize, protocol_mode.rs 28 to 35.

One artifact settles it. Each re-list carries a trigger tag, "list_changed" at connection_manager.rs 301 against "initial" at rmcp_client.rs 1325 and "shared_connection" at connection_pool.rs 157. Grep the control trace for the tag on that single tools/list.

media-ctrl avatar Nov 22 '26 14:11 media-ctrl

@media-ctrl Thanks for pointing out the distinction. I agree that mcp_tool_list_changed gates the refresh after a notification. I reran the test with Codex CLI 0.170.0 connected directly to a standalone server built with @modelcontextprotocol/server 2.4.0. The demo replaced sample_before with sample_after while both Codex and an independent SDK client were connected to the same HTTP endpoint.

Here is the legacy control trace with the refresh flag enabled (milliseconds from the start of that run):

175 ms  Codex → server   initialize
185 ms  Codex → server   tools/list                         (initial catalog)
599 ms  server           replaced sample_before with sample_after
599 ms  server → Codex   notifications/tools/list_changed
962 ms  Codex → server   tools/list                         (same thread, after the change)
Codex protocol Refresh flag Notifications observed on the Codex connection after the change Subsequent tools/list requests Tool visible in the same thread
2025-06-18 on 1 1 sample_after
2025-06-18 off 1 0 sample_before
2026-07-28 on 0 0 sample_before

The modern run gives a separate check on the server. The SDK client sent subscriptions/listen with params.notifications.toolsListChanged = true, received the notification, re-listed, and successfully called sample_after. Codex sent server/discover and the initial tools/list, but no subscriptions/listen from startup through ten subsequent mcpServerStatus/list checks on the same thread.

On the suggested trigger tag: at cf3ff15, the metric emission attaches codex_apps_refresh_trigger only for Codex Apps MCP servers. This ordinary MCP server uses the empty-label branch. The timestamps above distinguish the two requests directly on the wire.

jadchene avatar Nov 23 '26 00:11 jadchene

Confirmed on the server side too, with the same asymmetry.

Our MCP server declares tools.listChanged = true and pushes notifications/tools/list_changed on the open stream when the catalog changes. It negotiates up to 2025-11-25. It does not implement subscriptions/listen, so on the 2026-07-28 revision we land in the same position as Codex: the client sends server/discover, the server has no subscription to key the refresh off, and no follow-up tools/list arrives even though the notification logic is still there for the older revision.

That points to two independent fixes rather than one: Codex emitting subscriptions/listen with params.notifications.toolsListChanged = true during initialization, and servers implementing the method so the newer revision is not strictly worse than the legacy one. A server that only speaks the notification path looks healthy on the wire until the client uses the subscribe path, which matches your table.

Happy to share the wire trace shape we use for this if it helps the regression test.

media-ctrl avatar Nov 23 '26 00:11 media-ctrl