Skip to content

MCP Logging

MCP Server logging is meant to communicate to the client anything deemed communicable from the server end. It may or may not be made accessible to the user through the MCP client.

MCP Server API allows the following levels of logging:

Index Log Level Meaning Function
0 emergency System is unusable log-0-emergency
1 alert Must take immediate action log-1-alert
2 critical Critical conditions log-2-critical
3 error Error conditions log-3-error
4 warning Warning conditions log-4-warning
5 notice Normal but significant condition log-5-notice
6 info Informational messages log-6-info
6 debug Debug-level messages log-7-debug

Code example

You may log inside any handler function for tool, prompt, resource or completion. You need to pass the context (map) available in the kwargs:

(ns hello-mcp-clj.logging
  (:require
   [plumcp.core.api.mcp-server :as ms]
   [plumcp.core.deps.runtime :as rt]))


(defn handler-for-tool-prompt-or-resource
  "Handler fn for tool, prompt, resource, or completion."
  [{:as kwargs}]
  ;; ... other code ...
  (-> (rt/get-runtime kwargs)
      (ms/log-7-debug "debug log-message or map"))
  ;; ... other code ...
  (ms/with-logger [kwargs "discount-computation"]
    ;; ... other code ...
    (-> (rt/get-runtime kwargs)
        (ms/log-6-info "info log-message or map"))
    ;; ... other code ...
    )
  ;; ... other code
  )

The with-logger macro sets the logger to the specified name, which gets included in every log entry emitted in that lexical scope.