MCP ExplorerExplorer

Emacs Introspection Mcp

@ElleNajton a month ago
1 MIT
FreeCommunity
AI Systems
simple mcp server for emacs introspection using the daemon

Overview

What is Emacs Introspection Mcp

emacs-introspection-mcp is a simple MCP server designed for Emacs introspection using the emacsclient daemon. It allows users to interact with Emacs to retrieve documentation and current values of functions and variables.

Use cases

Common use cases include retrieving documentation for Emacs functions and variables while coding, checking the current values of variables during development, and enhancing the Emacs user experience through introspection.

How to use

To use emacs-introspection-mcp, first set up gptel and mcp.el. Then, add the server configuration to your mcp-hub-servers variable in Emacs. You can then call its functions to get documentation or variable values.

Key features

Key features include: 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. All interactions are secured against injection attacks.

Where to use

emacs-introspection-mcp can be used in software development environments where Emacs is utilized, particularly for programming languages and configurations that rely on Emacs for editing and documentation.

Content

#+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 )

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers