···
| CustomError _ -> "Error"
+
(* Protocol method types *)
+
(* Method type representing all MCP protocol methods *)
+
(* Initialization and lifecycle methods *)
+
| ResourcesTemplatesList
+
(* Progress notifications *)
+
(* Convert method type to string representation *)
+
let to_string = function
+
| Initialize -> "initialize"
+
| Initialized -> "notifications/initialized"
+
| ResourcesList -> "resources/list"
+
| ResourcesRead -> "resources/read"
+
| ResourcesTemplatesList -> "resources/templates/list"
+
| ResourcesSubscribe -> "resources/subscribe"
+
| ResourcesListChanged -> "notifications/resources/list_changed"
+
| ResourcesUpdated -> "notifications/resources/updated"
+
| ToolsList -> "tools/list"
+
| ToolsCall -> "tools/call"
+
| ToolsListChanged -> "notifications/tools/list_changed"
+
| PromptsList -> "prompts/list"
+
| PromptsGet -> "prompts/get"
+
| PromptsListChanged -> "notifications/prompts/list_changed"
+
| Progress -> "notifications/progress"
+
(* Convert string to method type *)
+
let of_string = function
+
| "initialize" -> Initialize
+
| "notifications/initialized" -> Initialized
+
| "resources/list" -> ResourcesList
+
| "resources/read" -> ResourcesRead
+
| "resources/templates/list" -> ResourcesTemplatesList
+
| "resources/subscribe" -> ResourcesSubscribe
+
| "notifications/resources/list_changed" -> ResourcesListChanged
+
| "notifications/resources/updated" -> ResourcesUpdated
+
| "tools/list" -> ToolsList
+
| "tools/call" -> ToolsCall
+
| "notifications/tools/list_changed" -> ToolsListChanged
+
| "prompts/list" -> PromptsList
+
| "prompts/get" -> PromptsGet
+
| "notifications/prompts/list_changed" -> PromptsListChanged
+
| "notifications/progress" -> Progress
+
| s -> failwith ("Unknown MCP method: " ^ s)
···
module JSONRPCMessage = struct
progress_token: ProgressToken.t option;
···
let yojson_of_notification (n: notification) =
("jsonrpc", `String "2.0");
+
("method", `String (Method.to_string n.method_));
let assoc = match n.params with
| Some params -> ("params", params) :: assoc
···
("jsonrpc", `String "2.0");
("id", Id.yojson_of_t r.id);
+
("method", `String (Method.to_string r.method_));
let assoc = match r.params with
···
let notification_of_yojson = function
let method_ = match List.assoc_opt "method" fields with
+
(try Method.of_string s
+
with Failure msg -> raise (Json.Of_json (msg, `String s)))
| _ -> raise (Json.Of_json ("Missing or invalid 'method' field", `Assoc fields))
let params = List.assoc_opt "params" fields in
···
| _ -> raise (Json.Of_json ("Missing or invalid 'id' field", `Assoc fields))
let method_ = match List.assoc_opt "method" fields with
+
(try Method.of_string s
+
with Failure msg -> raise (Json.Of_json (msg, `String s)))
| _ -> raise (Json.Of_json ("Missing or invalid 'method' field", `Assoc fields))
let params = List.assoc_opt "params" fields in
···
let params = yojson_of_t t in
+
JSONRPCMessage.create_request ~id ~method_:Method.Initialize ~params:(Some params) ()
···
+
JSONRPCMessage.create_notification ~method_:Method.Initialized ~params ()
···
JSONRPCMessage.t_of_yojson json
+
let create_notification ?(params=None) ~method_ () =
+
JSONRPCMessage.create_notification ~params ~method_ ()
+
let create_request ?(params=None) ?(progress_token=None) ~id ~method_ () =
+
JSONRPCMessage.create_request ~params ~progress_token ~id ~method_ ()
let create_response = JSONRPCMessage.create_response
let create_error = JSONRPCMessage.create_error