mirror of
https://github.com/openai/codex.git
synced 2026-11-23 07:17:11 +00:00
Upgrade rmcp to 3.0.0 (#36001)
## What changed - Update the Rust MCP SDK from `3.0.0-beta.3` to `3.0.0` and adapt to its renamed metadata and server discovery types. - Accept discovery responses without server identity metadata, using the configured server name as a fallback, and rely on the SDK's native support for namespaced server identity metadata. - Preserve typed OAuth HTTP errors so transport failures, cross-origin redirects, and transient HTTP responses are reported instead of being treated as anonymous access. ## Testing - Cover modern discovery with namespaced or missing server identity over HTTP, SSE, and stdio. - Cover OAuth discovery error propagation for transport failures, redirects, and transient status codes. GitOrigin-RevId: 12c1e45136cca89ce4fb15986c2b5df14608682a
This commit is contained in:
1 parent
df326d31cd
commit
a05bcda3db
22 files changed
+274
-155
No files matched your search
@@ -21,6 +21,20 @@ use crate::auth_status::OAuthDiscoveryTimeout;
|
||||
const MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES: usize = 1024 * 1024;
|
||||
static NEXT_OAUTH_REQUEST_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum OAuthHttpClientAdapterError {
|
||||
#[error("unsupported OAuth HTTP redirect policy")]
|
||||
UnsupportedRedirectPolicy,
|
||||
#[error("OAuth HTTP response body exceeds {maximum_bytes} bytes")]
|
||||
ResponseBodyTooLarge { maximum_bytes: usize },
|
||||
}
|
||||
|
||||
fn oauth_http_client_error(
|
||||
error: impl std::error::Error + Send + Sync + 'static,
|
||||
) -> OAuthHttpClientError {
|
||||
Box::new(error)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct OAuthHttpClientAdapter {
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
@@ -59,8 +73,8 @@ impl OAuthHttpClientAdapter {
|
||||
OAuthHttpRedirectPolicy::Follow => HttpRedirectPolicy::Follow,
|
||||
OAuthHttpRedirectPolicy::Stop => HttpRedirectPolicy::Stop,
|
||||
_ => {
|
||||
return Err(OAuthHttpClientError::new(
|
||||
"unsupported OAuth HTTP redirect policy",
|
||||
return Err(oauth_http_client_error(
|
||||
OAuthHttpClientAdapterError::UnsupportedRedirectPolicy,
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -76,10 +90,7 @@ impl OAuthHttpClientAdapter {
|
||||
.map(|(name, value)| {
|
||||
Ok(HttpHeader {
|
||||
name: name.as_str().to_string(),
|
||||
value: value
|
||||
.to_str()
|
||||
.map_err(|error| OAuthHttpClientError::new(error.to_string()))?
|
||||
.to_string(),
|
||||
value: value.to_str().map_err(oauth_http_client_error)?.to_string(),
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, OAuthHttpClientError>>()?;
|
||||
@@ -108,17 +119,15 @@ impl OAuthHttpClientAdapter {
|
||||
stream_response: true,
|
||||
})
|
||||
.await
|
||||
.map_err(|error| OAuthHttpClientError::new(error.to_string()))?;
|
||||
.map_err(oauth_http_client_error)?;
|
||||
let mut body = Vec::new();
|
||||
while let Some(chunk) = body_stream
|
||||
.recv()
|
||||
.await
|
||||
.map_err(|error| OAuthHttpClientError::new(error.to_string()))?
|
||||
{
|
||||
while let Some(chunk) = body_stream.recv().await.map_err(oauth_http_client_error)? {
|
||||
if chunk.len() > MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES - body.len() {
|
||||
return Err(OAuthHttpClientError::new(format!(
|
||||
"OAuth HTTP response body exceeds {MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES} bytes"
|
||||
)));
|
||||
return Err(oauth_http_client_error(
|
||||
OAuthHttpClientAdapterError::ResponseBodyTooLarge {
|
||||
maximum_bytes: MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES,
|
||||
},
|
||||
));
|
||||
}
|
||||
body.extend_from_slice(&chunk);
|
||||
}
|
||||
@@ -126,9 +135,7 @@ impl OAuthHttpClientAdapter {
|
||||
for header in response.headers {
|
||||
builder = builder.header(header.name, header.value);
|
||||
}
|
||||
builder
|
||||
.body(body)
|
||||
.map_err(|error| OAuthHttpClientError::new(error.to_string()))
|
||||
builder.body(body).map_err(oauth_http_client_error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user