chore: rustfmt, clippy lints and code tidying
This commit is contained in:
1 parent
3716c3e698
commit
1752753fcc
19 files changed
+1273
-738
No files matched your search
@@ -1,14 +1,15 @@
|
||||
use futures_util::StreamExt;
|
||||
use reqwest::Client;
|
||||
use std::env;
|
||||
use std::time::Duration;
|
||||
use futures_util::StreamExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let target = env::var("MCP_TARGET").unwrap_or_else(|_| "https://127.0.0.1:3000".to_string());
|
||||
let token = env::var("MCP_AUTH_TOKEN").unwrap_or_else(|_| "jP76lUJ5DtFRZmcvXH8LKdCTIkp29eAf".to_string());
|
||||
let token = env::var("MCP_AUTH_TOKEN")
|
||||
.unwrap_or_else(|_| "jP76lUJ5DtFRZmcvXH8LKdCTIkp29eAf".to_string());
|
||||
|
||||
tracing::info!("Starting skeletal client to {}", target);
|
||||
|
||||
@@ -17,13 +18,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.build()?;
|
||||
|
||||
let sse_url = format!("{}/sse", target);
|
||||
|
||||
|
||||
tracing::info!("Connecting to SSE: {}", sse_url);
|
||||
|
||||
let res = client.get(&sse_url)
|
||||
.bearer_auth(&token)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let res = client.get(&sse_url).bearer_auth(&token).send().await?;
|
||||
|
||||
if !res.status().is_success() {
|
||||
tracing::error!("Failed to connect to SSE: {}", res.status());
|
||||
@@ -40,15 +38,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
while let Some(chunk) = stream.next().await {
|
||||
let bytes = chunk?;
|
||||
buffer.extend_from_slice(&bytes);
|
||||
|
||||
|
||||
while let Some(pos) = buffer.windows(2).position(|w| w == b"\n\n" || w == b"\r\n") {
|
||||
let msg_bytes = buffer.drain(..pos).collect::<Vec<_>>();
|
||||
buffer.drain(..2);
|
||||
|
||||
|
||||
let text = String::from_utf8_lossy(&msg_bytes);
|
||||
let mut is_endpoint = false;
|
||||
let mut data_content = String::new();
|
||||
|
||||
|
||||
for line in text.lines() {
|
||||
if line.starts_with("event: endpoint") {
|
||||
is_endpoint = true;
|
||||
@@ -78,7 +76,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing::info!("Sending test payload to {}", post_url);
|
||||
tracing::info!("Payload: {}", payload);
|
||||
|
||||
let post_res = client.post(&post_url)
|
||||
let post_res = client
|
||||
.post(&post_url)
|
||||
.bearer_auth(&token)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(payload.to_string())
|
||||
@@ -91,7 +90,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Wait for the SSE stream to deliver the response
|
||||
tracing::info!("Waiting 2 seconds for SSE response delivery...");
|
||||
|
||||
|
||||
let mut timeout = tokio::time::interval(Duration::from_secs(2));
|
||||
timeout.tick().await; // first tick is immediate
|
||||
|
||||
|
||||
+7
-9
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
use clap::Parser;
|
||||
use futures_util::{SinkExt, StreamExt};
|
||||
use std::sync::Arc;
|
||||
use tokio::io::AsyncBufReadExt;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
@@ -23,11 +23,11 @@ async fn read_mcp_message(stdin: &mut tokio::io::BufReader<tokio::io::Stdin>) ->
|
||||
return None;
|
||||
}
|
||||
tracing::info!("Read {} bytes from stdin: {:?}", bytes_read, line);
|
||||
|
||||
|
||||
if line.starts_with('{') {
|
||||
return Some(line.trim_end().to_string());
|
||||
}
|
||||
|
||||
|
||||
let line = line.trim_end();
|
||||
if line.is_empty() {
|
||||
break;
|
||||
@@ -51,16 +51,16 @@ fn init_logging(app_name: &str) -> Option<tracing_appender::non_blocking::Worker
|
||||
let mut base_dir = dirs::home_dir().unwrap_or_else(|| std::path::PathBuf::from("."));
|
||||
base_dir.push(".gemini/mcp_memory/logs");
|
||||
std::fs::create_dir_all(&base_dir).unwrap_or_default();
|
||||
|
||||
|
||||
let file_appender = tracing_appender::rolling::daily(base_dir, format!("{}.log", app_name));
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
|
||||
let _ = tracing_subscriber::fmt()
|
||||
.with_writer(non_blocking)
|
||||
.with_ansi(false)
|
||||
.with_max_level(tracing::Level::TRACE)
|
||||
.try_init();
|
||||
|
||||
|
||||
Some(guard)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tracing::info!("Attempting to connect to {}", ws_url);
|
||||
|
||||
use tokio_tungstenite::tungstenite::client::IntoClientRequest;
|
||||
let mut request = match ws_url.clone().into_client_request() {
|
||||
let request = match ws_url.clone().into_client_request() {
|
||||
Ok(req) => req,
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to parse target URL {}: {}", ws_url, e);
|
||||
@@ -165,5 +165,3 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user