Skip to content

Commit 2a18d9b

Browse files
BuddhiLWclaude
andcommitted
fix: Prevent JSON serialization errors and accept keyword keys in tool properties
Changes: - server.clj: Add loggable-spec that strips :handler functions before logging to prevent JSON serialization errors when validation fails - specs.clj: Accept both string and keyword keys in tool inputSchema.properties 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Pedro Branquinho <pedrogbranquinho@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 25213e7 commit 2a18d9b

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/io/modelcontext/clojure_sdk/server.clj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,17 @@
309309
;;; Server Spec
310310

311311
(defn validate-spec!
312+
"Validates the server-spec and throws if invalid.
313+
Strips handler functions before logging to avoid JSON serialization errors."
312314
[server-spec]
313315
(when-not (specs/valid-server-spec? server-spec)
314-
(let [msg "Invalid server-spec definition"]
315-
(log/debug :msg msg :spec server-spec)
316+
(let [msg "Invalid server-spec definition"
317+
;; Strip handlers before logging to avoid JSON serialization errors
318+
loggable-spec (-> server-spec
319+
(update :tools (fn [tools] (mapv #(dissoc % :handler) tools)))
320+
(update :prompts (fn [prompts] (mapv #(dissoc % :handler) prompts)))
321+
(update :resources (fn [resources] (mapv #(dissoc % :handler) resources))))]
322+
(log/debug :msg msg :spec loggable-spec)
316323
(throw (ex-info msg (specs/explain-server-spec server-spec)))))
317324
server-spec)
318325

src/io/modelcontext/clojure_sdk/specs.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@
529529
;; Definition for a tool the client can call.
530530
(s/def :tool/name string?)
531531
(s/def :tool/description string?)
532-
(s/def :tool/properties (s/map-of string? any?))
532+
(s/def :tool/properties (s/map-of (s/or :str string? :kw keyword?) any?))
533533
(s/def :tool/required (s/coll-of string?))
534534
(s/def :schema/type #{"object"})
535535
;; A JSON Schema object defining the expected parameters for the tool.

0 commit comments

Comments
 (0)