Skip to content

mcp: copy all extensions over#1518

Merged
howardjohn merged 2 commits intoagentgateway:mainfrom
howardjohn:mcp/cpy-all-ext
Apr 15, 2026
Merged

mcp: copy all extensions over#1518
howardjohn merged 2 commits intoagentgateway:mainfrom
howardjohn:mcp/cpy-all-ext

Conversation

@howardjohn
Copy link
Copy Markdown
Collaborator

This lets us access any fields from the initial request in MCP context,
such as extauthz metadata, etc

@howardjohn howardjohn requested a review from a team as a code owner April 10, 2026 15:52
Copilot AI review requested due to automatic review settings April 10, 2026 15:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates MCP upstream request handling to propagate all http::Extensions from the incoming HTTP request into downstream MCP upstream requests, enabling access to additional request-scoped metadata (e.g., authz metadata) in MCP context.

Changes:

  • Replace per-extension propagation (Claims, BufferLimit) with cloning and forwarding the full http::Extensions map.
  • Extend outgoing MCP upstream requests with the captured extensions in IncomingRequestContext::apply.
  • Add TransformationMetadata to DebugExtensions output for improved observability.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/agentgateway/src/mcp/upstream/mod.rs Capture and forward all request extensions via IncomingRequestContext rather than copying a small subset.
crates/agentgateway/src/http/mod.rs Include TransformationMetadata in extension debug output for logging/troubleshooting.
Comments suppressed due to low confidence (1)

crates/agentgateway/src/mcp/upstream/mod.rs:26

  • The imports crate::http::jwt::Claims, crate::http::transformation_cel::TransformationMetadata, and crate::transport::BufferLimit appear unused in this module (they’re not referenced after switching to cloning parts.extensions). Please remove them to avoid unused-import warnings (which can fail CI if warnings are denied).
use crate::http::jwt::Claims;
use crate::http::transformation_cel::TransformationMetadata;
use crate::mcp::FailureMode;
use crate::mcp::mergestream::Messages;
use crate::mcp::router::{McpBackendGroup, McpTarget};
use crate::mcp::streamablehttp::StreamableHttpPostResponse;
use crate::mcp::{mergestream, upstream};
use crate::proxy::ProxyError;
use crate::proxy::httpproxy::PolicyClient;
use crate::transport::BufferLimit;
use crate::types::agent::McpTargetSpec;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 35 to 43
fn cpy_ext<T: Clone + Send + Sync + 'static>(
inp: &::http::request::Parts,
ext: &mut ::http::Extensions,
) {
if let Some(v) = inp.extensions.get::<T>() {
ext.insert(v.clone());
}
}

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpy_ext is currently unused. Please remove it, or wire it up if the intent is to selectively propagate only specific extension types (especially if you end up not cloning the entire Extensions map).

Suggested change
fn cpy_ext<T: Clone + Send + Sync + 'static>(
inp: &::http::request::Parts,
ext: &mut ::http::Extensions,
) {
if let Some(v) = inp.extensions.get::<T>() {
ext.insert(v.clone());
}
}

Copilot uses AI. Check for mistakes.
Comment on lines 29 to +33
#[derive(Debug, Clone)]
pub struct IncomingRequestContext {
headers: http::HeaderMap,
claims: Option<Claims>,
buffer_limit: Option<BufferLimit>,
ext: ::http::Extensions,
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IncomingRequestContext is cloned in a few hot paths (e.g., stdio and SSE transports clone ctx per message). With ext: http::Extensions added, each ctx.clone() now clones the full extensions map, which may include relatively large metadata maps. Consider mitigating the cost (e.g., storing only the specific extensions MCP needs, or storing extensions behind an Arc and only cloning selected heavy values) if this becomes a throughput/latency issue.

Copilot uses AI. Check for mistakes.
This lets us access any fields from the initial request in MCP context,
such as extauthz metadata, etc

Signed-off-by: John Howard <john.howard@solo.io>
Signed-off-by: John Howard <john.howard@solo.io>
@howardjohn howardjohn merged commit 76970c0 into agentgateway:main Apr 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants