Process a single raw JSON-RPC line and write the response. Used to replay a peeked `initialize` message that was consumed before the server's main loop started.
(
&self,
line: &str,
transport: &mut impl super::transport::McpTransport,
)
| 1610 | /// Used to replay a peeked `initialize` message that was consumed before |
| 1611 | /// the server's main loop started. |
| 1612 | pub async fn handle_and_write( |
| 1613 | &self, |
| 1614 | line: &str, |
| 1615 | transport: &mut impl super::transport::McpTransport, |
| 1616 | ) -> Result<()> { |
| 1617 | let parsed: std::result::Result<super::transport::JsonRpcRequest, _> = |
| 1618 | serde_json::from_str(line); |
| 1619 | let response = match parsed { |
| 1620 | Ok(request) => self.handle_request(&request).await, |
| 1621 | Err(e) => Some(super::transport::JsonRpcResponse::error( |
| 1622 | Value::Null, |
| 1623 | super::transport::ErrorCode::ParseError, |
| 1624 | format!("failed to parse JSON-RPC request: {e}"), |
| 1625 | )), |
| 1626 | }; |
| 1627 | if let Some(resp) = response { |
| 1628 | let mut json_str = serialize_response_line(&resp); |
| 1629 | json_str.push('\n'); |
| 1630 | transport.write_line(&json_str).await?; |
| 1631 | transport.flush().await?; |
| 1632 | } |
| 1633 | Ok(()) |
| 1634 | } |
| 1635 | |
| 1636 | /// Runs the server, reading JSON-RPC requests from stdin and writing |
| 1637 | /// responses to stdout. Runs until stdin is closed or a shutdown signal |
nothing calls this directly
no test coverage detected