Skip to main content

handle_line

Function handle_line 

Source
pub fn handle_line<R, E>(line: &str, rewrite: &R, exec: &E) -> Option<Value>
where R: Fn(&str) -> Option<String>, E: Fn(&str, &str) -> Execution,
Expand description

Handle one line of input, returning the response to write — or None when the server must stay silent.

Silence is the correct answer more often than it looks: blank lines, unparsable JSON, and notifications (which carry no id) all arrive on a healthy connection. notifications/initialized in particular is sent by every MCP client right after the handshake, and answering it would corrupt the stream.

rewrite maps a command to its rtk-optimized form, and exec runs the resulting command in a directory. Both are injected so the whole dispatch can be tested without spawning anything.