Skip to content

Commit b4778f9

Browse files
author
Bruce Hauman
committed
fix: prevent validation errors from triggering MCP error callbacks
Previously, the tool system conflated two distinct types of errors: 1. Processing/validation errors (expected, normal flow) 2. Tool execution failures (unexpected, exceptional) Both types were being passed to the MCP callback's error parameter, causing validation failures to be treated as infrastructure errors at the MCP protocol level. This change ensures only actual exceptions trigger MCP error callbacks by: - Always passing 'false' for the error parameter in normal flow - Maintaining exception handling for true tool failures - Preserving validation errors in the result for proper handling The commented-out original code (:error formatted) is retained for reference, with extensive inline documentation explaining the distinction between these error types and suggesting a future enhancement to introduce :exception-error for clearer separation. This aligns with error handling best practices where business logic errors (validation, processing) are distinguished from system failures (exceptions, infrastructure issues), ensuring the MCP protocol layer only receives error signals for genuine tool malfunctions.
1 parent 1db8df1 commit b4778f9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/clojure_mcp/tool_system.clj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@
9696
validated (validate-inputs tool-config keywordized-params)
9797
result (execute-tool tool-config validated)
9898
formatted (format-results tool-config result)]
99-
(callback (:result formatted) (:error formatted)))
99+
;; signaling an error to the MCP server should only
100+
;; happen on tool failure IE an exception.
101+
;; currently our internal errors conflate processing
102+
;; errors that occur as a matter of course with
103+
;; errors in the tools function we need to treat
104+
;; the (:error formatted) as errors that occur from
105+
;; the MCP sending bad data vs a new level of
106+
;; error (:exception-error formatted) [This dosn't exist yet]
107+
;; which should indicate the the tool isn't functioning correctly.
108+
109+
(callback (:result formatted) false #_(:error formatted)))
100110
(catch Exception e
101111
(log/error e)
102112
;; On error, create a sequence of error messages

0 commit comments

Comments
 (0)