Function: mcp--initialize-message
mcp--initialize-message is a natively compiled function defined in
mcp.el.
Signature
(mcp--initialize-message CONNECTION CHECK-SSE CALLBACK &optional ERROR-CALLBACK SYNCP)
Documentation
Helper function to send an initialize request to the CONNECTION.
CONNECTION is the MCP connection object. CHECK-SSE is an optional boolean flag indicating whether to verify is SSE mcp server before sending. CALLBACK is a function to call upon successful initialization. ERROR-CALLBACK is an optional function to call if an error occurs. SYNCP specifies if the operation should be synchronous or asynchronous.
See mcp-async-initialize-message and mcp-sync-initialize-message.
Source Code
;; Defined in /nix/store/5m747x13pb1ddrvbq9raj91c4q1h1kl0-emacs-packages-deps/share/emacs/site-lisp/elpa/mcp-20260615.940/mcp.el
(defun mcp--initialize-message (connection check-sse callback &optional error-callback syncp)
"Helper function to send an `initialize' request to the CONNECTION.
CONNECTION is the MCP connection object.
CHECK-SSE is an optional boolean flag indicating whether to verify is SSE
mcp server before sending.
CALLBACK is a function to call upon successful initialization.
ERROR-CALLBACK is an optional function to call if an error occurs.
SYNCP specifies if the operation should be synchronous or asynchronous.
See `mcp-async-initialize-message' and `mcp-sync-initialize-message'."
(let* ((success-fn (lambda (res)
(cl-destructuring-bind (&key protocolVersion serverInfo capabilities &allow-other-keys) res
(funcall callback protocolVersion serverInfo capabilities))))
(error-fn (jsonrpc-lambda (&key code message _data)
(if error-callback
(funcall error-callback code message)
(message "Sadly, %s mpc server reports %s: %s"
(jsonrpc-name connection) code message))))
(timeout-fn (lambda ()
(unless (and check-sse
(mcp-http-process-connection-p connection)
(mcp--sse connection))
(if error-callback
(funcall error-callback 124 "timeout")
(message "Sadly, mcp server (%s) timed out"
(jsonrpc-name connection))))))
(args `(,connection
:initialize
(:protocolVersion ,(car mcp--support-versions)
:capabilities (:roots (:listChanged t))
:clientInfo (:name "mcp-emacs" :version "0.1.0"))
,@(unless syncp `(:success-fn
,success-fn))
,@(unless syncp `(:error-fn
,error-fn))
:timeout ,mcp-server-start-time
,@(unless syncp `(:timeout-fn
,timeout-fn)))))
(if syncp
(condition-case-unless-debug res
(apply #'jsonrpc-request
args)
(jsonrpc-error
(pcase res
(`(jsonrpc-error ,_ (jsonrpc-error-code . ,code) (jsonrpc-error-message . ,message) ,_)
(funcall error-fn (list :code code :message message))
nil)
(`(jsonrpc-error ,_ (jsonrpc-error-message . "Timed out"))
(funcall timeout-fn)
nil)))
(:success
(cl-destructuring-bind (&key protocolVersion serverInfo capabilities &allow-other-keys) res
(funcall callback protocolVersion serverInfo capabilities))))
(apply #'jsonrpc-async-request
args))))