···
+
(* Standard error codes *)
+
module ErrorCode = struct
+
let parse_error = -32700
+
let invalid_request = -32600
+
let method_not_found = -32601
+
let invalid_params = -32602
+
let internal_error = -32603
+
let resource_not_found = -32002
+
let server_error_start = -32000
+
let server_error_end = -32099
···
| j -> raise (Json.Of_json ("Expected object for ImageContent", j))
+
module AudioContent = struct
+
annotations: Annotated.annotation option;
+
let yojson_of_t { data; mime_type; annotations } =
+
("data", `String data);
+
("mimeType", `String mime_type);
+
("type", `String "audio");
+
let assoc = match annotations with
+
| Some annotations -> ("annotations", Annotated.yojson_of_annotation annotations) :: assoc
+
let t_of_yojson = function
+
let data = match List.assoc_opt "data" fields with
+
| Some (`String s) -> s
+
| _ -> raise (Json.Of_json ("Missing or invalid 'data' field", `Assoc fields))
+
let mime_type = match List.assoc_opt "mimeType" fields with
+
| Some (`String s) -> s
+
| _ -> raise (Json.Of_json ("Missing or invalid 'mimeType' field", `Assoc fields))
+
let _ = match List.assoc_opt "type" fields with
+
| Some (`String "audio") -> ()
+
| _ -> raise (Json.Of_json ("Missing or invalid 'type' field", `Assoc fields))
+
let annotations = List.assoc_opt "annotations" fields |> Option.map Annotated.annotation_of_yojson in
+
{ data; mime_type; annotations }
+
| j -> raise (Json.Of_json ("Expected object for AudioContent", j))
module ResourceContents = struct
···
| j -> raise (Json.Of_json ("Expected object for EmbeddedResource", j))
+
description: string option;
+
let yojson_of_t { name; description; input_schema } =
+
("name", `String name);
+
("inputSchema", input_schema);
+
let assoc = match description with
+
| Some desc -> ("description", `String desc) :: assoc
+
let t_of_yojson = function
+
let name = match List.assoc_opt "name" fields with
+
| Some (`String s) -> s
+
| _ -> raise (Json.Of_json ("Missing or invalid 'name' field", `Assoc fields))
+
let description = match List.assoc_opt "description" fields with
+
| Some (`String s) -> Some s
+
let input_schema = match List.assoc_opt "inputSchema" fields with
+
| _ -> raise (Json.Of_json ("Missing 'inputSchema' field", `Assoc fields))
+
{ name; description; input_schema }
+
| j -> raise (Json.Of_json ("Expected object for Tool", j))
| Image of ImageContent.t
+
| Audio of AudioContent.t
| Resource of EmbeddedResource.t
let yojson_of_content = function
| Text t -> TextContent.yojson_of_t t
| Image i -> ImageContent.yojson_of_t i
+
| Audio a -> AudioContent.yojson_of_t a
| Resource r -> EmbeddedResource.yojson_of_t r
let content_of_yojson = function
···
(match List.assoc_opt "type" fields with
| Some (`String "text") -> Text (TextContent.t_of_yojson (`Assoc fields))
| Some (`String "image") -> Image (ImageContent.t_of_yojson (`Assoc fields))
+
| Some (`String "audio") -> Audio (AudioContent.t_of_yojson (`Assoc fields))
| Some (`String "resource") -> Resource (EmbeddedResource.t_of_yojson (`Assoc fields))
| _ -> raise (Json.Of_json ("Invalid or missing content type", `Assoc fields)))
| j -> raise (Json.Of_json ("Expected object for content", j))
+
module CallToolResult = struct
+
let yojson_of_t { content; is_error; meta } =
+
("content", `List (List.map yojson_of_content content));
+
("isError", `Bool is_error);
+
let assoc = match meta with
+
| Some meta_json -> ("_meta", meta_json) :: assoc
+
let t_of_yojson = function
+
let content = match List.assoc_opt "content" fields with
+
| Some (`List items) -> List.map content_of_yojson items
+
| _ -> raise (Json.Of_json ("Missing or invalid 'content' field", `Assoc fields))
+
let is_error = match List.assoc_opt "isError" fields with
+
| None -> false (* Default to false if not specified *)
+
| _ -> raise (Json.Of_json ("Invalid 'isError' field", `Assoc fields))
+
let meta = List.assoc_opt "_meta" fields in
+
{ content; is_error; meta }
+
| j -> raise (Json.Of_json ("Expected object for CallToolResult", j))
···
(* JSONRPC Message types *)
module JSONRPCMessage = struct