OCaml client library for Claude Code
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-claude: enable MDX on lib/tool.mli

Run mdx on lib/tool.mli so the two {[ ... ]} odoc blocks now
type-check.

The Basic Usage block was constructing the tool's input schema by
hand as raw `[`O ...]` JSON arrays. Replaced with the typed
`Claude.Tool.schema_object` / `schema_string` / `text_result`
helpers exposed by this same module -- the same shape, but the
example now demonstrates the helpers a user should actually call.

Dropped the "Tool Response Format" placeholder block (raw JSON
illustration) and inlined the explanation as prose. The
schema_object block under val schema_object now wraps in
`let schema = ...` so the binding is consumable.

+26 -31
+7 -1
lib/dune
··· 4 4 (libraries eio eio_main fmt logs nox-json)) 5 5 6 6 (mdx 7 - (files mcp_server.mli client.mli claude.mli hooks.mli handler.mli) 7 + (files 8 + mcp_server.mli 9 + client.mli 10 + claude.mli 11 + hooks.mli 12 + handler.mli 13 + tool.mli) 8 14 (libraries claude nox-json logs fmt eio eio.core eio.unix eio_main))
+19 -30
lib/tool.mli
··· 10 10 11 11 {2 Basic Usage} 12 12 13 + Use {!schema_object} / {!schema_string} and {!text_result} so the 14 + schema and response shape stay typed instead of constructing the 15 + JSON values by hand: 16 + 13 17 {[ 14 18 let greet = 15 - Tool.v ~name:"greet" ~description:"Greet a user by name" 19 + Claude.Tool.v ~name:"greet" ~description:"Greet a user by name" 16 20 ~input_schema: 17 - (`O 18 - [ 19 - ("type", `String "object"); 20 - ("properties", `O [ ("name", `O [ ("type", `String "string") ]) ]); 21 - ("required", `A [ `String "name" ]); 22 - ]) 21 + (Claude.Tool.schema_object 22 + [ ("name", Claude.Tool.schema_string) ] 23 + ~required:[ "name" ]) 23 24 ~handler:(fun args -> 24 - match Tool_input.string args "name" with 25 + match Claude.Tool_input.string args "name" with 25 26 | Some name -> 26 - Ok 27 - (`A 28 - [ 29 - `O 30 - [ 31 - ("type", `String "text"); 32 - ("text", `String (Printf.sprintf "Hello, %s!" name)); 33 - ]; 34 - ]) 27 + Ok (Claude.Tool.text_result ("Hello, " ^ name ^ "!")) 35 28 | None -> Error "Missing 'name' parameter") 36 29 ]} 37 30 38 - {2 Tool Response Format} 39 - 40 - Tool handlers return MCP-compatible content: 41 - - Success: [Ok content] where content is JSON array of content blocks 42 - - Error: [Error message] for error responses 43 - 44 - Content blocks are typically: 45 - {[ 46 - `A [ `O [ ("type", `String "text"); ("text", `String "result") ] ] 47 - ]} *) 31 + Tool handlers return MCP-compatible content via {!text_result} 32 + on success, or [Error message] for error responses. *) 48 33 49 34 type t 50 35 (** Abstract type for tool definitions. *) ··· 103 88 val schema_object : (string * Json.t) list -> required:string list -> Json.t 104 89 (** [schema_object props ~required] creates an object schema. 105 90 {[ 106 - schema_object 107 - [ ("name", schema_string); ("age", schema_int) ] 108 - ~required:[ "name" ] 91 + let schema = 92 + Claude.Tool.schema_object 93 + [ 94 + ("name", Claude.Tool.schema_string); 95 + ("age", Claude.Tool.schema_int); 96 + ] 97 + ~required:[ "name" ] 109 98 ]} *) 110 99 111 100 val schema_string : Json.t