Skip to content

Commit 75c49a9

Browse files
committed
Forward backend notifications by session
Signed-off-by: lucarlig <luca.carlig@ibm.com>
1 parent 722ba7b commit 75c49a9

16 files changed

Lines changed: 2935 additions & 1260 deletions

File tree

crates/contextforge-gateway-rs-lib/src/gateway/backend_notifications.rs

Lines changed: 222 additions & 160 deletions
Large diffs are not rendered by default.

crates/contextforge-gateway-rs-lib/src/gateway/mcp_call_validator.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
use contextforge_gateway_rs_apis::user_store::{UserConfig, VirtualHost};
2+
use std::sync::Arc;
3+
24
use http::request::Parts;
3-
//use rmcp::{ErrorData, RoleServer, model::ErrorCode, service::RequestContext, transport::DownstreamSessionId};
45
use rmcp::{
5-
ErrorData, RoleServer, model::ErrorCode, service::RequestContext,
6+
ErrorData, RoleServer,
7+
model::{ErrorCode, Extensions},
8+
service::RequestContext,
69
transport::streamable_http_server::tower::DownstreamSessionId,
710
};
811
use tracing::info;
912

1013
use crate::{
1114
common::ContextForgeClaims,
15+
gateway::UserSession,
1216
layers::{session_id::SessionId, virtual_host_id::VirtualHostId},
1317
};
1418

@@ -33,6 +37,20 @@ impl SessionKey {
3337
session_id: session_id.to_owned(),
3438
}
3539
}
40+
41+
pub(crate) fn from_authorized_extensions(extensions: &Extensions) -> Option<Self> {
42+
let parts = extensions.get::<Parts>()?;
43+
let session_id = parts.extensions.get::<SessionId>()?;
44+
let user_config = parts.extensions.get::<UserConfig>()?;
45+
let virtual_host_id = parts.extensions.get::<VirtualHostId>()?;
46+
let claims = parts.extensions.get::<ContextForgeClaims>()?;
47+
user_config.virtual_hosts.get(virtual_host_id.value())?;
48+
Some(Self::new(&claims.sub, virtual_host_id.value(), session_id.value()))
49+
}
50+
51+
pub(crate) fn to_user_session(&self) -> UserSession {
52+
UserSession::new(self.subject.clone(), self.virtual_host_id.clone(), Arc::from(self.session_id.as_str()))
53+
}
3654
}
3755

3856
impl std::fmt::Display for SessionKey {
@@ -54,6 +72,7 @@ pub struct AuthorizedCallContext<'a> {
5472

5573
pub struct InitializeCallContext<'a> {
5674
pub virtual_host: &'a VirtualHost,
75+
pub virtual_host_id: &'a str,
5776
pub downstream_session_id: &'a DownstreamSessionId,
5877
pub principal: &'a str,
5978
pub session_key: SessionKey,
@@ -194,6 +213,7 @@ impl<'a> InitializeCallValidator<'a> {
194213

195214
Ok(InitializeCallContext {
196215
virtual_host,
216+
virtual_host_id: virtual_host_id.value(),
197217
downstream_session_id,
198218
principal: &claims.sub,
199219
session_key: SessionKey::new(&claims.sub, virtual_host_id.value(), downstream_session_id.value()),

0 commit comments

Comments
 (0)