Model Context Protocol in OCaml
1(** Mcp_message - High-level RPC message definitions for Model Context Protocol 2*) 3 4open Mcp 5open Jsonrpc 6 7(** Resources/List - Request to list available resources *) 8module ResourcesList : sig 9 (** Request parameters *) 10 module Request : sig 11 type t = { cursor : Cursor.t option (** Optional pagination cursor *) } 12 13 include Json.Jsonable.S with type t := t 14 end 15 16 (** Resource definition *) 17 module Resource : sig 18 type t = { 19 uri : string; (** Unique identifier for the resource *) 20 name : string; (** Human-readable name *) 21 description : string option; (** Optional description *) 22 mime_type : string option; (** Optional MIME type *) 23 size : int option; (** Optional size in bytes *) 24 } 25 26 include Json.Jsonable.S with type t := t 27 end 28 29 (** Response result *) 30 module Response : sig 31 type t = { 32 resources : Resource.t list; (** List of available resources *) 33 next_cursor : Cursor.t option; (** Optional cursor for the next page *) 34 } 35 36 include Json.Jsonable.S with type t := t 37 end 38 39 val create_request : 40 ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t 41 (** Create a resources/list request *) 42 43 val create_response : 44 id:RequestId.t -> 45 resources:Resource.t list -> 46 ?next_cursor:Cursor.t -> 47 unit -> 48 JSONRPCMessage.t 49 (** Create a resources/list response *) 50end 51 52(** Resources/Templates/List - Request to list available resource templates *) 53module ListResourceTemplatesRequest : sig 54 type t = { cursor : Cursor.t option (** Optional pagination cursor *) } 55 56 include Json.Jsonable.S with type t := t 57end 58 59(** Resources/Templates/List - Response with resource templates *) 60module ListResourceTemplatesResult : sig 61 (** Resource Template definition *) 62 module ResourceTemplate : sig 63 type t = { 64 uri_template : string; (** URI template for the resource *) 65 name : string; (** Human-readable name *) 66 description : string option; (** Optional description *) 67 mime_type : string option; (** Optional MIME type *) 68 } 69 70 include Json.Jsonable.S with type t := t 71 end 72 73 type t = { 74 resource_templates : ResourceTemplate.t list; 75 (** List of available resource templates *) 76 next_cursor : Cursor.t option; (** Optional cursor for the next page *) 77 } 78 79 include Json.Jsonable.S with type t := t 80 81 val create_request : 82 ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t 83 (** Create a resources/templates/list request *) 84 85 val create_response : 86 id:RequestId.t -> 87 resource_templates:ResourceTemplate.t list -> 88 ?next_cursor:Cursor.t -> 89 unit -> 90 JSONRPCMessage.t 91 (** Create a resources/templates/list response *) 92end 93 94(** Resources/Read - Request to read resource contents *) 95module ResourcesRead : sig 96 (** Request parameters *) 97 module Request : sig 98 type t = { uri : string (** URI of the resource to read *) } 99 100 include Json.Jsonable.S with type t := t 101 end 102 103 (** Resource content *) 104 module ResourceContent : sig 105 type t = 106 | TextResource of TextResourceContents.t (** Text content *) 107 | BlobResource of BlobResourceContents.t (** Binary content *) 108 109 include Json.Jsonable.S with type t := t 110 end 111 112 (** Response result *) 113 module Response : sig 114 type t = { 115 contents : ResourceContent.t list; (** List of resource contents *) 116 } 117 118 include Json.Jsonable.S with type t := t 119 end 120 121 val create_request : uri:string -> ?id:RequestId.t -> unit -> JSONRPCMessage.t 122 (** Create a resources/read request *) 123 124 val create_response : 125 id:RequestId.t -> 126 contents:ResourceContent.t list -> 127 unit -> 128 JSONRPCMessage.t 129 (** Create a resources/read response *) 130end 131 132(** Tools/List - Request to list available tools *) 133module ToolsList : sig 134 (** Request parameters *) 135 module Request : sig 136 type t = { cursor : Cursor.t option (** Optional pagination cursor *) } 137 138 include Json.Jsonable.S with type t := t 139 end 140 141 (** Tool definition *) 142 module Tool : sig 143 type t = { 144 name : string; (** Unique identifier for the tool *) 145 description : string option; (** Human-readable description *) 146 input_schema : Json.t; (** JSON Schema defining expected parameters *) 147 annotations : Json.t option; 148 (** Optional properties describing tool behavior *) 149 } 150 151 include Json.Jsonable.S with type t := t 152 end 153 154 (** Response result *) 155 module Response : sig 156 type t = { 157 tools : Tool.t list; (** List of available tools *) 158 next_cursor : Cursor.t option; (** Optional cursor for the next page *) 159 } 160 161 include Json.Jsonable.S with type t := t 162 end 163 164 val create_request : 165 ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t 166 (** Create a tools/list request *) 167 168 val create_response : 169 id:RequestId.t -> 170 tools:Tool.t list -> 171 ?next_cursor:Cursor.t -> 172 unit -> 173 JSONRPCMessage.t 174 (** Create a tools/list response *) 175end 176 177(** Tools/Call - Request to invoke a tool *) 178module ToolsCall : sig 179 (** Request parameters *) 180 module Request : sig 181 type t = { 182 name : string; (** Name of the tool to call *) 183 arguments : Json.t; (** Arguments for the tool invocation *) 184 } 185 186 include Json.Jsonable.S with type t := t 187 end 188 189 (** Tool content *) 190 module ToolContent : sig 191 type t = 192 | Text of TextContent.t (** Text content *) 193 | Image of ImageContent.t (** Image content *) 194 | Audio of AudioContent.t (** Audio content *) 195 | Resource of EmbeddedResource.t (** Resource content *) 196 197 include Json.Jsonable.S with type t := t 198 end 199 200 (** Response result *) 201 module Response : sig 202 type t = { 203 content : ToolContent.t list; 204 (** List of content items returned by the tool *) 205 is_error : bool; (** Whether the result represents an error *) 206 } 207 208 include Json.Jsonable.S with type t := t 209 end 210 211 val create_request : 212 name:string -> 213 arguments:Json.t -> 214 ?id:RequestId.t -> 215 unit -> 216 JSONRPCMessage.t 217 (** Create a tools/call request *) 218 219 val create_response : 220 id:RequestId.t -> 221 content:ToolContent.t list -> 222 is_error:bool -> 223 unit -> 224 JSONRPCMessage.t 225 (** Create a tools/call response *) 226end 227 228(** Prompts/List - Request to list available prompts *) 229module PromptsList : sig 230 (** Prompt argument *) 231 module PromptArgument : sig 232 type t = { 233 name : string; (** Name of the argument *) 234 description : string option; (** Description of the argument *) 235 required : bool; (** Whether the argument is required *) 236 } 237 238 include Json.Jsonable.S with type t := t 239 end 240 241 (** Prompt definition *) 242 module Prompt : sig 243 type t = { 244 name : string; (** Unique identifier for the prompt *) 245 description : string option; (** Human-readable description *) 246 arguments : PromptArgument.t list; (** Arguments for customization *) 247 } 248 249 include Json.Jsonable.S with type t := t 250 end 251 252 (** Request parameters *) 253 module Request : sig 254 type t = { cursor : Cursor.t option (** Optional pagination cursor *) } 255 256 include Json.Jsonable.S with type t := t 257 end 258 259 (** Response result *) 260 module Response : sig 261 type t = { 262 prompts : Prompt.t list; (** List of available prompts *) 263 next_cursor : Cursor.t option; (** Optional cursor for the next page *) 264 } 265 266 include Json.Jsonable.S with type t := t 267 end 268 269 val create_request : 270 ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t 271 (** Create a prompts/list request *) 272 273 val create_response : 274 id:RequestId.t -> 275 prompts:Prompt.t list -> 276 ?next_cursor:Cursor.t -> 277 unit -> 278 JSONRPCMessage.t 279 (** Create a prompts/list response *) 280end 281 282(** Prompts/Get - Request to get a prompt with arguments *) 283module PromptsGet : sig 284 (** Request parameters *) 285 module Request : sig 286 type t = { 287 name : string; (** Name of the prompt to get *) 288 arguments : (string * string) list; (** Arguments for the prompt *) 289 } 290 291 include Json.Jsonable.S with type t := t 292 end 293 294 (** Response result *) 295 module Response : sig 296 type t = { 297 description : string option; (** Description of the prompt *) 298 messages : PromptMessage.t list; (** List of messages in the prompt *) 299 } 300 301 include Json.Jsonable.S with type t := t 302 end 303 304 val create_request : 305 name:string -> 306 arguments:(string * string) list -> 307 ?id:RequestId.t -> 308 unit -> 309 JSONRPCMessage.t 310 (** Create a prompts/get request *) 311 312 val create_response : 313 id:RequestId.t -> 314 ?description:string -> 315 messages:PromptMessage.t list -> 316 unit -> 317 JSONRPCMessage.t 318 (** Create a prompts/get response *) 319end 320 321(** List Changed Notifications *) 322module ListChanged : sig 323 val create_resources_notification : unit -> JSONRPCMessage.t 324 (** Create a resources/list_changed notification *) 325 326 val create_tools_notification : unit -> JSONRPCMessage.t 327 (** Create a tools/list_changed notification *) 328 329 val create_prompts_notification : unit -> JSONRPCMessage.t 330 (** Create a prompts/list_changed notification *) 331end 332 333(** Resource Updated Notification *) 334module ResourceUpdated : sig 335 (** Notification parameters *) 336 module Notification : sig 337 type t = { uri : string (** URI of the updated resource *) } 338 339 include Json.Jsonable.S with type t := t 340 end 341 342 val create_notification : uri:string -> unit -> JSONRPCMessage.t 343 (** Create a resources/updated notification *) 344end 345 346(** Progress Notification *) 347module Progress : sig 348 (** Notification parameters *) 349 module Notification : sig 350 type t = { 351 progress : float; (** Current progress value *) 352 total : float; (** Total progress value *) 353 progress_token : ProgressToken.t; (** Token identifying the operation *) 354 } 355 356 include Json.Jsonable.S with type t := t 357 end 358 359 val create_notification : 360 progress:float -> 361 total:float -> 362 progress_token:ProgressToken.t -> 363 unit -> 364 JSONRPCMessage.t 365 (** Create a progress notification *) 366end