Skip to content

MCP Tools (Server)

An MCP tool represents an action that a model may be allowed to invoke. In the LLM context, MCP tools may be described as actions that the LLM may know and choose to prescribe to achieve a certain goal.

Tools are the MCP server workhorse

Tools are commonly the biggest use case for MCP servers. The tools encapsulate the interface to business systems and implementation that MCP clients can access.

From an implementation perspective, tools are remote functions invoked over the MCP protocol. MCP clients specify the tool name and arguments to call the tool.

As you may have seen in Quickstart a tool is composed of the tool metadata and a handler function. Let us see another tool example:

(ns hello-mcp-clj.tool
  (:require
   [plumcp.core.api.entity-gen :as eg]
   [plumcp.core.util :as u]))


(defn get-forecast
  [part-no weeks]
  ;; Call internal function to generate the data
  {:part-number "4588-RT-345"
   :description "O Ring Heat-resistant Grade-3"
   :quantity 28
   :denomination "each"})


(defn ^{:mcp-name "generate_demand_forecast"
        :mcp-type :tool} demand-forecast
  "Generate demand forecast for specified equipment"
  [{:keys [^{:name "part_number"
             :doc "Equipment part number" :type "string"} part-no
           ^{:doc "Forecast weeks count" :type "integer"
             :default 3 :minimum 1 :maximum 8} weeks]}]
  (let [fc (get-forecast part-no weeks)]
    (eg/make-call-tool-result
     [(eg/make-text-content (u/json-write fc))])))

Client call

See Tools (Client) for the client call.

Tool Var definition

As you can see in the highlighted code example above, var annotations convey the tool metadata whereas the function itself produces the result:

  • :mcp-name (optional) The MCP tool name - same as function name if unspecified
  • :mcp-type :tool indicates that this is an MCP tool
  • The function docstring acts as the tool description
  • An MCP primitive var is always an arity-1 function. The argument is a map of specified, annotated keyword args. In the example above - part-no and weeks are tool arguments with specified :name (name, optional), :doc (description) and :type (JSON type) annotations. The :default, :minimum and :maximum hints are for UI hints.
  • The function is called when MCP call-tool method is invoked. The function body is supposed to return a call-tool result, which is done above by the plumcp.core.api.entity-gen/make-call-tool-result function.

In practice, tools are very business specific. Since AI Agents are associated with natural language the tool implementations often need to incorporate search (e.g. similar text) along with their business implementation.