mcp: improve event loop and response handling

- Use an allocating writer in `sendResponse` to handle large payloads.
- Update the main loop to tick the HTTP client and cap poll timeouts.
- Update protocol version and minify tool input schemas.
This commit is contained in:
Adrià Arrufat
2026-03-02 11:12:00 +09:00
parent d4747b5386
commit a91afab038
3 changed files with 36 additions and 74 deletions

View File

@@ -12,7 +12,7 @@ app: *App,
http_client: *HttpClient,
notification: *lp.Notification,
browser: lp.Browser,
browser: *lp.Browser,
session: *lp.Session,
page: *lp.Page,
@@ -53,12 +53,12 @@ pub fn deinit(self: *Self) void {
self.allocator.destroy(self);
}
pub fn sendResponse(_: *Self, response: anytype) !void {
var buffer: [8192]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&buffer);
try std.json.Stringify.value(response, .{ .emit_null_optional_fields = false }, &stdout.interface);
try stdout.interface.writeByte('\n');
try stdout.interface.flush();
pub fn sendResponse(self: *Self, response: anytype) !void {
var aw: std.Io.Writer.Allocating = .init(self.allocator);
defer aw.deinit();
try std.json.Stringify.value(response, .{ .emit_null_optional_fields = false }, &aw.writer);
try aw.writer.writeByte('\n');
try std.fs.File.stdout().writeAll(aw.written());
}
pub fn sendResult(self: *Self, id: std.json.Value, result: anytype) !void {