Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(torii): add SSE support for mcp #3075

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
98 changes: 65 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/torii/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ async-trait = "0.1.83"
tokio-tungstenite = "0.20.0"
hyper-tungstenite = "0.11.1"
futures-util.workspace = true
tokio-stream = "0.1.17"
uuid = "1.15.1"
13 changes: 6 additions & 7 deletions crates/torii/server/src/handlers/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

pub(crate) const LOG_TARGET: &str = "torii::server::handlers::graphql";

#[derive(Debug)]
pub struct GraphQLHandler {
client_ip: IpAddr,
graphql_addr: Option<SocketAddr>,
pub(crate) graphql_addr: Option<SocketAddr>,
}

impl GraphQLHandler {
pub fn new(client_ip: IpAddr, graphql_addr: Option<SocketAddr>) -> Self {
Self { client_ip, graphql_addr }
pub fn new(graphql_addr: Option<SocketAddr>) -> Self {
Self { graphql_addr }

Check warning on line 18 in crates/torii/server/src/handlers/graphql.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/graphql.rs#L17-L18

Added lines #L17 - L18 were not covered by tests
}
}

Expand All @@ -25,11 +25,10 @@
req.uri().path().starts_with("/graphql")
}

async fn handle(&self, req: Request<Body>) -> Response<Body> {
async fn handle(&self, req: Request<Body>, client_addr: IpAddr) -> Response<Body> {

Check warning on line 28 in crates/torii/server/src/handlers/graphql.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/graphql.rs#L28

Added line #L28 was not covered by tests
if let Some(addr) = self.graphql_addr {
let graphql_addr = format!("http://{}", addr);
match crate::proxy::GRAPHQL_PROXY_CLIENT.call(self.client_ip, &graphql_addr, req).await
{
match crate::proxy::GRAPHQL_PROXY_CLIENT.call(client_addr, &graphql_addr, req).await {

Check warning on line 31 in crates/torii/server/src/handlers/graphql.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/graphql.rs#L31

Added line #L31 was not covered by tests
Ok(response) => response,
Err(_error) => {
error!(target: LOG_TARGET, "GraphQL proxy error: {:?}", _error);
Expand Down
Loading
Loading