Merge branch 'main' of ssh://git.qubit.ltd:10022/lyman/Fundamental_Analysis
This commit is contained in:
commit
b2351de882
@ -6,7 +6,7 @@ use tracing::{info, warn};
|
||||
#[derive(Deserialize)]
|
||||
pub struct TestConnectionRequest {
|
||||
// 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
|
||||
// in the MCP connection itself, depending on auth mechanism.
|
||||
pub api_key: Option<String>,
|
||||
@ -23,20 +23,15 @@ pub struct TestConnectionResponse {
|
||||
pub async fn test_connection(
|
||||
Json(payload): Json<TestConnectionRequest>,
|
||||
) -> 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() {
|
||||
return (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(TestConnectionResponse {
|
||||
success: false,
|
||||
message: "API URL (MCP Endpoint) cannot be empty.".to_string(),
|
||||
}),
|
||||
).into_response();
|
||||
}
|
||||
info!("Testing connection to MCP endpoint: {}", base_url);
|
||||
|
||||
// 要求传入 base MCP URL(不包含查询参数)与 api_key,然后按官方文档拼接 ?apikey=
|
||||
if payload.api_url.contains('?') {
|
||||
if base_url.contains('?') {
|
||||
return (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(TestConnectionResponse {
|
||||
@ -45,6 +40,7 @@ pub async fn test_connection(
|
||||
}),
|
||||
).into_response();
|
||||
}
|
||||
|
||||
let Some(key) = &payload.api_key else {
|
||||
return (
|
||||
StatusCode::BAD_REQUEST,
|
||||
@ -54,7 +50,8 @@ pub async fn test_connection(
|
||||
}),
|
||||
).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);
|
||||
let mcp_client = match AvClient::connect(&final_url).await {
|
||||
Ok(client) => client,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user