#![forbid(unsafe_code)]
#![deny(missing_docs)]
use anyhow::Context;
use std::io::{self, BufRead, Write};
fn main() -> anyhow::Result<()> {
let stdin = io::stdin();
let stdout = io::stdout();
let mut out = stdout.lock();
for line in stdin.lock().lines() {
let line = line.context("read stdin")?;
if line.trim().is_empty() {
continue;
}
let request: rlg_mcp::Request =
match serde_json::from_str(&line) {
Ok(req) => req,
Err(e) => {
let resp = rlg_mcp::Response::err(
None,
-32_700,
format!("parse error: {e}"),
);
writeln!(out, "{}", serde_json::to_string(&resp)?)?;
out.flush()?;
continue;
}
};
if let Some(response) = rlg_mcp::dispatch(&request) {
writeln!(out, "{}", serde_json::to_string(&response)?)?;
out.flush()?;
}
}
Ok(())
}