systemprompt_api/services/proxy/engine/
handlers.rs1use axum::body::Body;
8use axum::extract::{Path, Request, State};
9use axum::http::StatusCode;
10use axum::response::{IntoResponse, Response};
11use systemprompt_runtime::AppContext;
12
13use super::{ProxyEngine, ProxyKind, ProxyTarget};
14
15impl ProxyEngine {
16 pub async fn handle_mcp_request_with_path(
17 &self,
18 path_params: Path<(String, String)>,
19 State(ctx): State<AppContext>,
20 request: Request<Body>,
21 ) -> Response<Body> {
22 let Path((service_name, path)) = path_params;
23 let target = ProxyTarget {
24 service_name: &service_name,
25 path: &path,
26 kind: ProxyKind::Mcp,
27 };
28 match self.proxy_request(target, request, ctx).await {
29 Ok(response) => response,
30 Err(e) => e.into_response(),
31 }
32 }
33
34 pub async fn handle_agent_request(
35 &self,
36 path_params: Path<(String,)>,
37 State(ctx): State<AppContext>,
38 request: Request<Body>,
39 ) -> Result<Response<Body>, StatusCode> {
40 let Path((service_name,)) = path_params;
41 let target = ProxyTarget {
42 service_name: &service_name,
43 path: "",
44 kind: ProxyKind::Agent,
45 };
46 self.proxy_request(target, request, ctx)
47 .await
48 .map_err(|e| e.to_status_code())
49 }
50
51 pub async fn handle_agent_request_with_path(
52 &self,
53 path_params: Path<(String, String)>,
54 State(ctx): State<AppContext>,
55 request: Request<Body>,
56 ) -> Result<Response<Body>, StatusCode> {
57 let Path((service_name, path)) = path_params;
58 let target = ProxyTarget {
59 service_name: &service_name,
60 path: &path,
61 kind: ProxyKind::Agent,
62 };
63 self.proxy_request(target, request, ctx)
64 .await
65 .map_err(|e| e.to_status_code())
66 }
67}