Function: claude-code-ide-mcp--on-open

claude-code-ide-mcp--on-open is a natively compiled function defined in claude-code-ide-mcp.el.

Signature

(claude-code-ide-mcp--on-open SESSION WS)

Documentation

Handle new WebSocket connection WS for SESSION.

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-mcp.el
(defun claude-code-ide-mcp--on-open (session ws)
  "Handle new WebSocket connection WS for SESSION."
  (claude-code-ide-debug "=== WebSocket connection opened ===")
  (claude-code-ide-debug "WebSocket object: %S" ws)
  (claude-code-ide-debug "WebSocket state: %s" (websocket-ready-state ws))
  (claude-code-ide-debug "WebSocket URL: %s" (websocket-url ws))

  ;; Adopt the new connection, dropping any previous client (CLI
  ;; reconnect).  Pending deferred ids died with the old socket, so flush
  ;; them; active diffs stay — the user may be mid-ediff.
  (let ((old-client (claude-code-ide-mcp-session-client session)))
    (when (and old-client (not (eq old-client ws)))
      (claude-code-ide-debug "Replacing existing client connection")
      (ignore-errors (websocket-close old-client))
      (clrhash (claude-code-ide-mcp-session-deferred session))
      (setf (claude-code-ide-mcp-session-last-selection session) nil)))
  (setf (claude-code-ide-mcp-session-client session) ws)
  (claude-code-ide-debug "Claude Code connected to MCP server for %s"
                         (file-name-nondirectory
                          (directory-file-name (claude-code-ide-mcp-session-project-dir session))))

  ;; Track initial active editor if we have one in the project
  (let ((file-path (buffer-file-name))
        (project-dir (claude-code-ide-mcp-session-project-dir session)))
    (when (and file-path
               project-dir
               (string-prefix-p (expand-file-name project-dir)
                                (expand-file-name file-path)))
      (setf (claude-code-ide-mcp-session-last-buffer session) (current-buffer))
      ;; Update MCP tools server's last active buffer
      (claude-code-ide-mcp-server-update-last-active-buffer
       (claude-code-ide-mcp-session-session-id session)
       (current-buffer)))))