Pure MCP boundary coercion — string→typed value conversion.
MCP JSON transports deliver ALL parameter values as strings. These functions systematically coerce strings to the declared types, returning Result maps ({:ok v} / {:error category ...}).
Compose with hive-dsl.result/let-ok for railway-oriented pipelines.
Zero external dependencies — pure Clojure.
ClojureScript: JVM number parsing (Long/Double) is replaced by strict js/parseInt|parseFloat guards, and JSON parsing by js/JSON.parse — so the ->int/->double/->vec semantics match across platforms.
Pure MCP boundary coercion — string→typed value conversion.
MCP JSON transports deliver ALL parameter values as strings.
These functions systematically coerce strings to the declared types,
returning Result maps ({:ok v} / {:error category ...}).
Compose with hive-dsl.result/let-ok for railway-oriented pipelines.
Zero external dependencies — pure Clojure.
ClojureScript: JVM number parsing (Long/Double) is replaced by strict
js/parseInt|parseFloat guards, and JSON parsing by js/JSON.parse — so the
->int/->double/->vec semantics match across platforms.(->boolean v)Coerce value to boolean.
"true" → {:ok true} "false" → {:ok false} true → {:ok true} nil → {:ok nil}
Coerce value to boolean.
"true" → {:ok true}
"false" → {:ok false}
true → {:ok true}
nil → {:ok nil}(->double v)Coerce value to double.
"0.9" → {:ok 0.9} 0.9 → {:ok 0.9} nil → {:ok nil}
Coerce value to double.
"0.9" → {:ok 0.9}
0.9 → {:ok 0.9}
nil → {:ok nil}(->enum v allowed-set)Coerce value to keyword and validate against allowed set.
(->enum "both" #{:outgoing :incoming :both}) → {:ok :both} (->enum "nope" #{:outgoing :incoming :both}) → {:error ...}
Coerce value to keyword and validate against allowed set.
(->enum "both" #{:outgoing :incoming :both}) → {:ok :both}
(->enum "nope" #{:outgoing :incoming :both}) → {:error ...}(->int v)Coerce value to integer.
"3" → {:ok 3} 3 → {:ok 3} nil → {:ok nil} (pass-through; use with defaults at call site) "x" → {:error :coerce/invalid-int ...}
Coerce value to integer.
"3" → {:ok 3}
3 → {:ok 3}
nil → {:ok nil} (pass-through; use with defaults at call site)
"x" → {:error :coerce/invalid-int ...}(->keyword v)Coerce value to keyword.
"both" → {:ok :both} :both → {:ok :both} nil → {:ok nil}
Coerce value to keyword.
"both" → {:ok :both}
:both → {:ok :both}
nil → {:ok nil}(->vec v)Coerce value to vector.
["a"] → {:ok ["a"]} "["a"]" → {:ok ["a"]} (JSON parse) nil → {:ok nil}
Coerce value to vector.
["a"] → {:ok ["a"]}
"[\"a\"]" → {:ok ["a"]} (JSON parse)
nil → {:ok nil}(coerce-map schema params)Declarative map coercion — coerce param map fields per schema.
schema: {field-key [type-spec ...]} params: raw param map (string values from MCP)
Only coerces fields present in both schema and params. Unknown fields pass through unchanged.
(coerce-map {:max_depth [:int] :direction [:enum #{:outgoing :incoming :both}]} {:max_depth "3" :direction "both" :scope "hive-mcp"}) => {:ok {:max_depth 3 :direction :both :scope "hive-mcp"}}
Declarative map coercion — coerce param map fields per schema.
schema: {field-key [type-spec ...]}
params: raw param map (string values from MCP)
Only coerces fields present in both schema and params.
Unknown fields pass through unchanged.
(coerce-map {:max_depth [:int]
:direction [:enum #{:outgoing :incoming :both}]}
{:max_depth "3" :direction "both" :scope "hive-mcp"})
=> {:ok {:max_depth 3 :direction :both :scope "hive-mcp"}}cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |