Model Context Protocol in OCaml
1(** Mcp_message - High-level RPC message definitions for Model Context Protocol *)
2
3open Mcp
4open Jsonrpc
5
6(** Resources/List - Request to list available resources *)
7module ResourcesList : sig
8 (** Request parameters *)
9 module Request : sig
10 type t = {
11 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 include Json.Jsonable.S with type t := t
26 end
27
28 (** Response result *)
29 module Response : sig
30 type t = {
31 resources: Resource.t list; (** List of available resources *)
32 next_cursor: Cursor.t option; (** Optional cursor for the next page *)
33 }
34 include Json.Jsonable.S with type t := t
35 end
36
37 (** Create a resources/list request *)
38 val create_request : ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
39
40 (** Create a resources/list response *)
41 val create_response : id:RequestId.t -> resources:Resource.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t
42end
43
44(** Resources/Read - Request to read resource contents *)
45module ResourcesRead : sig
46 (** Request parameters *)
47 module Request : sig
48 type t = {
49 uri: string; (** URI of the resource to read *)
50 }
51 include Json.Jsonable.S with type t := t
52 end
53
54 (** Resource content *)
55 module ResourceContent : sig
56 type t =
57 | TextResource of TextResourceContents.t (** Text content *)
58 | BlobResource of BlobResourceContents.t (** Binary content *)
59 include Json.Jsonable.S with type t := t
60 end
61
62 (** Response result *)
63 module Response : sig
64 type t = {
65 contents: ResourceContent.t list; (** List of resource contents *)
66 }
67 include Json.Jsonable.S with type t := t
68 end
69
70 (** Create a resources/read request *)
71 val create_request : uri:string -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
72
73 (** Create a resources/read response *)
74 val create_response : id:RequestId.t -> contents:ResourceContent.t list -> unit -> JSONRPCMessage.t
75end
76
77(** Tools/List - Request to list available tools *)
78module ToolsList : sig
79 (** Request parameters *)
80 module Request : sig
81 type t = {
82 cursor: Cursor.t option; (** Optional pagination cursor *)
83 }
84 include Json.Jsonable.S with type t := t
85 end
86
87 (** Tool definition *)
88 module Tool : sig
89 type t = {
90 name: string; (** Unique identifier for the tool *)
91 description: string option; (** Human-readable description *)
92 input_schema: Json.t; (** JSON Schema defining expected parameters *)
93 annotations: Json.t option; (** Optional properties describing tool behavior *)
94 }
95 include Json.Jsonable.S with type t := t
96 end
97
98 (** Response result *)
99 module Response : sig
100 type t = {
101 tools: Tool.t list; (** List of available tools *)
102 next_cursor: Cursor.t option; (** Optional cursor for the next page *)
103 }
104 include Json.Jsonable.S with type t := t
105 end
106
107 (** Create a tools/list request *)
108 val create_request : ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
109
110 (** Create a tools/list response *)
111 val create_response : id:RequestId.t -> tools:Tool.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t
112end
113
114(** Tools/Call - Request to invoke a tool *)
115module ToolsCall : sig
116 (** Request parameters *)
117 module Request : sig
118 type t = {
119 name: string; (** Name of the tool to call *)
120 arguments: Json.t; (** Arguments for the tool invocation *)
121 }
122 include Json.Jsonable.S with type t := t
123 end
124
125 (** Tool content *)
126 module ToolContent : sig
127 type t =
128 | Text of TextContent.t (** Text content *)
129 | Image of ImageContent.t (** Image content *)
130 | Audio of AudioContent.t (** Audio content *)
131 | Resource of EmbeddedResource.t (** Resource content *)
132 include Json.Jsonable.S with type t := t
133 end
134
135 (** Response result *)
136 module Response : sig
137 type t = {
138 content: ToolContent.t list; (** List of content items returned by the tool *)
139 is_error: bool; (** Whether the result represents an error *)
140 }
141 include Json.Jsonable.S with type t := t
142 end
143
144 (** Create a tools/call request *)
145 val create_request : name:string -> arguments:Json.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
146
147 (** Create a tools/call response *)
148 val create_response : id:RequestId.t -> content:ToolContent.t list -> is_error:bool -> unit -> JSONRPCMessage.t
149end
150
151(** Prompts/List - Request to list available prompts *)
152module PromptsList : sig
153 (** Prompt argument *)
154 module PromptArgument : sig
155 type t = {
156 name: string; (** Name of the argument *)
157 description: string option; (** Description of the argument *)
158 required: bool; (** Whether the argument is required *)
159 }
160 include Json.Jsonable.S with type t := t
161 end
162
163 (** Prompt definition *)
164 module Prompt : sig
165 type t = {
166 name: string; (** Unique identifier for the prompt *)
167 description: string option; (** Human-readable description *)
168 arguments: PromptArgument.t list; (** Arguments for customization *)
169 }
170 include Json.Jsonable.S with type t := t
171 end
172
173 (** Request parameters *)
174 module Request : sig
175 type t = {
176 cursor: Cursor.t option; (** Optional pagination cursor *)
177 }
178 include Json.Jsonable.S with type t := t
179 end
180
181 (** Response result *)
182 module Response : sig
183 type t = {
184 prompts: Prompt.t list; (** List of available prompts *)
185 next_cursor: Cursor.t option; (** Optional cursor for the next page *)
186 }
187 include Json.Jsonable.S with type t := t
188 end
189
190 (** Create a prompts/list request *)
191 val create_request : ?cursor:Cursor.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
192
193 (** Create a prompts/list response *)
194 val create_response : id:RequestId.t -> prompts:Prompt.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t
195end
196
197(** Prompts/Get - Request to get a prompt with arguments *)
198module PromptsGet : sig
199 (** Request parameters *)
200 module Request : sig
201 type t = {
202 name: string; (** Name of the prompt to get *)
203 arguments: (string * string) list; (** Arguments for the prompt *)
204 }
205 include Json.Jsonable.S with type t := t
206 end
207
208 (** Response result *)
209 module Response : sig
210 type t = {
211 description: string option; (** Description of the prompt *)
212 messages: PromptMessage.t list; (** List of messages in the prompt *)
213 }
214 include Json.Jsonable.S with type t := t
215 end
216
217 (** Create a prompts/get request *)
218 val create_request : name:string -> arguments:(string * string) list -> ?id:RequestId.t -> unit -> JSONRPCMessage.t
219
220 (** Create a prompts/get response *)
221 val create_response : id:RequestId.t -> ?description:string -> messages:PromptMessage.t list -> unit -> JSONRPCMessage.t
222end
223
224(** List Changed Notifications *)
225module ListChanged : sig
226 (** Create a resources/list_changed notification *)
227 val create_resources_notification : unit -> JSONRPCMessage.t
228
229 (** Create a tools/list_changed notification *)
230 val create_tools_notification : unit -> JSONRPCMessage.t
231
232 (** Create a prompts/list_changed notification *)
233 val create_prompts_notification : unit -> JSONRPCMessage.t
234end
235
236(** Resource Updated Notification *)
237module ResourceUpdated : sig
238 (** Notification parameters *)
239 module Notification : sig
240 type t = {
241 uri: string; (** URI of the updated resource *)
242 }
243 include Json.Jsonable.S with type t := t
244 end
245
246 (** Create a resources/updated notification *)
247 val create_notification : uri:string -> unit -> JSONRPCMessage.t
248end
249
250(** Progress Notification *)
251module Progress : sig
252 (** Notification parameters *)
253 module Notification : sig
254 type t = {
255 progress: float; (** Current progress value *)
256 total: float; (** Total progress value *)
257 progress_token: ProgressToken.t; (** Token identifying the operation *)
258 }
259 include Json.Jsonable.S with type t := t
260 end
261
262 (** Create a progress notification *)
263 val create_notification : progress:float -> total:float -> progress_token:ProgressToken.t -> unit -> JSONRPCMessage.t
264end