+330
bin/audio_example.ml
+330
bin/audio_example.ml
···+let value = int_of_float (amplitude *. max_amplitude *. sin (2.0 *. Float.pi *. frequency *. t)) in+let b2 = if i * 3 + 1 < String.length bytes then Char.code (String.get bytes (i * 3 + 1)) else 0 in+let b3 = if i * 3 + 2 < String.length bytes then Char.code (String.get bytes (i * 3 + 2)) else 0 in
+48
-15
bin/capitalize_sdk.ml
+48
-15
bin/capitalize_sdk.ml
············
+193
bin/completion_example.ml
+193
bin/completion_example.ml
···+("rust", ["memory safety"; "performance"; "static typing"; "ownership"; "zero-cost abstractions"]);+("javascript", ["dynamic typing"; "interpreted"; "prototypes"; "single-threaded"; "event-driven"]);+content = make_text_content (Printf.sprintf "Tell me about the %s programming language" language)+content = make_text_content (Printf.sprintf "%s is a programming language with the following features: %s" language features)
+33
-12
bin/dune
+33
-12
bin/dune
···
+468
bin/image_generator_example.ml
+468
bin/image_generator_example.ml
···+let b2 = if i * 3 + 1 < String.length bytes then Char.code (String.get bytes (i * 3 + 1)) else 0 in+let b3 = if i * 3 + 2 < String.length bytes then Char.code (String.get bytes (i * 3 + 2)) else 0 in+let result = Buffer.create (8 + Buffer.length ihdr_chunk + Buffer.length idat_chunk + Buffer.length iend_chunk) in+content = make_text_content (Printf.sprintf "Please describe what you see in this %dx%d pixel art."
-728
bin/markdown_book_sdk.ml
-728
bin/markdown_book_sdk.ml
···-OCaml is a general-purpose, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features.-OCaml was created in 1996 by Xavier Leroy, Jรฉrรดme Vouillon, Damien Doligez, and Didier Rรฉmy at INRIA in France. It evolved from the Caml language, which itself was an implementation of ML.-OCaml offers a unique combination of features that make it particularly well-suited for certain domains:-- **Symbolic Computing**: Excellent for manipulating complex data structures and symbolic expressions-- **Systems Programming**: Can be used for low-level systems programming with high safety guarantees-In the following chapters, we'll explore the language features in depth and learn how to leverage OCaml's strengths for building robust, maintainable software.-In OCaml, variables are immutable by default. Once a value is bound to a name, that binding cannot change.-This introduction to basic syntax sets the foundation for understanding OCaml's more advanced features, which we'll explore in the next chapters.-Variants (also called algebraic data types) represent values that can be one of several cases:-These data structures form the backbone of OCaml programming and allow for expressing complex data relationships in a type-safe way.-OCaml's module system is one of its most powerful features. It allows for organizing code into reusable components with clear interfaces.-module MakeSet (Element : sig type t val compare : t -> t -> int end) : COLLECTION with type 'a t = Element.t list = struct-The module system enables OCaml programmers to build highly modular, reusable code with clear boundaries between components.-OCaml offers several advanced features that set it apart from other languages. This chapter explores some of the more powerful language constructs.-These advanced features make OCaml a uniquely powerful language for expressing complex programs with strong guarantees about correctness.
+502
bin/multimodal_example.ml
+502
bin/multimodal_example.ml
···+let b2 = if i * 3 + 1 < String.length bytes then Char.code (String.get bytes (i * 3 + 1)) else 0 in+let b3 = if i * 3 + 2 < String.length bytes then Char.code (String.get bytes (i * 3 + 2)) else 0 in+let value = int_of_float (amplitude *. max_amplitude *. sin (2.0 *. Float.pi *. frequency *. t)) in+content = make_text_content "I've received your multimodal message with text, image, and audio."+content = make_text_resource_content (Printf.sprintf "resource://%s" resource_id) resource_content ~mime_type:"text/plain" ()+let server = configure_server server ~with_tools:true ~with_resources:false ~with_prompts:true () in
-371
bin/multimodal_sdk.ml
-371
bin/multimodal_sdk.ml
···-Tool.create_tool_result [Mcp.make_text_content (Printf.sprintf "Error: %s" msg)] ~is_error:true-Tool.create_tool_result [Mcp.make_text_content (Printf.sprintf "Error: %s" msg)] ~is_error:true-Tool.create_tool_result [Mcp.make_text_content (Printf.sprintf "Error: %s" msg)] ~is_error:true
-166
bin/ocaml_eval_sdk.ml
-166
bin/ocaml_eval_sdk.ml
···-Tool.create_tool_result [Mcp.make_text_content (Printf.sprintf "Error: %s" msg)] ~is_error:true
+186
bin/resource_template_example.ml
+186
bin/resource_template_example.ml
···+Text TextContent.{ text = Printf.sprintf "Resource reference for document %s:" doc_id; annotations = None };+content = make_text_content (Printf.sprintf "Please summarize the following document (ID: %s):" doc_id)
+365
bin/server.ml
+365
bin/server.ml
···+log_debug (Printf.sprintf "Client info: %s v%s" req.client_info.name req.client_info.version);+log_debug (Printf.sprintf "Protocol version mismatch: client=%s server=%s - will use server version"+Some (create_error ~id:req.id ~code:(-32601) ~message:("Method not found: " ^ req.method_) ()))+log_error (Printf.sprintf "Exception during message processing: %s" (Printexc.to_string exc));
+5
bin/server.mli
+5
bin/server.mli
···
-21
dune-project
-21
dune-project
···
+3
-13
lib/dune
+3
-13
lib/dune
···
+601
-316
lib/mcp.ml
+601
-316
lib/mcp.ml
··················let annotations = List.assoc_opt "annotations" fields |> Option.map Annotated.annotation_of_yojson in······let annotations = List.assoc_opt "annotations" fields |> Option.map Annotated.annotation_of_yojson in······let annotations = List.assoc_opt "annotations" fields |> Option.map Annotated.annotation_of_yojson in············let annotations = List.assoc_opt "annotations" fields |> Option.map Annotated.annotation_of_yojson in·······································
+219
-887
lib/mcp.mli
+219
-887
lib/mcp.mli
···-- Follows a client-server model where clients (often LLM-integrated applications) communicate with MCP servers-| Text of TextContent.t (** Text content for natural language messages. This is the most common content type for user-assistant interactions. *)-| Image of ImageContent.t (** Image content for visual data. Used for sharing visual context in multimodal conversations. *)-| Audio of AudioContent.t (** Audio content for audio data. Used for sharing audio context in multimodal conversations. *)-| Resource of EmbeddedResource.t (** Resource content for referencing server-side resources. Used for incorporating managed server content with stable URIs. *)-val create_request : ?params:Json.t option -> ?progress_token:ProgressToken.t option -> id:RequestId.t -> meth:Method.t -> unit -> t+val create_request : ?params:Json.t option -> ?progress_token:ProgressToken.t option -> id:RequestId.t -> method_:string -> unit -> tval create_error : id:RequestId.t -> code:int -> message:string -> ?data:Json.t option -> unit -> tval create : capabilities:Json.t -> client_info:Implementation.t -> protocol_version:string -> tval create : capabilities:Json.t -> server_info:Implementation.t -> protocol_version:string -> ?instructions:string -> ?meta:Json.t -> unit -> t-val create_request : ?params:Json.t option -> ?progress_token:ProgressToken.t option -> id:RequestId.t -> meth:Method.t -> unit -> JSONRPCMessage.t-val create_error : id:RequestId.t -> code:int -> message:string -> ?data:Json.t option -> unit -> JSONRPCMessage.t+val create_request : ?params:Json.t option -> ?progress_token:ProgressToken.t option -> id:RequestId.t -> method_:string -> unit -> JSONRPCMessage.t+val create_error : id:RequestId.t -> code:int -> message:string -> ?data:Json.t option -> unit -> JSONRPCMessage.t+val create_completion_request : id:RequestId.t -> argument:Completion.Argument.t -> ref:Completion.Request.reference -> JSONRPCMessage.t+val create_completion_response : id:RequestId.t -> values:string list -> ?has_more:bool option -> ?total:int option -> ?meta:Json.t option -> unit -> JSONRPCMessage.t
-834
lib/mcp_rpc.ml
-834
lib/mcp_rpc.ml
···
-298
lib/mcp_rpc.mli
-298
lib/mcp_rpc.mli
···-val create_response : id:RequestId.t -> resources:Resource.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> resource_templates:ResourceTemplate.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> contents:ResourceContent.t list -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> tools:Tool.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t-val create_request : name:string -> arguments:Json.t -> ?id:RequestId.t -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> content:ToolContent.t list -> is_error:bool -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> prompts:Prompt.t list -> ?next_cursor:Cursor.t -> unit -> JSONRPCMessage.t-val create_request : name:string -> arguments:(string * string) list -> ?id:RequestId.t -> unit -> JSONRPCMessage.t-val create_response : id:RequestId.t -> ?description:string -> messages:PromptMessage.t list -> unit -> JSONRPCMessage.t-val create_notification : progress:float -> total:float -> progress_token:ProgressToken.t -> unit -> JSONRPCMessage.t
+131
-275
lib/mcp_sdk.ml
+131
-275
lib/mcp_sdk.ml
···············-Log.warningf "Resource '%s' contains template variables. Consider using add_resource_template instead." uri;············-(* Convert a list of ResourceTemplate.t to the format needed for resources/templates/list response *)···-let default_capabilities ?(with_tools=true) ?(with_resources=false) ?(with_resource_templates=false) ?(with_prompts=false) () =+let default_capabilities ?(with_tools=true) ?(with_resources=false) ?(with_prompts=false) () =············-let configure_server server ?with_tools ?with_resources ?with_resource_templates ?with_prompts () =···-let capabilities = default_capabilities ~with_tools ~with_resources ~with_resource_templates ~with_prompts () in
+62
-98
lib/mcp_sdk.mli
+62
-98
lib/mcp_sdk.mli
······-val create : ?request_id:RequestId.t -> ?progress_token:ProgressToken.t -> ?lifespan_context:(string * Json.t) list -> unit -> t···val create : name:string -> ?description:string -> input_schema:Json.t -> handler:handler -> unit -> t···-val create : uri:string -> name:string -> ?description:string -> ?mime_type:string -> handler:handler -> unit -> t-val create : uri_template:string -> name:string -> ?description:string -> ?mime_type:string -> handler:handler -> unit -> t+val create : uri_template:string -> ?description:string -> ?mime_type:string -> handler:handler -> unit -> t-(** Convert a list of ResourceTemplate.t to the format needed for resources/templates/list response *)-val to_rpc_resource_templates_list : t list -> Mcp_rpc.ListResourceTemplatesResult.ResourceTemplate.t list···val create : name:string -> ?description:string -> ?arguments:argument list -> handler:handler -> unit -> tval create_argument : name:string -> ?description:string -> ?required:bool -> unit -> argumentval create_server : name:string -> ?version:string -> ?protocol_version:string -> unit -> server-val default_capabilities : ?with_tools:bool -> ?with_resources:bool -> ?with_resource_templates:bool -> ?with_prompts:bool -> unit -> Json.t+val default_capabilities : ?with_tools:bool -> ?with_resources:bool -> ?with_prompts:bool -> unit -> Json.tval add_tool : server -> name:string -> ?description:string -> ?schema_properties:(string * string * string) list -> ?schema_required:string list -> (Json.t -> Json.t) -> Tool.t-val add_resource : server -> uri:string -> name:string -> ?description:string -> ?mime_type:string -> (string list -> string) -> Resource.t+val add_resource : server -> uri_template:string -> ?description:string -> ?mime_type:string -> (string list -> string) -> Resource.t-val add_resource_template : server -> uri_template:string -> name:string -> ?description:string -> ?mime_type:string -> (string list -> string) -> ResourceTemplate.tval add_prompt : server -> name:string -> ?description:string -> ?arguments:(string * string option * bool) list -> ((string * string) list -> Prompt.message list) -> Prompt.t-val configure_server : server -> ?with_tools:bool -> ?with_resources:bool -> ?with_resource_templates:bool -> ?with_prompts:bool -> unit -> server+val configure_server : server -> ?with_tools:bool -> ?with_resources:bool -> ?with_prompts:bool -> unit -> server
+507
-463
lib/mcp_server.ml
+507
-463
lib/mcp_server.ml
···-let response = Mcp_rpc.ResourcesList.create_response ~id:req.id ~resources:resources_list () in-let templates_list = ResourceTemplate.to_rpc_resource_templates_list (resource_templates server) in-let response = Mcp_rpc.ListResourceTemplatesResult.create_response ~id:req.id ~resource_templates:templates_list () in-Some (create_jsonrpc_error req.id ErrorCode.InvalidParams "Missing params for resources/read request" ())-let response = Mcp_rpc.ResourcesRead.create_response ~id:req.id ~contents:[resource_content] () in-Some (create_jsonrpc_error req.id ErrorCode.InternalError ("Error reading resource: " ^ err) ()))-let response = Mcp_rpc.ResourcesRead.create_response ~id:req.id ~contents:[resource_content] () in-Some (create_jsonrpc_error req.id ErrorCode.InternalError ("Error reading resource template: " ^ err) ()))-Some (create_jsonrpc_error req.id ErrorCode.MethodNotFound ("Method not found: " ^ (Method.to_string req.meth)) ()))+Some (create_error ~id:req.id ~code:ErrorCode.invalid_params ~message:"Invalid params for tools/call" ())+Some (create_error ~id:req.id ~code:ErrorCode.method_not_found ~message:"Resources not supported" ())+Some (create_error ~id:req.id ~code:ErrorCode.method_not_found ~message:"Prompts not supported" ())+Some (create_error ~id:req.id ~code:ErrorCode.invalid_params ~message:(Printf.sprintf "Prompt not found: %s" name) ())+Some (create_error ~id:req.id ~code:ErrorCode.invalid_params ~message:"Invalid params format" ())+Some (create_error ~id:req.id ~code:ErrorCode.method_not_found ~message:"Prompts not supported" ())+Some (create_error ~id:req.id ~code:ErrorCode.method_not_found ~message:("Method not found: " ^ req.method_) ())+Log.error (Printf.sprintf "Exception during message processing: %s" (Printexc.to_string exc));+Log.debug (Printf.sprintf "Raw input: %s" (String.sub line 0 (min 100 (String.length line))));+Log.error (Printf.sprintf "Input was: %s" (String.sub line 0 (min 100 (String.length line))));+let error_resp = create_error ~id ~code:ErrorCode.internal_error ~message:(Printexc.to_string exc) () in
+54
lib/mcp_server.mli
+54
lib/mcp_server.mli
···
-32
mcp.opam
-32
mcp.opam
···
+178
spec/00-arch.md
+178
spec/00-arch.md
···
+4
spec/README.md
+4
spec/README.md
+239
spec/lifecycle.md
+239
spec/lifecycle.md
···+| -------- | -------------- | -------------------------------------------------------------------------- |+| Client | `sampling` | Support for LLM [sampling]({{< ref "../client/sampling" >}}) requests |+| Server | `logging` | Emits structured [log messages]({{< ref "../server/utilities/logging" >}}) |
+265
spec/prompts.md
+265
spec/prompts.md
···
+357
spec/resources.md
+357
spec/resources.md
···+[XDG MIME type](https://specifications.freedesktop.org/shared-mime-info-spec/0.14/ar01s02.html#id-1.3.14),
spec/slash-command.png
spec/slash-command.png
This is a binary file and will not be displayed.
+299
spec/tools.md
+299
spec/tools.md
···
+278
spec/transports.md
+278
spec/transports.md
···+[SSE standard](https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation).+[`Last-Event-ID`](https://html.spec.whatwg.org/multipage/server-sent-events.html#the-last-event-id-header)