mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
mcp: improve RawJson stringification and schema formatting
- Update `RawJson.jsonStringify` to parse and re-write JSON content, ensuring valid output. - Reformat tool input schemas in `tools.zig` using multi-line string literals for better readability.
This commit is contained in:
@@ -101,9 +101,13 @@ pub const RawJson = struct {
|
|||||||
json: []const u8,
|
json: []const u8,
|
||||||
|
|
||||||
pub fn jsonStringify(self: @This(), jw: anytype) !void {
|
pub fn jsonStringify(self: @This(), jw: anytype) !void {
|
||||||
try jw.beginWriteRaw();
|
var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
|
||||||
try jw.writer.writeAll(self.json);
|
defer arena.deinit();
|
||||||
jw.endWriteRaw();
|
|
||||||
|
const parsed = std.json.parseFromSlice(std.json.Value, arena.allocator(), self.json, .{}) catch return error.WriteFailed;
|
||||||
|
defer parsed.deinit();
|
||||||
|
|
||||||
|
try jw.write(parsed.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,32 +13,79 @@ pub const tool_list = [_]protocol.Tool{
|
|||||||
.{
|
.{
|
||||||
.name = "goto",
|
.name = "goto",
|
||||||
.description = "Navigate to a specified URL and load the page in memory so it can be reused later for info extraction.",
|
.description = "Navigate to a specified URL and load the page in memory so it can be reused later for info extraction.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\",\"description\":\"The URL to navigate to, must be a valid URL.\"}},\"required\":[\"url\"]}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "url": { "type": "string", "description": "The URL to navigate to, must be a valid URL." }
|
||||||
|
\\ },
|
||||||
|
\\ "required": ["url"]
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "search",
|
.name = "search",
|
||||||
.description = "Use a search engine to look for specific words, terms, sentences. The search page will then be loaded in memory.",
|
.description = "Use a search engine to look for specific words, terms, sentences. The search page will then be loaded in memory.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\",\"description\":\"The text to search for, must be a valid search query.\"}},\"required\":[\"text\"]}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "text": { "type": "string", "description": "The text to search for, must be a valid search query." }
|
||||||
|
\\ },
|
||||||
|
\\ "required": ["text"]
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "markdown",
|
.name = "markdown",
|
||||||
.description = "Get the page content in markdown format. If a url is provided, it navigates to that url first.",
|
.description = "Get the page content in markdown format. If a url is provided, it navigates to that url first.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\",\"description\":\"Optional URL to navigate to before fetching markdown.\"}}}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "url": { "type": "string", "description": "Optional URL to navigate to before fetching markdown." }
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "links",
|
.name = "links",
|
||||||
.description = "Extract all links in the opened page. If a url is provided, it navigates to that url first.",
|
.description = "Extract all links in the opened page. If a url is provided, it navigates to that url first.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\",\"description\":\"Optional URL to navigate to before extracting links.\"}}}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "url": { "type": "string", "description": "Optional URL to navigate to before extracting links." }
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "evaluate",
|
.name = "evaluate",
|
||||||
.description = "Evaluate JavaScript in the current page context. If a url is provided, it navigates to that url first.",
|
.description = "Evaluate JavaScript in the current page context. If a url is provided, it navigates to that url first.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"script\":{\"type\":\"string\"},\"url\":{\"type\":\"string\",\"description\":\"Optional URL to navigate to before evaluating.\"}},\"required\":[\"script\"]}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "script": { "type": "string" },
|
||||||
|
\\ "url": { "type": "string", "description": "Optional URL to navigate to before evaluating." }
|
||||||
|
\\ },
|
||||||
|
\\ "required": ["script"]
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "over",
|
.name = "over",
|
||||||
.description = "Used to indicate that the task is over and give the final answer if there is any. This is the last tool to be called in a task.",
|
.description = "Used to indicate that the task is over and give the final answer if there is any. This is the last tool to be called in a task.",
|
||||||
.inputSchema = .{ .json = "{\"type\":\"object\",\"properties\":{\"result\":{\"type\":\"string\",\"description\":\"The final result of the task.\"}},\"required\":[\"result\"]}" },
|
.inputSchema = .{ .json =
|
||||||
|
\\{
|
||||||
|
\\ "type": "object",
|
||||||
|
\\ "properties": {
|
||||||
|
\\ "result": { "type": "string", "description": "The final result of the task." }
|
||||||
|
\\ },
|
||||||
|
\\ "required": ["result"]
|
||||||
|
\\}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user