package mcp-kit

All checked builds pass
  1. Overview
  2. Docs
OCaml library for building MCP servers

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ocaml-mcp-v0.2.0.tar.gz
sha256=43c8319a13be91e323ae952a71ab673533fb3295886029eed9d81e5828de5ef7

doc/src/mcp-kit.jsonschema-validation/kw_conditional.ml.html

Source file kw_conditional.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(** Keywords: if, then, else (spec §6.6). *)

open Jsonschema_core

let parent_path path =
  match List.rev path with [] -> [] | _ :: rest -> List.rev rest

let compile_if : Compiler.keyword_compiler =
  {
    keyword = "if";
    compile =
      (fun ctx value ->
        let if_v = ctx.compile_sub value in
        let then_v =
          match Schema.keyword "then" (Schema.Obj ctx.schema_obj) with
          | Some s ->
              Some
                (ctx.compile_sub
                   ~schema_path:
                     (Json_pointer.append (parent_path ctx.schema_path) "then")
                   s)
          | None -> None
        in
        let else_v =
          match Schema.keyword "else" (Schema.Obj ctx.schema_obj) with
          | Some s ->
              Some
                (ctx.compile_sub
                   ~schema_path:
                     (Json_pointer.append (parent_path ctx.schema_path) "else")
                   s)
          | None -> None
        in
        Some
          (fun instance path ->
            if if_v instance path = [] then
              (* if validates → apply then *)
              match then_v with
              | Some v -> v instance path
              | None -> []
            else
              (* if fails → apply else *)
              match else_v with
              | Some v -> v instance path
              | None -> []));
  }

let compilers = [ compile_if ]