Skip to content

Commit a3f4c13

Browse files
Integrate mcp security guards into agentgateway
1 parent 8b3487d commit a3f4c13

17 files changed

Lines changed: 4104 additions & 3139 deletions

File tree

crates/agentgateway/src/mcp/handler.rs

Lines changed: 449 additions & 33 deletions
Large diffs are not rendered by default.

crates/agentgateway/src/mcp/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub enum Error {
5959
ForwardLegacySse(String),
6060
#[error("failed to create SSE url: {0}")]
6161
CreateSseUrl(String),
62+
#[error("security guard rejected: {1} - {2}")]
63+
SecurityGuard(RequestId, String, String),
6264
}
6365

6466
impl From<Error> for ProxyError {

crates/agentgateway/src/mcp/router.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ impl App {
105105
.collect::<Result<Vec<_>, _>>()?;
106106

107107
McpBackendGroup {
108+
name: format!(
109+
"{}/{}",
110+
backend_group_name.namespace, backend_group_name.name
111+
),
108112
targets: nt,
109113
stateful: backend.stateful,
114+
security_guards: backend.security_guards.clone(),
110115
}
111116
};
117+
let guard_registry = self.state.guard_registry.clone();
112118
let sm = self.session.clone();
113119
let client = PolicyClient { inputs: pi.clone() };
114120
let authorization_policies = backend_policies
@@ -178,12 +184,14 @@ impl App {
178184
match (req.uri().path(), req.method(), authn) {
179185
("/sse", _, _) => {
180186
// Assume this is streamable HTTP otherwise
187+
let guard_registry_clone = guard_registry.clone();
181188
let sse = LegacySSEService::new(
182189
move || {
183190
Relay::new(
184191
backends.clone(),
185192
authorization_policies.clone(),
186193
client.clone(),
194+
guard_registry_clone.clone(),
187195
)
188196
.map_err(|e| Error::new(e.to_string()))
189197
},
@@ -226,6 +234,7 @@ impl App {
226234
backends.clone(),
227235
authorization_policies.clone(),
228236
client.clone(),
237+
guard_registry.clone(),
229238
)
230239
.map_err(|e| Error::new(e.to_string()))
231240
},
@@ -247,8 +256,10 @@ impl App {
247256

248257
#[derive(Debug, Clone)]
249258
pub struct McpBackendGroup {
259+
pub name: String,
250260
pub targets: Vec<Arc<McpTarget>>,
251261
pub stateful: bool,
262+
pub security_guards: Vec<crate::mcp::security::McpSecurityGuard>,
252263
}
253264

254265
#[derive(Debug)]

0 commit comments

Comments
 (0)