Function: mcp-make-text-tool
mcp-make-text-tool is a natively compiled function defined in mcp.el.
Signature
(mcp-make-text-tool NAME TOOL-NAME &optional ASYNCP)
Documentation
Create a gptel tool with the given NAME, TOOL-NAME, and ASYNCP.
NAME is the name of the server connection. TOOL-NAME is the name of the tool to be created.
Currently, only synchronous messages are supported.
This function retrieves the tool definition from the server connection, constructs a basic tool with the appropriate properties, and returns it. The tool is configured to handle input arguments, call the server, and process the response to extract and return text content.
Source Code
;; Defined in /nix/store/5m747x13pb1ddrvbq9raj91c4q1h1kl0-emacs-packages-deps/share/emacs/site-lisp/elpa/mcp-20260615.940/mcp.el
;;;###autoload
(defun mcp-make-text-tool (name tool-name &optional asyncp)
"Create a `gptel' tool with the given NAME, TOOL-NAME, and ASYNCP.
NAME is the name of the server connection.
TOOL-NAME is the name of the tool to be created.
Currently, only synchronous messages are supported.
This function retrieves the tool definition from the server connection,
constructs a basic tool with the appropriate properties, and returns it.
The tool is configured to handle input arguments, call the server, and process
the response to extract and return text content."
(when-let* ((connection (gethash name mcp-server-connections))
(tools (mcp--tools connection))
(tool (cl-find tool-name tools :test #'equal :key (lambda (tool) (plist-get tool :name)))))
(cl-destructuring-bind (&key description ((:inputSchema input-schema)) &allow-other-keys) tool
(cl-destructuring-bind (&key properties required &allow-other-keys) input-schema
(list
:function (if asyncp
(lambda (callback &rest args)
(when (< (length args) (length required))
(error "Error: args not match: %s -> %s" required args))
(if-let* ((connection (gethash name mcp-server-connections)))
(mcp-async-call-tool connection
tool-name
(mcp--generate-tool-call-args args properties)
(lambda (res)
(funcall callback
(mcp--parse-tool-call-result res)))
(lambda (code message)
(funcall callback
(format "call %s tool error with %s: %s"
tool-name
code
message))))
(error "Error: %s server not connect" name)))
(lambda (&rest args)
(when (< (length args) (length required))
(error "Error: args not match: %s -> %s" required args))
(if-let* ((connection (gethash name mcp-server-connections)))
(if-let* ((res (mcp-call-tool connection
tool-name
(mcp--generate-tool-call-args args properties))))
(mcp--parse-tool-call-result res)
(error "Error: call %s tool error" tool-name))
(error "Error: %s server not connect" name))))
:name tool-name
:async asyncp
:description description
:args
(mcp--parse-tool-args properties (or required '())))))))