Merge branch 'main' of ssh://git.qubit.ltd:10022/lyman/Fundamental_Analysis

This commit is contained in:
Lv, Qi 2025-12-01 02:05:13 +08:00
commit b2351de882

View File

@ -6,7 +6,7 @@ use tracing::{info, warn};
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TestConnectionRequest { pub struct TestConnectionRequest {
// This is the MCP endpoint URL // This is the MCP endpoint URL
pub api_url: String, pub api_url: Option<String>,
// The API key is passed for validation but might not be used directly // The API key is passed for validation but might not be used directly
// in the MCP connection itself, depending on auth mechanism. // in the MCP connection itself, depending on auth mechanism.
pub api_key: Option<String>, pub api_key: Option<String>,
@ -23,20 +23,15 @@ pub struct TestConnectionResponse {
pub async fn test_connection( pub async fn test_connection(
Json(payload): Json<TestConnectionRequest>, Json(payload): Json<TestConnectionRequest>,
) -> impl IntoResponse { ) -> impl IntoResponse {
info!("Testing connection to MCP endpoint: {}", payload.api_url); // Default MCP URL if not provided
let base_url = payload.api_url
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "https://mcp.alphavantage.co/mcp".to_string());
if payload.api_url.is_empty() { info!("Testing connection to MCP endpoint: {}", base_url);
return (
StatusCode::BAD_REQUEST,
Json(TestConnectionResponse {
success: false,
message: "API URL (MCP Endpoint) cannot be empty.".to_string(),
}),
).into_response();
}
// 要求传入 base MCP URL不包含查询参数与 api_key然后按官方文档拼接 ?apikey= // 要求传入 base MCP URL不包含查询参数与 api_key然后按官方文档拼接 ?apikey=
if payload.api_url.contains('?') { if base_url.contains('?') {
return ( return (
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
Json(TestConnectionResponse { Json(TestConnectionResponse {
@ -45,6 +40,7 @@ pub async fn test_connection(
}), }),
).into_response(); ).into_response();
} }
let Some(key) = &payload.api_key else { let Some(key) = &payload.api_key else {
return ( return (
StatusCode::BAD_REQUEST, StatusCode::BAD_REQUEST,
@ -54,7 +50,8 @@ pub async fn test_connection(
}), }),
).into_response(); ).into_response();
}; };
let final_url = format!("{}?apikey={}", payload.api_url, key);
let final_url = format!("{}?apikey={}", base_url, key);
info!("Testing MCP with final endpoint: {}", final_url); info!("Testing MCP with final endpoint: {}", final_url);
let mcp_client = match AvClient::connect(&final_url).await { let mcp_client = match AvClient::connect(&final_url).await {
Ok(client) => client, Ok(client) => client,