Skip to content

Instantly share code, notes, and snippets.

@evacchi
Created February 19, 2025 10:02
Show Gist options
  • Save evacchi/5090808070a3fc464aec6e7484dab6d6 to your computer and use it in GitHub Desktop.
Save evacchi/5090808070a3fc464aec6e7484dab6d6 to your computer and use it in GitHub Desktop.
const std = @import("std");
const json = std.json;
pub const ContentType = enum {
text,
image,
resource,
};
pub const CallToolResult = struct {
isError: bool = false,
content: []const Content,
};
/// A content response.
/// For text content set type to ContentType.Text and set the `text` property
/// For image content set type to ContentType.Image and set the `data` and `mimeType` properties
pub const Content = struct {
type: ?ContentType = ContentType.text,
text: ?[]const u8 = null,
data: ?[]const u8 = null,
mimeType: ?[]const u8 = null,
};
const allocator = std.heap.page_allocator;
pub fn main() !void {
const stdout_file = std.io.getStdOut().writer();
const r = try getResult();
try json.stringify(r, .{}, stdout_file);
}
fn getResult() !CallToolResult {
const msg = try std.fmt.allocPrint(
allocator,
"Error {d}: {s}",
.{ 404, "Not Found" },
);
return CallToolResult{ .content = &.{.{ .text = msg }} };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment