emacs-introspection-mcp

ElleNajt/emacs-introspection-mcp

3.2

If you are the rightful owner of emacs-introspection-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A simple MCP server for Emacs introspection through the emacsclient daemon.

Tools
  1. describe_function

    Retrieves documentation for Emacs functions.

  2. describe_variable

    Retrieves documentation for Emacs variables.

  3. get_variable_value

    Gets the current value of an Emacs variable.

#+title: Readme

A simple MCP server for emacs introspection through the emacsclient daemon.

This server currently provides three tools for interacting with Emacs:

  1. describe_function - Retrieves documentation for Emacs functions
  2. describe_variable - Retrieves documentation for Emacs variables
  3. get_variable_value - Gets the current value of an Emacs variable
  • Warning

All of these evaluate elisp via the emacsclient, though they do so in the following controlled ways:

#+begin_src bash emacsclient -e "(documentation '$FUNCTION_NAME)" emacsclient -e "(documentation-property '$VARIABLE_NAME 'variable-documentation)" emacsclient -e "(symbol-value '$VARIABLE_NAME)" #+end_src

The security measures to prevent weird injections from the LLM are:

  • Using ', which in my understanding prevents evaluation of the form following it, unlike backtick (which would be vulnerable to an LLM passing in a , to escape the quoting.)
  • Using execFile with shell=false to on the typescript side, to prevent shell injection
  • Sanitized with this regexp:

#+begin_src ts const isValidEmacsSymbol = (str: string) => /^[a-zA-Z0-9-_]+$/.test(str); #+end_src

  • Installation

First, set up [[https://github.com/karthink/gptel][gptel]] and [[https://github.com/lizqwerscott/mcp.el][mcp.el]] .

Then, add this to your the mcp-hub-servers variable:

#+begin_src emacs-lisp :tangle yes ("emacs_introspection" . (:command "npx" :args ("-y" "@lnajt/emacs-introspection-mcp")) ) #+end_src

  • Implementation details

** describe_function Gets the documentation for an Emacs function by name.

  • Parameter: function_name (string)
  • Implementation: Uses emacsclient to call (documentation 'function-name)

** describe_variable Gets the documentation for an Emacs variable by name.

  • Parameter: variable_name (string)
  • Implementation: Uses emacsclient to call (documentation-property 'variable-name 'variable-documentation)

** get_variable_value Gets the current value of an Emacs variable by name.

  • Parameter: variable_name (string)
  • Implementation: Uses emacsclient to call (symbol-value 'variable-name )