Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
482 changes: 449 additions & 33 deletions crates/agentgateway/src/mcp/handler.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/agentgateway/src/mcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub enum Error {
ForwardLegacySse(String),
#[error("failed to create SSE url: {0}")]
CreateSseUrl(String),
#[error("security guard rejected: {1} - {2}")]
SecurityGuard(RequestId, String, String),
}

impl From<Error> for ProxyError {
Expand Down
11 changes: 11 additions & 0 deletions crates/agentgateway/src/mcp/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ impl App {
.collect::<Result<Vec<_>, _>>()?;

McpBackendGroup {
name: format!(
"{}/{}",
backend_group_name.namespace, backend_group_name.name
),
targets: nt,
stateful: backend.stateful,
security_guards: backend.security_guards.clone(),
}
};
let guard_registry = self.state.guard_registry.clone();
let sm = self.session.clone();
let client = PolicyClient { inputs: pi.clone() };
let authorization_policies = backend_policies
Expand Down Expand Up @@ -178,12 +184,14 @@ impl App {
match (req.uri().path(), req.method(), authn) {
("/sse", _, _) => {
// Assume this is streamable HTTP otherwise
let guard_registry_clone = guard_registry.clone();
let sse = LegacySSEService::new(
move || {
Relay::new(
backends.clone(),
authorization_policies.clone(),
client.clone(),
guard_registry_clone.clone(),
)
.map_err(|e| Error::new(e.to_string()))
},
Expand Down Expand Up @@ -226,6 +234,7 @@ impl App {
backends.clone(),
authorization_policies.clone(),
client.clone(),
guard_registry.clone(),
)
.map_err(|e| Error::new(e.to_string()))
},
Expand All @@ -247,8 +256,10 @@ impl App {

#[derive(Debug, Clone)]
pub struct McpBackendGroup {
pub name: String,
pub targets: Vec<Arc<McpTarget>>,
pub stateful: bool,
pub security_guards: Vec<crate::mcp::security::McpSecurityGuard>,
}

#[derive(Debug)]
Expand Down
Loading