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
|
||||
|
||||
|
||||
Reference in new issue
Block a user