execute_emacs_lisp_code
Send Emacs Lisp code to the Emacs process for execution and retrieve results, enabling AI assistants to control and interact with Emacs programmatically.
Instructions
Execute Emacs Lisp code by sending it to the Emacs process and return the result.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- emacs_mcp_server.py:60-74 (handler)The handler function decorated with @mcp.tool() for registration, implements execution of Emacs Lisp code via subprocess call to emacsclient.@log_execution @mcp.tool() def execute_emacs_lisp_code(code: str) -> str: """Execute Emacs Lisp code by sending it to the Emacs process and return the result.""" try: # Properly escape the Emacs Lisp code and pass it to emacsclient # The -e or --eval flag is used to evaluate the expression emacsclient_path = os.environ.get("EMACSCLIENT", "emacsclient") result = subprocess.check_output( [emacsclient_path, "--eval", code], text=True, stderr=subprocess.PIPE ).strip() return result except subprocess.CalledProcessError as e: return f"Error executing Emacs Lisp code: {e.stderr}"