mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add MCP 2026-07-28 discovery support (#35724)
## What changed - Add an opt-in `mcp_2026_07_28` protocol mode while preserving the legacy lifecycle by default. - Negotiate the new protocol over streamable HTTP with `server/discover`, including bounded responses, redirect protection, and fallback only when a response establishes that the endpoint is legacy-only. - Require stdio servers to opt in with `CODEX_MCP_PROTOCOL_VERSION=2026-07-28`, and add a bounded local stdio transport for the modern lifecycle. - Consume paginated tool, resource, and resource-template catalogs in modern mode, reject repeated cursors, and retain discovered server identity. - Reconnect reusable MCP clients when their selected protocol mode changes. ## Testing - Cover HTTP JSON and SSE discovery, legacy fallback and rejection cases, redirects, retries, response limits, and pagination. - Cover local and executor stdio discovery, protocol markers, message limits, and legacy compatibility. GitOrigin-RevId: f6a78816e127d2a482292d63b91c8384f1595903
This commit is contained in:
1 parent
85c6da1c79
commit
be2e4afcd7
28 files changed
+2891
-105
No files matched your search
@@ -187,6 +187,7 @@ impl McpConnectionSet {
|
||||
let codex_home = config.codex_home.clone();
|
||||
let prefix_mcp_tool_names = config.prefix_mcp_tool_names;
|
||||
let non_prefixed_mcp_tool_servers = config.non_prefixed_mcp_tool_servers.clone();
|
||||
let protocol_mode = config.protocol_mode;
|
||||
let client_elicitation_capability = config.client_elicitation_capability.clone();
|
||||
let tool_plugin_provenance = crate::mcp::tool_plugin_provenance(&config);
|
||||
let auth = auth.as_ref();
|
||||
@@ -292,6 +293,26 @@ impl McpConnectionSet {
|
||||
client_elicitation_capability.clone(),
|
||||
supports_openai_form_elicitation,
|
||||
);
|
||||
let expected_protocol_mode = match &configured_config.transport {
|
||||
McpServerTransportConfig::StreamableHttp { .. } => Some(protocol_mode),
|
||||
McpServerTransportConfig::Stdio { .. }
|
||||
if protocol_mode == crate::McpProtocolMode::Legacy =>
|
||||
{
|
||||
Some(crate::McpProtocolMode::Legacy)
|
||||
}
|
||||
McpServerTransportConfig::Stdio { env, .. } => match env
|
||||
.as_ref()
|
||||
.and_then(|variables| variables.get("CODEX_MCP_PROTOCOL_VERSION"))
|
||||
{
|
||||
None => Some(crate::McpProtocolMode::Legacy),
|
||||
Some(version)
|
||||
if version == rmcp::model::ProtocolVersion::V_2026_07_28.as_str() =>
|
||||
{
|
||||
Some(protocol_mode)
|
||||
}
|
||||
Some(_) => None,
|
||||
},
|
||||
};
|
||||
if let Some(previous_view) =
|
||||
reusable_previous.and_then(|previous| previous.servers.get(&server_name))
|
||||
{
|
||||
@@ -299,7 +320,10 @@ impl McpConnectionSet {
|
||||
if connection
|
||||
.reusable_client(&connection_identity)
|
||||
.await
|
||||
.is_some()
|
||||
.is_some_and(|client| {
|
||||
expected_protocol_mode
|
||||
.is_some_and(|expected| client.client.protocol_mode() == expected)
|
||||
})
|
||||
{
|
||||
servers.insert(
|
||||
server_name.clone(),
|
||||
@@ -346,6 +370,7 @@ impl McpConnectionSet {
|
||||
runtime_auth_provider,
|
||||
client_elicitation_capability.clone(),
|
||||
supports_openai_form_elicitation,
|
||||
protocol_mode,
|
||||
);
|
||||
servers.insert(
|
||||
server_name.clone(),
|
||||
|
||||
Reference in new issue
Block a user