feat(mcp): enhance MCP server registration with error handling and improve transport process management

refactor: update various tools for better error handling and path resolution
fix: improve markdown rendering and input display in TUI
This commit is contained in:
asepharyana
2026-07-20 13:12:04 +07:00
parent 89ee213454
commit 148ba4e07b
17 changed files with 242 additions and 82 deletions
+29 -2
View File
@@ -218,14 +218,27 @@ impl SseParser {
///
/// Return: all `StreamEvent`s completed by this chunk.
pub fn feed(&mut self, chunk: &str) -> Vec<StreamEvent> {
self.buffer.push_str(chunk);
// Normalize \r\n and bare \r to \n for consistent line ending handling
let chunk = chunk.replace("\r\n", "\n").replace('\r', "\n");
// Prevent unbounded buffer growth for long lines without \n
const MAX_BUFFER_SIZE: usize = 1_048_576; // 1 MB
if self.buffer.len() + chunk.len() > MAX_BUFFER_SIZE {
tracing::warn!("SSE buffer exceeded maximum size, resetting");
self.buffer.clear();
self.event_type = None;
self.data_lines.clear();
}
self.buffer.push_str(&chunk);
let mut events = Vec::new();
while let Some(line_end) = self.buffer.find('\n') {
let line = self.buffer[..line_end].trim_end_matches('\r').to_string();
self.buffer = self.buffer[line_end + 1..].to_string();
if line.is_empty() {
events.extend(self.flush_event());
} else if let Some(ty) = line.strip_prefix("event: ") {
} else if let Some(ty) = line.strip_prefix("event:") {
// Handle both "event:foo" and "event: foo"
self.event_type = Some(ty.trim().to_string());
} else if let Some(data) = line.strip_prefix("data:") {
let data = data.trim_start().to_string();
@@ -372,6 +385,20 @@ impl SseParser {
}
d_events
}
"content_block_delta" => {
let mut d_events = Vec::new();
if let Some(delta) = value.get("delta") {
if let Some(content) = delta.get("text").and_then(|c| c.as_str()) {
d_events.push(StreamEvent::Token(content.to_string()));
}
if let Some(reasoning) =
delta.get("reasoning_content").and_then(|r| r.as_str())
{
d_events.push(StreamEvent::Reasoning(reasoning.to_string()));
}
}
d_events
}
_ => vec![],
};