MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / read_first_non_empty_stdin_line

Function read_first_non_empty_stdin_line

src/serve.rs:305–332  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

303}
304
305async fn read_first_non_empty_stdin_line() -> Option<String> {
306 use tokio::io::AsyncReadExt;
307
308 let mut stdin = tokio::io::stdin();
309 let mut line = Vec::new();
310 let mut byte = [0_u8; 1];
311 // Avoid buffering past the first line; the normal stdio transport must still
312 // receive any later JSON-RPC messages from stdin.
313 loop {
314 match stdin.read(&mut byte).await {
315 Ok(0) if line.is_empty() => return None,
316 Ok(0) => {
317 let text = String::from_utf8(line).ok()?;
318 return (!text.trim().is_empty()).then_some(text);
319 }
320 Ok(_) => {
321 line.push(byte[0]);
322 if byte[0] == b'\n' {
323 let text = String::from_utf8(std::mem::take(&mut line)).ok()?;
324 if !text.trim().is_empty() {
325 return Some(text);
326 }
327 }
328 }
329 Err(_) => return None,
330 }
331 }
332}
333
334pub(crate) fn local_path_from_mcp_root_uri(uri: &str) -> Option<std::path::PathBuf> {
335 let path = if let Some(rest) = uri.strip_prefix("file://") {

Callers 1

read_initialize_rootsFunction · 0.85

Calls 3

pushMethod · 0.80
readMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected