Function: mcp--list-items

mcp--list-items is a natively compiled function defined in mcp.el.

Signature

(mcp--list-items CONNECTION METHOD KEY-NAME SLOT-NAME CALLBACK ERROR-CALLBACK SYNCP)

Documentation

Helper function to list items from the MCP server.

CONNECTION is the MCP connection object. METHOD is the JSON-RPC method to call (e.g., :tools/list). KEY-NAME is the connection slot to store results (e.g., :tools). SLOT-NAME is the connection slot to store results (e.g., -tools). CALLBACK is a function to call with the result. ERROR-CALLBACK is a function to call on error. SYNCP specifies if the operation should be synchronous or asynchronous.

Source Code

;; Defined in /nix/store/5m747x13pb1ddrvbq9raj91c4q1h1kl0-emacs-packages-deps/share/emacs/site-lisp/elpa/mcp-20260615.940/mcp.el
(defun mcp--list-items (connection method key-name slot-name callback error-callback syncp)
  "Helper function to list items from the MCP server.

CONNECTION is the MCP connection object.
METHOD is the JSON-RPC method to call (e.g., :tools/list).
KEY-NAME is the connection slot to store results (e.g., :tools).
SLOT-NAME is the connection slot to store results (e.g., -tools).
CALLBACK is a function to call with the result.
ERROR-CALLBACK is a function to call on error.
SYNCP specifies if the operation should be synchronous or asynchronous."
  (let* ((success-fn (lambda (res)
                       (when-let* ((items (plist-get res key-name)))
                         (setf (slot-value connection slot-name) items)
                         (when callback
                           (funcall callback connection items)))))
         (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))))
         (args `(,connection
                 ,method ,(make-hash-table)
                 :timeout ,(mcp--timeout connection)
                 ,@(unless syncp `(:success-fn
                                   ,success-fn))
                 ,@(unless syncp `(:error-fn
                                   ,error-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)))
          (:success (funcall success-fn res)))
      (apply #'jsonrpc-async-request
             args))))