Function: claude-code-ide-mcp--handle-tools-call
claude-code-ide-mcp--handle-tools-call is a natively compiled function
defined in claude-code-ide-mcp.el.
Signature
(claude-code-ide-mcp--handle-tools-call ID PARAMS &optional SESSION WS)
Documentation
Handle the tools/call request with ID and PARAMS.
Optional SESSION contains the MCP session context; WS is the websocket the request arrived on, used to detect a client swap during a yielding handler.
Source Code
;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-mcp.el
(defun claude-code-ide-mcp--handle-tools-call (id params &optional session ws)
"Handle the tools/call request with ID and PARAMS.
Optional SESSION contains the MCP session context; WS is the websocket
the request arrived on, used to detect a client swap during a yielding
handler."
(claude-code-ide-debug "Handling tools/call request with id: %s" id)
;; Ensure handlers are loaded
(let* ((tool-name (alist-get 'name params))
(arguments (alist-get 'arguments params))
(handler (alist-get tool-name claude-code-ide-mcp-tools nil nil #'string=)))
(claude-code-ide-debug "Tool call: %s with arguments: %S" tool-name arguments)
(if handler
(condition-case err
(progn
(claude-code-ide-debug "Found handler for tool: %s" tool-name)
(let ((result (funcall handler arguments session)))
;; Check if this is a deferred response
(if (alist-get 'deferred result)
(progn
(claude-code-ide-debug "Tool %s returned deferred, storing id %s" tool-name id)
;; Correlate strictly with the session whose websocket
;; carried the request; a guessed session could file the
;; id under a sibling instance and answer the wrong CLI.
(let* ((unique-key (alist-get 'unique-key result))
(storage-key (if unique-key
(format "%s-%s" tool-name unique-key)
tool-name)))
(cond
;; The requester was replaced while the handler ran;
;; its ids are dead — storing one would answer the
;; successor with an id it never sent
((and ws session
(not (eq ws (claude-code-ide-mcp-session-client session))))
(claude-code-ide-debug
"Discarding deferred id %s: client replaced mid-request" id))
(session
(let ((session-deferred (claude-code-ide-mcp-session-deferred session)))
(puthash storage-key id session-deferred)
(claude-code-ide-debug "Stored deferred response in session for %s"
(claude-code-ide-mcp-session-project-dir session))))
(t
(claude-code-ide-debug "Warning: No session found, cannot store deferred response"))))
;; Don't send a response yet
nil)
;; Normal response
(claude-code-ide-debug "Tool %s returned result: %S" tool-name result)
(claude-code-ide-mcp--make-response id `((content . ,result))))))
(mcp-error
(claude-code-ide-debug "Tool %s threw MCP error: %S" tool-name err)
(claude-code-ide-mcp--make-error-response
id -32603 (if (listp (cdr err))
(car (cdr err))
(cdr err))))
(error
(claude-code-ide-debug "Tool %s threw error: %S" tool-name err)
(claude-code-ide-mcp--make-error-response
id -32603 (format "Tool execution failed: %s" (error-message-string err)))))
(progn
(claude-code-ide-debug "Unknown tool requested: %s" tool-name)
(claude-code-ide-mcp--make-error-response
id -32601 (format "Unknown tool: %s" tool-name))))))