feat: implement mcp server request handling
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -1,4 +1,59 @@
|
|||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|
||||||
pub use server::KeepMcpServer;
|
use axum::{
|
||||||
|
extract::State,
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use log::error;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use crate::modes::server::common::AppState;
|
||||||
|
use crate::modes::server::common::ApiResponse;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct McpRequest {
|
||||||
|
pub method: String,
|
||||||
|
pub params: Option<Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn handle_mcp_request(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(request): Json<McpRequest>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let mcp_server = server::KeepMcpServer::new(state);
|
||||||
|
|
||||||
|
match mcp_server.handle_request(&request.method, request.params).await {
|
||||||
|
Ok(result) => {
|
||||||
|
match serde_json::from_str(&result) {
|
||||||
|
Ok(parsed_result) => {
|
||||||
|
let response = ApiResponse {
|
||||||
|
success: true,
|
||||||
|
data: Some(parsed_result),
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
(StatusCode::OK, Json(response))
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
let response = ApiResponse {
|
||||||
|
success: true,
|
||||||
|
data: Some(serde_json::Value::String(result)),
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
(StatusCode::OK, Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let response = ApiResponse {
|
||||||
|
success: false,
|
||||||
|
data: None,
|
||||||
|
error: Some(e.to_string()),
|
||||||
|
};
|
||||||
|
(StatusCode::BAD_REQUEST, Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user